How to simulate voting vb.net ?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 14
Reputation: asif786 is an unknown quantity at this point 
Solved Threads: 0
asif786 asif786 is offline Offline
Newbie Poster

How to simulate voting vb.net ?

 
0
  #1
Feb 18th, 2009
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;
      Global Variables
Dim candidatearray() As String
    Dim drink1 As Integer
    Dim drink2 As Integer
    Dim drink3 As Integer
    Dim drink4 As Integer
    Dim drink5 As Integer

Code;    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
Last edited by asif786; Feb 18th, 2009 at 6:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 89
Reputation: toko is an unknown quantity at this point 
Solved Threads: 8
toko's Avatar
toko toko is offline Offline
Junior Poster in Training

Re: How to simulate voting vb.net ?

 
0
  #2
Feb 18th, 2009
First, i would make a two arrays, one fore the name and one for the rating. Then i would use the for loop to get the names then get the rating for those names. Finaly i would display those inputs in a text box.

Here it is:
  1. Dim favSoftDrink() As String
  2. Dim favSoftDrinkRating() As Integer
  3. Dim results As String
  4. Dim b As Integer
  5. Dim a As Integer
  6. Dim NumDrinks As Integer
  7. Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
  8.  
  9. NumDrinks = InputBox("How many Soft drink are you going to vote on?")
  10. ReDim favSoftDrink(NumDrinks)
  11. ReDim favSoftDrinkRating(NumDrinks)
  12. For b = 0 To NumDrinks - 1
  13. favSoftDrink(b) = InputBox("Please Enter The Name of the soft drink number:" & b + 1)
  14. Next
  15. For a = 0 To NumDrinks - 1
  16. favSoftDrinkRating(a) = InputBox("Please Enter a rating for " & favSoftDrink(a))
  17. Next
  18. For c = 0 To NumDrinks - 1
  19. results += "SoftDrink: " & favSoftDrink(c) & vbTab & "Rating: " & favSoftDrinkRating(c) & vbCrLf
  20. Next
  21. TextBox1.Text = results
  22. End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC