Hello Group,
I'm trying to convert some VBA code into VB.net. Here is that VBA code:
Open filePath For Input As #1 ' filePath = the text file I need to read
Do Until textRowNo = 8
'discard these first 7 rows...
Line Input #1, LineFromFile
'this is the row counter
textRowNo = (textRowNo + 1)
Loop
Ultimately I need to throw out the first seven rows of the text file. But is there a VB.net equivalent to Open filePath For Input As #1
?
After this is done, I want to continue and begin at line 8 and do the following:
Do Until EOF(1)
Line Input #1, LineFromFile
arrival = Mid(LineFromFile, 1, 9)
status = Trim(Mid(LineFromFile, 11, 3))
typeText = Mid(LineFromFile, 18, 1)
guestName = Trim(Mid(LineFromFile, 23, 28))
roomType = Trim(Mid(LineFromFile, 54, 5))
rateSched = Trim(Mid(LineFromFile, 60, 10))
rateText = Mid(LineFromFile, 71, 11)
roomRate = Val(rateText)
CCtype = Mid(LineFromFile, 93, 2)
CCNo = Mid(LineFromFile, 98, 9)
textRowNo = (textRowNo + 1)
Here I'm moving specific portions of the line into the various variables. I then need to do the same for Line 9:
If EOF(1) Then Exit Do 'checks to see if it's the end of file
Line Input #1, LineFromFile
departure = Mid(LineFromFile, 1, 9)
source = Trim(Mid(LineFromFile, 48, 5))
agent = Trim(Mid(LineFromFile, 122, 9))
And now I'm reading line 10
Cells(rowNumber, 13).Value = los
rowNumber = (rowNumber + 1)
textRowNo = (textRowNo + 1)
' Row 10
If EOF(1) Then Exit Do
Line Input #1, LineFromFile
textHead = Mid(LineFromFile, 52, 11)
'this is a blank row - throw it away or it might be the end of file
If textHead = "Reservation" Then
Line Input #1, LineFromFile
If EOF(1) Then
Exit Do
End If
Line Input #1, LineFromFile
If EOF(1) Then
Exit Do
End If
Line Input #1, LineFromFile
If EOF(1) Then
Exit Do
End If
Line Input #1, LineFromFile
If EOF(1) Then
Exit Do
End If
Line Input #1, LineFromFile
If EOF(1) Then
Exit Do
End If
Line Input #1, LineFromFile
If EOF(1) Then
Exit Do
End If
textRowNo = (textRowNo + 5)
End If
textRowNo = (textRowNo + 1)
Loop ' Loop the code begining at line 11
Close #1
Are there thoughts on how I might convert this VB.net?
Thanks,
Don