Adding to list box from text file

Aspen2K
10-04-2001, 12:23 PM
I'm having troubles trying to load from a text file back into a list box. The code below for loading actually works if there is only 3 items in the listbox upon saving when program last exited, however if there are more or less entries it don't work. So my question is, when loading how do I determine in code how many lines are to be added ? I tried somthing like For i = 0 to EOF but it did not work. Whats the dilly ? Thank you

Dim I as Integer
Dim strEntry as String

Private Sub CmdSaveLst_Click()

ff = FreeFile(0)
Open "C:\WINDOWS\Desktop\data.txt" For Output As #ff
For i = 0 To List2.ListCount - 1
strEntry = List2.List(i)
Print #ff, strEntry
Next i
Close ff

End Sub

Private Sub Form_Load()

ff = FreeFile(0)
Open "C:\WINDOWS\Desktop\data.txt" For Input As #ff
For i = 0 To 2 <font color=green>' Part In Question</font color=green>
Input #ff, strEntry
List2.List(i) = strEntry
Next i
Close ff

End Sub

KesleyK
10-04-2001, 12:38 PM
Instead of the For...Next loop, use a Do...Loop and check for EOF each time through.

__________
HOOOaaaaa! Semper Fi!

Squirm
10-04-2001, 12:47 PM
<pre>Private Sub Form_Load()

ff = FreeFile
Open "C:\WINDOWS\Desktop\data.txt" For Input As #ff
Do Until EOF(ff)
Input #ff, strEntry
List2.List(i) = strEntry
Loop
Close ff

End Sub</pre>

<P ID="edit"><FONT class="small"><EM>Edited by Squirm on 10/04/01 01:48 PM.</EM></FONT></P>

Aspen2K
10-04-2001, 12:51 PM
Thank you very much, worked like a charm :)

KesleyK
10-04-2001, 12:56 PM
np, m8!

__________
HOOOaaaaa! Semper Fi!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum