468,270 Members | 1,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,270 developers. It's quick & easy.

How can I load text file into list box in Visual Basic 6

I have downloaded a Visual Basic 6 application which pick a random name from a list box. But I want the list box to already be filled with names from a text. What should I do? I have entirely no knowledge about Visual Basic and I am just watching tutorial from YouTube. I will just use this application so that I can randomly pick names on my online class. Thanks
Jul 26 '20 #1
4 2466
Opening text file in vb6 requires a physical path to the file location.

This code can help you.
Expand|Select|Wrap|Line Numbers
  1. Sub ReadFile(listBox1 As ListBox, filePath As String)
  2.  
  3. Open filePath For Input As #dfile
  4. Dim txt As String
  5.  
  6.   Do While Not EOF(dfile)        ' this will read all text to listbox
  7.    Line Input #dfile, txt  
  8.     listBox1.Items.Add(txt)
  9.   Loop
  10.  
  11.   Close #dfile
  12. End Sub
  13.  
Good luck
Jul 26 '20 #2
It works!!! Thanks a lot, Mate. Really appreciate it!
Jul 26 '20 #3
i was looking for this
thanks alot
Jul 26 '20 #4
You're welcome. Wish you happy coding
Jul 26 '20 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by lord.tyranus.96 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.