hey im new to vb6 and I am making a blackjack game but can not randomize the array correctly. Could you help please
[CODE=vb]Option Explicit
Const NumItems As Integer = 53
Public Sub RandomizeCards( )
Dim i As Integer
Dim j As Integer
Dim tmp As Integer
' Randomize the array.
Randomize
For i = 1 To NumItems - 1
' Pick a random entry.
j = Int((NumItems - i + 1) * Rnd + i)
' Swap the numbers.
imgCards(j) = imgCards(i)
imgCards(tmp) = imgCards(j)
imgCards(i) = imgCards(tmp)
Next i
imgUser(0) = imgCards(j)
imgUser(1) = imgCards(i)
End Sub
Private Sub cmdDeal_Click()
RandomizeCards
End Sub[/CODE]
I have zipped the program as well for you to look at.
[CODE=vb]Option Explicit
Const NumItems As Integer = 53
Public Sub RandomizeCards( )
Dim i As Integer
Dim j As Integer
Dim tmp As Integer
' Randomize the array.
Randomize
For i = 1 To NumItems - 1
' Pick a random entry.
j = Int((NumItems - i + 1) * Rnd + i)
' Swap the numbers.
imgCards(j) = imgCards(i)
imgCards(tmp) = imgCards(j)
imgCards(i) = imgCards(tmp)
Next i
imgUser(0) = imgCards(j)
imgUser(1) = imgCards(i)
End Sub
Private Sub cmdDeal_Click()
RandomizeCards
End Sub[/CODE]
I have zipped the program as well for you to look at.
Comment