below I have posted my code, the program should take a number in through a text box, then create an array relevant to that number, then take data in for each part of the array and display it, this all seems to work fine, the program should then create a random number that will match with a number in that array and display part of the data from that array in a different text box, the problem is it seems to be generating the random number fine (I have it displaying this in a text box at the moment) but it is only displaying the winner when it matches up to the maximum number of the array, can anyone please help?
ublic Class speaktheLingo
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
'set variables
Dim cinema As Integer
Randomize()
Dim numstudents As Integer
numstudents = txtNumstudent.Text
Dim studentname(numstudents) As String
Dim bookedhours(numstudents) As Integer
Dim freehours(numstudents) As Integer
Dim totalhours(numstudents) As Integer
Dim counter As Integer
'get user inputs
For counter = 1 To (numstudents)
totalhours(numstudents) = 0
freehours(numstudents) = 0
studentname(numstudents) = InputBox("What is the students first name?")
bookedhours(numstudents) = InputBox("How many hours has " & studentname(numstudents) & " booked?")
'set up IF's
If bookedhours(numstudents) < 10 Then
freehours(numstudents) = 0
End If
If bookedhours(numstudents) >= 10 And bookedhours(numstudents) < 15 Then
freehours(numstudents) = 1
Else
freehours(numstudents) = 2
End If
'calculation area
totalhours(numstudents) = bookedhours(numstudents) + freehours(numstudents)
'Display area
txtDisplay.AppendText(studentname(numstudents) & " you have " & freehours(numstudents) & " free hours" & vbCrLf & "Your total number of hours booked (including free hours) is now " & totalhours(numstudents) & vbCrLf)
Next
'generate random number to decide which name in array wins
cinema = Int(Rnd() * numstudents + 1)
'display winner
txtWinner.Text = (studentname(cinema))
'temporary code and txtbox to check random number is working
txtCinema.Text = cinema
End Sub
End Class
ublic Class speaktheLingo
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
'set variables
Dim cinema As Integer
Randomize()
Dim numstudents As Integer
numstudents = txtNumstudent.Text
Dim studentname(numstudents) As String
Dim bookedhours(numstudents) As Integer
Dim freehours(numstudents) As Integer
Dim totalhours(numstudents) As Integer
Dim counter As Integer
'get user inputs
For counter = 1 To (numstudents)
totalhours(numstudents) = 0
freehours(numstudents) = 0
studentname(numstudents) = InputBox("What is the students first name?")
bookedhours(numstudents) = InputBox("How many hours has " & studentname(numstudents) & " booked?")
'set up IF's
If bookedhours(numstudents) < 10 Then
freehours(numstudents) = 0
End If
If bookedhours(numstudents) >= 10 And bookedhours(numstudents) < 15 Then
freehours(numstudents) = 1
Else
freehours(numstudents) = 2
End If
'calculation area
totalhours(numstudents) = bookedhours(numstudents) + freehours(numstudents)
'Display area
txtDisplay.AppendText(studentname(numstudents) & " you have " & freehours(numstudents) & " free hours" & vbCrLf & "Your total number of hours booked (including free hours) is now " & totalhours(numstudents) & vbCrLf)
Next
'generate random number to decide which name in array wins
cinema = Int(Rnd() * numstudents + 1)
'display winner
txtWinner.Text = (studentname(cinema))
'temporary code and txtbox to check random number is working
txtCinema.Text = cinema
End Sub
End Class