i want to users to be able to vote for their favourite soft drink. They will input the names of the soft drinks through the use of an inputbox, the names input are stored in an array.
what i would like to do is count the votes given to each soft drink. How would this be done, please provide example code if possible. thanks
p.s. i tried using a listbox and command button but have failed.
Here is my code;
[U] Global Variables[/U]
Dim candidatearray() As String
Dim drink1 As Integer
Dim drink2 As Integer
Dim drink3 As Integer
Dim drink4 As Integer
Dim drink5 As Integer
[U]Code; [/U] Private Sub btnsetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsetup.Click
noofdrinks = InputBox("Please enter the number of drinks", "number of drinks")
Do While noofdrinks > 5 Or noofdrinks < 2
MsgBox("Please enter a vaild number of drinks, between 2 and 5")
noofdrinks = InputBox("Please enter the number of drinks", "noofdrinks")
Loop
Dim X As Integer = 0
drinknumber = 0
ReDim drinkarray(noofcandidates)
Do Until noofdrinks = drinknumber
drinkname = InputBox("Enter the drinks name:", "drinkname")
drinknumber = drinknumber + 1
lbxvotedrinks.Items.Insert(X, drinkname)
X = X + 1
candidatearray(i) = candidatename
i = i + 1
Private Sub btnvotefordrink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvoteforcan.Click
If lbxvotedrinks.SelectedItem = 0 Then
drink1 = drink1 + 1
votesballot = votesballot + 1
End If
If lbxvotecdrinks.SelectedItem = 1 Then
drink2 = cdrink2 + 1
votesballot = votesballot + 1
End If
If lbxvotedrinks.SelectedItem = 2 Then
drink3 = drink3 + 1
votesballot = votesballot + 1
End If
If lbxvotedrinks.SelectedItem = 3 Then
drink4 = drink4 + 1
votesballot = votesballot + 1
End If
If lbxvotedrinks.SelectedItem = 4 Then
drink5 = drink5 + 1
votesballot = votesballot + 1
End If
If lbxvotedrinks.SelectedItem = 5 Then
drink1 = drink1 + 1
votesballot = votesballot + 1
End If
End Sub
Could you sugget other ways of storing the votes separately for each candidate. thanks