Visual Studio Developer Center > Visual Studio Forums > Visual Studio Debugger > Error in what is outputted into 4 labels from a click event
Ask a questionAsk a question
 

AnswerError in what is outputted into 4 labels from a click event

  • Sunday, November 01, 2009 3:46 AMDustinsfl Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    When I click the button get results, I wanted precinct labels 1-4 to display the total number or female republican voters out of total voters for each precinct in their respected precinct label; however, label shows 0 out of a 1000 and the other come up blank.
    Here is the code I have used. Can someone please help? Thanks.

    Option Strict On
    Imports System.IO   'Allows files to be read/written.
    Public Class Form1
        Dim TotalInteger As Integer 'Declare module-level variable.
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim VoterStreamReader As New StreamReader("voter_stream.txt")   'Load .txt file to be used.
            Do Until VoterStreamReader.Peek = -1
                PrecinctListBox.Items.Add(VoterStreamReader.ReadLine)   'Adds all the precincts to the listbox.
                GenderListBox.Items.Add(VoterStreamReader.ReadLine) 'Adds all the genders to the listbox.
                VoterStreamReader.ReadLine()
                VoterStreamReader.ReadLine()
                AffiliationListBox.Items.Add(VoterStreamReader.ReadLine)    'Adds all the affiliations to the listbox.
                TotalInteger += 1   'Calculates the total voters.
            Loop
            VoterStreamReader.Close()
        End Sub
    
        Private Sub ResultButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResultButton.Click
            Dim VoterStreamReader As New StreamReader("voter_stream.txt")   'Load .txt file to be used.
            Dim FoundBoolean As Boolean = False
            Dim PrecinctString, GenderString, AffiliationString As String
            Dim Precinct1Integer, Precinct2Integer, Precinct3Integer, Precinct4Integer As Integer
            Do Until FoundBoolean = True
                PrecinctString = VoterStreamReader.ReadLine
                GenderString = VoterStreamReader.ReadLine
                VoterStreamReader.ReadLine()
                VoterStreamReader.ReadLine()
                AffiliationString = VoterStreamReader.ReadLine
                If PrecinctString = "1" Then
                    If GenderString = "F" Then
                        If AffiliationString = "R" Then
                            FoundBoolean = True
                            Precinct1Label.Text = Precinct1Integer.ToString & " of " & TotalInteger.ToString
                        End If
                    End If
                End If
            Loop
            VoterStreamReader.Close()
            Do Until FoundBoolean = True
                PrecinctString = VoterStreamReader.ReadLine
                GenderString = VoterStreamReader.ReadLine
                VoterStreamReader.ReadLine()
                VoterStreamReader.ReadLine()
                AffiliationString = VoterStreamReader.ReadLine
                If PrecinctString = "2" Then
                    If GenderString = "F" Then
                        If AffiliationString = "R" Then
                            FoundBoolean = True
                            Precinct2Label.Text = Precinct2Integer.ToString & " of " & TotalInteger.ToString
                        End If
                    End If
                End If
            Loop
            VoterStreamReader.Close()
            Do Until FoundBoolean = True
                PrecinctString = VoterStreamReader.ReadLine
                GenderString = VoterStreamReader.ReadLine
                VoterStreamReader.ReadLine()
                VoterStreamReader.ReadLine()
                AffiliationString = VoterStreamReader.ReadLine
                If PrecinctString = "3" Then
                    If GenderString = "F" Then
                        If AffiliationString = "R" Then
                            FoundBoolean = True
                            Precinct3Label.Text = Precinct3Integer.ToString & " of " & TotalInteger.ToString
                        End If
                    End If
                End If
            Loop
            VoterStreamReader.Close()
            Do Until FoundBoolean = True
                PrecinctString = VoterStreamReader.ReadLine
                GenderString = VoterStreamReader.ReadLine
                VoterStreamReader.ReadLine()
                VoterStreamReader.ReadLine()
                AffiliationString = VoterStreamReader.ReadLine
                If PrecinctString = "4" Then
                    If GenderString = "F" Then
                        If AffiliationString = "R" Then
                            FoundBoolean = True
                            Precinct4Label.Text = Precinct4Integer.ToString & " of " & TotalInteger.ToString
                        End If
                    End If
                End If
            Loop
            VoterStreamReader.Close()
        End Sub
    End Class

Answers

All Replies