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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Marethyu
    New Member
    • Jul 2020
    • 2

    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
  • Otekpo Emmanuel
    New Member
    • Dec 2013
    • 23

    #2
    Opening text file in vb6 requires a physical path to the file location.

    This code can help you.
    Code:
    Sub ReadFile(listBox1 As ListBox, filePath As String)
    
    Open filePath For Input As #dfile
    Dim txt As String
    
      Do While Not EOF(dfile)        ' this will read all text to listbox
       Line Input #dfile, txt  
        listBox1.Items.Add(txt)
      Loop
    
      Close #dfile
    End Sub
    Good luck

    Comment

    • Marethyu
      New Member
      • Jul 2020
      • 2

      #3
      It works!!! Thanks a lot, Mate. Really appreciate it!

      Comment

      • rayankhaled
        New Member
        • Jul 2020
        • 1

        #4
        i was looking for this
        thanks alot

        Comment

        • Otekpo Emmanuel
          New Member
          • Dec 2013
          • 23

          #5
          You're welcome. Wish you happy coding

          Comment

          Working...