what i want to do is for e.g., i have list.txt in my application directory so i want to loop through this file and get all the lines and put each entry into a list box, is this possible.?
anyone have any sample code, would be very much appreciated!!
Printable View
what i want to do is for e.g., i have list.txt in my application directory so i want to loop through this file and get all the lines and put each entry into a list box, is this possible.?
anyone have any sample code, would be very much appreciated!!
i did this, but it just prints 5 zeros :confused:
i want to put the entries into the list box
VB Code:
Private Sub Command3_Click() Dim fnum As Integer, one_line As String, lines As Long fnum = FreeFile Open "list.txt" For Input As #fnum Do While Not EOF(fnum) Line Input #fnum, one_line 'need to put the entries into list box Debug.Print lines Loop Close fnum End Sub
Try thisVB Code:
Private Sub Command1_Click() Dim sData As String Dim sFilename As String sFilename = "c:\list.txt" Open sFilename For Input As #1 While Not EOF(1) Line Input #1, sData List1.AddItem sData Wend Close #1 End Sub
ok thank you thats beautiful, is it also possible to now debug.print the number of entries in the list box?
Quote:
Originally Posted by Pouncer
VB Code:
Debug.Print List1.ListCount
ok thank you very much Hack, now is it possible to debug.print for e.g. the 2nd entry in the list box? or 3rd etc
each list entry has an index (starting at zero)
Debug.Print List1.List(0) '1st item
Debug.Print List1.List(1) '2nd
Debug.Print List1.List(2) '3rd and so on
Quote:
Originally Posted by Pouncer
VB Code:
Debug.Print List1.List(2)