General information
Category:
Coding, syntax & commands
Title:
Reading string a line at time
I am loading a string variable with a text file...
Public ncurpos
Public sData
Private Sub Command1_Click()
Open "c:\temp\test.txt" For Input As #1
Do While Not EOF(1) ' Check for end of file.
Line Input #1, InputData ' Read line of data.
sData = sData + InputData + Chr(13) + Chr(10)
Loop
Close #1 '
Text1.Text = sData
End Sub
That works fine.
Then I need to process sData one line at a time as if it was being read
from the file right then.
So I do this...
Private Sub Command2_Click()
Text2.Text = ReadLine(sData) ' Just to see what is happening
End Sub
Private Function ReadLine(cP)
stemp = Mid(cP, ncurpos, InStr(ncurpos, cP, Chr(13)) - 1) ' copy line up to CR
ncurpos = (ncurpos - 1) + Len(stemp) + 3
ReadLine = stemp
End Function
Private Sub Form_Load()
ncurpos = 1
End Sub
After one line it breaks because it can't see the next CR. I'm not sure
why. Any tips or ideas on how to do this better?
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only