|
-
Oct 11th, 2005, 11:33 AM
#1
Thread Starter
Frenzied Member
get the file contents
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!!
-
Oct 11th, 2005, 11:52 AM
#2
Thread Starter
Frenzied Member
Re: get the file contents
i did this, but it just prints 5 zeros
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
-
Oct 11th, 2005, 11:54 AM
#3
Re: get the file contents
Try this
VB 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
-
Oct 11th, 2005, 11:57 AM
#4
Thread Starter
Frenzied Member
Re: get the file contents
ok thank you thats beautiful, is it also possible to now debug.print the number of entries in the list box?
-
Oct 11th, 2005, 11:59 AM
#5
Re: get the file contents
 Originally Posted by Pouncer
ok thank you thats beautiful, is it also possible to now debug.print the number of entries in the list box?
VB Code:
Debug.Print List1.ListCount
-
Oct 11th, 2005, 12:01 PM
#6
Thread Starter
Frenzied Member
Re: get the file contents
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
-
Oct 11th, 2005, 12:05 PM
#7
Re: get the file contents
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Oct 11th, 2005, 12:06 PM
#8
Re: get the file contents
 Originally Posted by Pouncer
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
VB Code:
Debug.Print List1.List(2)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|