First, I need to read from a text file and display the results in a textbox. The text file is two columns, 18 rows, with the first column a certain ingredient and the second the amount of that ingredient remaining. Depending on what is ordered, the amounts in the list box will be updated with a button. I have another button that's supposed to update the text file. Can anyone get me started?


Recommended Answers

All 2 Replies

I would start with taking a look at the namespace System.IO.
It contains a whole bunch of classes for reading files.
System.IO.StreamReader is one of those classes, which also happens to contain a method called ReadLine().
Combine that with a While loop and off you go. :)
Perhaps this thread could be of some help.

And depending on how those columns in the textfile are separated perhaps you should also dig into how to read CSV files.

From there it's quite a small step to separate the file's content into proper containers.

You could also use the System.IO.File.ReadAllLines method to fill the listbox in one statement. Something like this


then to update the textfile something like this:

    Dim sw As StreamWriter = File.CreateText("TextFile1.txt")
    For I = 0 To ListBox1.Items.Count - 1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.