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)
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