I have a text file like this;

Bananas=60
Tomatoes=34
Rasberries=102
Apples=23

If I have a form with textboxes or numericalupdowns is there anyway I could change the number of fruit and veg in the text file?

Could it be possible to somehow open the textfile into the form then, edit & save?

Thanks

Edited 5 Years Ago by BleepyE: n/a

What have you done so far? Please post your code here and someone will help you. Do wrap your programming code blocks within [code] .. [/code] tags.

I have no code at the moment.

All i have is abunch of textboxes for the numbers of fruits.

Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click

        'ToDo: Perform Error Checking
        Dim fStream As New System.IO.FileStream("C:\Fruit.txt", IO.FileMode.Open)
        Dim sReader As New System.IO.StreamReader(fStream)
        Dim line() As String

        Do While sReader.Peek > -1
            line = sReader.ReadLine.Split(New Char() {"="c}, StringSplitOptions.RemoveEmptyEntries)
            If line.Count <> 2 Then Continue Do 'wrong format
            If Not IsNumeric(line(1)) Then Continue Do 'wrong format

            Select Case line(0).ToLower
                Case "bananas"
                    txtBananas.Text = line(1)
                Case "apples"
                    txtApples.Text = line(1)
                Case "rasberries"
                    txtRasberries.Text = line(1)
                Case "tomatoes"
                    txtTomatoes.Text = line(1)
                Case Else
                    'Bad Fruit
            End Select
        Loop

        fStream.Close()
        sReader.Dispose()

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        'ToDo: Perform Error Checking Andalso Validate TextBoxes
        Dim fStream As New System.IO.FileStream("C:\Fruit.txt", IO.FileMode.OpenOrCreate)
        Dim sWriter As New System.IO.StreamWriter(fStream)

        sWriter.WriteLine("Bananas=" & txtBananas.Text)
        sWriter.WriteLine("Apples=" & txtApples.Text)
        sWriter.WriteLine("Rasberries=" & txtRasberries.Text)
        sWriter.WriteLine("Tomatoes=" & txtTomatoes.Text)

        sWriter.Close()
        fStream.Close()

        sWriter.Dispose()

    End Sub

Ive got small problem.

It wont open the values from the text file when I have it like this

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'ToDo: Perform Error Checking
        Dim fStream As New System.IO.FileStream("c:\Users\Ollie\Desktop\test.txt", IO.FileMode.Open)
        Dim sReader As New System.IO.StreamReader(fStream)
        Dim line() As String

        Do While sReader.Peek > -1
            line = sReader.ReadLine.Split(New Char() {"="c}, StringSplitOptions.RemoveEmptyEntries)
            If line.Count <> 2 Then Continue Do 'wrong format
            If Not IsNumeric(line(1)) Then Continue Do 'wrong format

            Select Case line(0).ToLower
                Case "A"
                    A.Text = line(1)
                Case "B"
                    B.Text = line(1)
                Case "C"
                    C.Text = line(1)
                Case Else
                    'Bad Fruit
            End Select
        Loop

        fStream.Close()
        sReader.Dispose()

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        'ToDo: Perform Error Checking Andalso Validate TextBoxes
        Dim fStream As New System.IO.FileStream("c:\Users\Ollie\Desktop\test.txt", IO.FileMode.OpenOrCreate)
        Dim sWriter As New System.IO.StreamWriter(fStream)

        sWriter.WriteLine("A" & " " & A.Text)
        sWriter.WriteLine("B" & " " & B.Text)
        sWriter.WriteLine("C" & " " & C.Text)


        sWriter.Close()
        fStream.Close()

        sWriter.Dispose()

    End Sub
   
End Class
This question has already been answered. Start a new discussion instead.