Can someone please review my streamreader code and please let me know what I need to do in order to tabulate the selected political party? I keep having "zero" in all of the labels. Please help. Thank you very much in advance!!!

vb.net Code:
  1. Public Class frmMain
  2.  
  3.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  4.         Me.Close()
  5.     End Sub
  6.     Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.         ' fill the list box with values
  8.  
  9.         lstParty.Items.Add("Democrats")
  10.         lstParty.Items.Add("Republicans")
  11.         lstParty.Items.Add("Independents")
  12.     End Sub
  13.     Private Sub txtAge_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAge.KeyPress
  14.         ' allows the text box to accept only numbers, the period, and the Backspace key
  15.  
  16.         If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
  17.             e.KeyChar <> ControlChars.Back Then
  18.             ' cancel the key
  19.             e.Handled = True
  20.         End If
  21.     End Sub
  22.     Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
  23.  
  24.         ' writes a political party to a sequential access file
  25.         ' declare a StreamWriter variable
  26.         Dim outFile As IO.StreamWriter
  27.  
  28.         ' open the file for append
  29.         outFile = IO.File.AppendText("Party.txt")
  30.  
  31.         ' write the name on a separate line in the file
  32.         outFile.Write(lstParty.Text)
  33.         outFile.Write(",")
  34.         outFile.Write(txtAge.Text)
  35.         outFile.WriteLine()
  36.  
  37.         ' close the file
  38.         outFile.Close()
  39.  
  40.         ' set focus
  41.         txtAge.Focus()
  42.     End Sub
  43.  
  44.     Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
  45.         ' reads political party from a sequential access file
  46.         ' and displays them in the interface
  47.  
  48.         ' declare variables
  49.         Dim inFile As IO.StreamReader
  50.         Dim strParty As String
  51.         Dim intDem As Integer
  52.         Dim intRep As Integer
  53.         Dim intInd As Integer
  54.  
  55.         If IO.File.Exists("Party.txt") Then
  56.             'open the file for input
  57.             inFile = IO.File.OpenText("Party.txt")
  58.             ' process loop instructions until the end of file
  59.             Do Until inFile.Peek = -1
  60.                 ' read a name
  61.                 strParty = inFile.ReadLine
  62.                 Select Case strParty
  63.                     Case "Democrats"
  64.                         intDem += 1
  65.                         'lblDemocrats.Text = intDem.ToString
  66.                     Case "Republicans"
  67.                         intRep += 1
  68.                         'lblRepublicans.Text = intRep.ToString
  69.                     Case "Independents"
  70.                         intInd += 1
  71.                         'lblIndependents.Text = intInd.ToString
  72.                 End Select
  73.                 ' add name to list box
  74.                 lblDemocrats.Text = intDem.ToString
  75.                 lblRepublicans.Text = intRep.ToString
  76.                 lblIndependents.Text = intInd.ToString
  77.             Loop
  78.             ' close the file
  79.             inFile.Close()
  80.         Else
  81.             MessageBox.Show("Can't find the file", "Political Party", MessageBoxButtons.OK, MessageBoxIcon.Information)
  82.         End If
  83.     End Sub
  84.     Private Sub txtAge_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAge.Enter
  85.         txtAge.SelectAll()
  86.     End Sub
  87. End Class

Name:  form.jpg
Views: 606
Size:  31.6 KB