Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

Displaying Totals from a text file?

$
0
0
Attachment 98415

In this program I record the person's party affiliation and age to a txt file (example: Republican, 21). I had that working and now I am trying to get the numbers to read out from the file into the lables you see in the pictures but I am having issues getting that to work. I also set an expression expected error with {,} where it is ({,}, StringSplitOptions.RemoveEmptyEntries)

Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles writeButton.Click
        'declare a streamwriter variable
        Dim outfile As IO.StreamWriter

        'open the file for append
        outfile = IO.File.AppendText("pao.txt")
        outfile.WriteLine(partyListBox.Text & "," & ageTextBox.Text)


    End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'reads totals from file and displays them
        Dim inFile As New IO.StreamReader("pao.txt")
        Dim str As String = inFile.ReadToEnd
        inFile.Close()

        Dim partyList As New List(Of String)
        For Each item As String In str.Split({,}, StringSplitOptions.RemoveEmptyEntries)
            partyList.Add(item)
        Next
        democratTotals.Text = partyList.Item(1) 'This will be integer1
        republicanTotals.Text = partyList.Item(3) 'This will be integer2
        independentTotals.Text = partyList.Item(5) 'This will be integer3

    End Sub

Attached Images
 

Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>