-
I have a need to be able to use the Line input# function to read one line of a text file into a variable however some lines only end with vblf (chr(10)) , not the usual vbcr & vblf (chr(13) chr(10)). Any ideas on how to make this work without re-writing the whole Line Input# function? Any help would be greatly appreciated.
Thanks,
Mike
-
Try something like:
Code:
Private Sub Command1_Click()
Dim iFile As Integer
Dim sFile As String
Dim sLine As String
Dim nPos As Long
iFile = FreeFile
Open "C:\TheFile.txt" For Binary Access Read As iFile
sFile = Space(LOF(iFile))
Get #iFile, , sFile
Close iFile
sFile = Replace(sFile, Chr(13), "")
Do
nPos = InStr(sFile, Chr(10))
If nPos = 0 Then nPos = Len(sFile) + 1
sLine = Left(sFile, nPos - 1)
MsgBox sLine
sFile = Mid(sFile, nPos + 1)
Loop While Len(sFile)
End Sub