Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading string a line at time
Message
 
To
All
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Title:
Reading string a line at time
Miscellaneous
Thread ID:
00532794
Message ID:
00532794
Views:
33
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
Map
View

Click here to load this message in the networking platform