0
Reply

Vb .NET Array loop?

Mohammed

Mohammed

Feb 3 2009 10:07 AM
5.7k
I am constructing an array in Vb .NET for a voting simulation program, i want it to store numbers which are being generated these will be unique numbers to each voter and then perform a check to see if the number input by the user matches those stored in the array.

The numbers generated are sequential i.e. 1,2,3 adding 1 each time here is my code;

Public Class Form1
Inherits System.Windows.Forms.Form

Dim noofvoters As Integer
Dim noofcandidates As Integer
Dim votearr(5000) As Integer
Dim voternumhold As Integer
Dim count As Integer
Dim j As Integer
Dim k As Integer
Dim voternumcheck As String
Dim booFound As Boolean
Dim counter As Integer

btnvoternumber.Click

Call genrandomnum()

End Sub

Private Sub genrandomnum()
counter = counter + 1
count = counter
MsgBox("You're voter number is" & count)
j = 5000
j = j - 1
j = k
count = votearr(k)
End Sub

Private Sub btnvoternum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvoternum.Click

voternumcheck = InputBox("Please input voter number")
booFound = False
For k = 5000 To LBound(votearr)

If voternumcheck = votearr(k) Then
MsgBox("Value matched at k=" & k)
Else
MsgBox("Value was not found in array")

End If
Next k


I can only have up to 5000 voters so a maximum of 5000 inputs will be allowed therefore i have set the upper bound to 5000. i did not describe as i thought i may confuse people.