0

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?

Thanks

3
Contributors
2
Replies
30
Views
4 Years
Discussion Span
Last Post by tinstaafl
0

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.

0

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

ListBox1.Items.AddRange(File.ReadAllLines("TextFile1.txt"))

then to update the textfile something like this:

    File.Delete("TextFile1.txt")
    Dim sw As StreamWriter = File.CreateText("TextFile1.txt")
    For I = 0 To ListBox1.Items.Count - 1
        sw.WriteLine(ListBox1.Items(I).ToString)
    Next
    sw.Close()

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.