Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading string a line at time
Message
De
19/07/2001 17:32:04
 
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00532794
Message ID:
00532875
Vues:
16
>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?

Don't you need to put a loop on ReadLine until all lines have been read?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform