By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,213 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,213 IT Pros & Developers. It's quick & easy.

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

P: 2
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
1 Week Ago #1
Share this Question
Share on Google+
4 Replies


P: 20
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
1 Week Ago #2

P: 2
It works!!! Thanks a lot, Mate. Really appreciate it!
1 Week Ago #3

P: 1
i was looking for this
thanks alot
1 Week Ago #4

P: 20
You're welcome. Wish you happy coding
1 Week Ago #5

Post your reply

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