I need help here. I'm writing a program to be able to read a text file. I have been able to open and read the file correctly thanks to the search utility in this forum.
However, I want it to read the previous line whenever a condition is not met. Could someone please show me the code for this.
Here is part of my code. I want the system to move back to the previous line in the text file whenever the Else case is executed. I have tried "Input #-1, MyLine" but it is not working.
However, I want it to read the previous line whenever a condition is not met. Could someone please show me the code for this.
Here is part of my code. I want the system to move back to the previous line in the text file whenever the Else case is executed. I have tried "Input #-1, MyLine" but it is not working.
Code:
Private Sub cmdRead_Click()
On Error GoTo Read_Err
Dim MyLine As String
Dim tIMSI As String
Dim tMSISDN As String
Dim tVID As String
Dim tCAT As String
Dim tTBS1 As String
Dim tTBS2 As String
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("tblHLRDUMP", dbOpenDynaset)
Open "C:\HLRDUMP20050604.txt" For Input As #1
Input #1, MyLine
Do While Not EOF(1)
'This checks if it's the start of a new profile
If Mid(Trim(MyLine), 2, 8) = "SUBBEGIN" Then
'Skips the first line
Input #1, MyLine 'line 1
'Starts storing values for current profile
If Left(MyLine, 4) = "IMSI" Then
tIMSI = Mid(MyLine, 6, 45)
Else
Input #-1, MyLine
End If
Input #1, MyLine 'line 2
If Left(MyLine, 6) = "MSISDN" Then
tMSISDN = Mid(MyLine, 8, 45)
Else
Input #-1, MyLine
End If
Input #1, MyLine 'line 3
If Left(MyLine, 3) = "VID" Then
tVID = Mid(MyLine, 5, 45)
Else
Input #-1, MyLine
End If
Input #1, MyLine 'line 4
If Left(MyLine, 3) = "CAT" Then
tCAT = Mid(MyLine, 5, 45)
Else
Input #-1, MyLine
End If
Input #1, MyLine ' line 5
If Left(MyLine, 3) = "TBS" Then
tTBS1 = Mid(MyLine, 5, 45)
Else
Input #-1, MyLine
End If
Input #1, MyLine ' line 6
If Left(MyLine, 3) = "TBS" Then
tTBS2 = Mid(MyLine, 5, 45)
Else
Input #-1, MyLine
End If
'Now it stores into the database
With rst
.AddNew
rst("IMSI") = tIMSI
rst("MSISDN") = tMSISDN
rst("VID") = tVID
rst("CAT") = tCAT
rst("TBS1") = tTBS1
rst("TBS2") = tTBS2
.Update
End With
tIMSI = ""
tMSISDN = ""
tVID = ""
tCAT = ""
tTBS1 = ""
tTBS2 = ""
Else
Input #1, MyLine
End If
Loop
Close #1
rst.Close
MsgBox "All records read and loaded successfully.", vbInformation, "HLR Profile Reader"
Exit_Read:
Exit Sub
Read_Err:
MsgBox Err.Description, vbOKOnly, "HLR Profile Reader"
Resume Exit_Read
End Sub