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

VS 2010 Help with listbox and sequential access file

$
0
0
I am working on an assignment where I have toe create and application that keeps track of the voting for three students running for office. I have to save the voting information into a sequential access file and then also be able to display the number of votes per candidates.

Here is what I have so far. I am not looking for you to do the project but rather give some clues as to if I am in the right direction or if I am totally off.
Basically there is a listbox, three text boxes to reveal how many votes for each candidate and three buttons: one for saving the votes, one for displaying the votes and the other is an exit button.

Code:

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm
   

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()

    End Sub

    Private Sub saveVoteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles saveVoteButton.Click
        Dim mark As Integer
        Dim sheima As Integer
        Dim sam As Integer
        Dim tally As Integer

        Dim outFile As IO.StreamWriter
        outFile = IO.File.AppendText("candidate.txt")
        outFile.WriteLine(candidateListBox.SelectedItem)
        If candidateListBox.SelectedItem Is "Mark Stone" Then
            tally = 1
            mark = mark + tally
        ElseIf candidateListBox.SelectedItem Is "Sheima Patel" Then
            tally = 1
            sheima = sheima + tally

        ElseIf candidateListBox.SelectedItem Is "Sam Perez" Then
            tally = 1
            sam = sam + tally
        End If



        outFile.Close()
    End Sub



    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       

        candidateListBox.Items.Add("Mark Stone")
        candidateListBox.Items.Add("Sheima Patel")
        candidateListBox.Items.Add("Sam Perez")
    End Sub
End Class


Any help would be appreciated.

Viewing all articles
Browse latest Browse all 27349

Trending Articles



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