• 0

[vb] Loading Info From Textfile Into A Combo Box


Question

Hey all :)

I need to know how I can make a program load a text file with a list of words into a Combo box.

For example in the text file, it has

One

Two

Three

Then after I started the program, One, Two, and Three would be in the combo box.

Thanks. :ninja:

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Here:

Open "C:\Textfile.txt" For Input As #1
    Do While EOF(1) = False
        Line Input #1, sInput
        Combo1.AddItem sInput
    Loop
Close #1

Don't forget:

Dim sInput As String

My textfile looked like this:

One

Two

Three

Link to comment
Share on other sites

  • 0

Ooohh, cool, thanks! :)

But one last thing, I've have a command button, and a text box, now when you type say, Four into it, it adds Four to the textfile under Three. :wacko:

Link to comment
Share on other sites

  • 0

That's because it's just tagging it on the end of the file. Unless you can write a piece of code to sort the words into ascending order (not alphabetical order) the best bet would be to use numbers in the file instead of words - then I believe you can get the combo box to auto-sort the items.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.