Sub Read_DLU(ByVal path As String)
Try
Dim Tempval() As String
Dim i As Integer, j As Integer, n As Integer, d As Integer
Dim Miss As String = ""
Dim Delta_t() As Double
Dim All_DTC As String = ""
Dim DTC() As String = New String() {}
Dim Currentline As String = ""
'Check existence of the file
PE.Check_path(path)
Dim Reader = New myAlias.TextFieldParser(path)
'Set text fields as Fixed Width
Reader.TextFieldType = myAlias.FieldType.FixedWidth
i = 1
Do While Not Reader.EndOfData
Dim line_number As Long
line_number = Reader.LineNumber()
Try
If line_number = 7 Then
Data_type = Mid(Trim(Reader.ReadLine), 14, InStr(Reader.ReadLine, " DATA") - 1)
'Data_type = Mid(Data_type, 1, Len(Data_type) - 5) 'remove " data" string from data_type
'Start getting Rec_nr after the Header
ElseIf line_number > 12 Then
'Avoid unuseful lines:
If Currentline.Contains("") Or Currentline.Contains("MODEL") Or Currentline.Contains("CHECKPASS") Or _
Currentline.Contains("TEST") Or Currentline.Contains("NUMBER") Or Currentline = Nothing Then
'MsgBox(line_number & " " & Currentline)
GoTo read_next_row
End If
'-----------------------------------------------------------|
'When reach "SUMMARY..." row, jump over the rows in-between |
'until reach "ALL DATACODES" row |
If Currentline.Contains("SUMMARY") Then '|
' |
Do Until Currentline.Contains("ALL DATACODES") '|
Currentline = Reader.ReadLine '|
Loop '|
End If '|
' |
'-----------------------------------------------------------|
'Get the array of data codes and the total number of DTCs
If Currentline.Contains("ALL DATACODES") Then
Try
Currentline = Reader.ReadLine
'Read the remainder of the DLU as a whole
All_DTC = Reader.ReadToEnd.Trim
MsgBox(All_DTC)
'Extract each DTC from the string
For n = 0 To All_DTC.Length
ReDim Preserve DTC(n)
DTC(n) = All_DTC.Substring(0, 6)
All_DTC = Right(All_DTC, All_DTC.Trim.Length - 6).Trim
If All_DTC = "" Then
Nr_Of_DTC = n + 1 'Total Number of DTCs
MsgBox(Nr_Of_DTC)
GoTo conclusions
End If
Next
Catch ex As Exception
MsgBox(ex.Message, , "Error after line <ALL DATACODES>!")
End Try
GoTo conclusions
End If
'Else, if it's a normal Record row:
ReDim Preserve Rec_nr(i)
Rec_nr(i) = CInt(Mid(Currentline, 11, 9))
'MsgBox(Rec_nr(i))
Test_nr = Mid(Currentline, 1, InStr(Currentline, ".") - 1).Trim
ReDim Preserve Delta_t(i)
Delta_t(i) = CDbl(Mid(Currentline, 47, 18))
ReDim Preserve DTC_nr(i)
DTC_nr(i) = CInt(Mid(Currentline, 130, 15))
'MsgBox(Delta_t(j) & " " & DTC_nr(j))
i = i + 1
End If
Catch ex As myAlias.MalformedLineException
End Try
read_next_row:
Currentline = Reader.ReadLine
Loop
conclusions:
[B]reader.close()[/B]
'Create list of missing records:
If Rec_nr(1) <> 1 Then Miss = "1"
For i = 2 To UBound(Rec_nr)
d = Rec_nr(i) - Rec_nr(i - 1)
If d > 1 And d < 1000 Then
For j = 1 To d - 1
Miss = Miss & ", " & Rec_nr(i - 1) + j
Next j
End If
'cont_3:
Next i
'Remove comma if Miss string starts with comma:
If Left(Miss, 1) = "," Then
Miss = Trim(Mid(Miss, 2))
End If
'Group_nonprimes (Miss)
If Miss = "" Then Miss = "None."
MsgBox(Miss)
'---------------------------------------------------------------------------
'Verify the number of DTCs for each record
For j = 1 To UBound(Rec_nr)
If DTC_nr(j) <> Nr_Of_DTC Then
MsgBox("Rec " & Rec_nr(j) & " might have a different nr of DTCs!")
End If
Next
'----------------------------------------------------------------------------
If Form1.cbCopy.Checked = True Then
Copy_file()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")
End Try
End Sub