I am trying to create a program to randomly generate a name from a cake rota array. I cannot seem to get it to work. Currently, the message box shows a random number rather than the name stored in the array. Help please!
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strNames(18) As String
Dim frances, emma, piotr, jake, jess, jonah, john, flynn, will, nick As String
strNames(0) = "frances"
strNames(1) = "emma"
strNames(2) = "piotr"
strNames(3) = "jake"
strNames(4) = "jess"
strNames(5) = "jonah"
strNames(6) = "john"
strNames(7) = "flynn"
strNames(8) = "will"
strNames(9) = "nick"
Dim rnum As Integer
Dim temp As String
For i = 0 To 18
strNames(i) = i
Next i
Randomize()
For i = 0 To 9
rnum = Int(Rnd() * (UBound(strNames) - LBound(strNames) + 1) + LBound(strNames))
temp = strNames(i)
strNames(i) = strNames(rnum)
strNames(rnum) = temp
Next i
For i = 0 To 9
MessageBox.Show(strNames(i))
Next i
End Sub
rnumhas to depend oni). Please see how to shuffle array in VB? or Shuffling an array of strings in vb.net.