| | |
How to simulate voting vb.net ?
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 14
Reputation:
Solved Threads: 0
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;
Could you sugget other ways of storing the votes separately for each candidate. thanks
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.
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:
Here it is:
vb Syntax (Toggle Plain Text)
Dim favSoftDrink() As String Dim favSoftDrinkRating() As Integer Dim results As String Dim b As Integer Dim a As Integer Dim NumDrinks As Integer Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click NumDrinks = InputBox("How many Soft drink are you going to vote on?") ReDim favSoftDrink(NumDrinks) ReDim favSoftDrinkRating(NumDrinks) For b = 0 To NumDrinks - 1 favSoftDrink(b) = InputBox("Please Enter The Name of the soft drink number:" & b + 1) Next For a = 0 To NumDrinks - 1 favSoftDrinkRating(a) = InputBox("Please Enter a rating for " & favSoftDrink(a)) Next For c = 0 To NumDrinks - 1 results += "SoftDrink: " & favSoftDrink(c) & vbTab & "Rating: " & favSoftDrinkRating(c) & vbCrLf Next TextBox1.Text = results End Sub
![]() |
Similar Threads
- vb .net array loop? (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: One form data to be inserted/updated into multiple tables
- Next Thread: Linking Comboboxes in VB 2008
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic beginner browser button buttons center checkbox client code convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel fade filter forms ftp generatetags gridview html images inline input insert intel internet lib listview mobile monitor net objects open panel passingparameters pdf picturebox port position print printing problem read remove save searchvb.net select serial settings shutdown soap sorting sqlserver survey table temperature textbox timer timespan transparency trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winforms wpf wrapingcode year





