Davidprince
Programmer
Ladies and Gentlemen
I have the following code to do some card shuffling in an existing program (borrowed off the net about 3 years ago).
I have had the program running with two decks (104 cards) but the bloody Casino has now gone to 4 decks (208 cards).
I thought that's easy just change the Array size to 208 as under. Unfortunately, the program didn't work. Tried a few numbers from 104 to 208 and got it running correctly at 180 but it failed at 200.
Could someone enlighten me?
Sub Shuffle()
Dim order(1 To 208) As Integer
Dim colCardsLeft As New Collection
Dim c As Integer
Dim rndCard As Integer
' initialise collection of cards
' To make use of handly features of collections
For c = 1 To 208
colCardsLeft.Add Str(c)
Next c
' now shuffle by placing a card in each position
' in the deck. Using the collection's remove method
' to prevent any repeats
c = 1
Randomize Timer
While colCardsLeft.Count > 0
rndCard = Int(Rnd() * colCardsLeft.Count) + 1
order(c) = CInt(colCardsLeft(rndCard))
colCardsLeft.Remove (rndCard)
c = c + 1
Wend
' take a look at the shuffle
For c = 1 To 208
Debug.Print order(c)
Next c
End Sub
Private Sub Command1_Click()
Call Shuffle
End Sub
Best wishes for a great Christmas and a happy New Year.
David
I have the following code to do some card shuffling in an existing program (borrowed off the net about 3 years ago).
I have had the program running with two decks (104 cards) but the bloody Casino has now gone to 4 decks (208 cards).
I thought that's easy just change the Array size to 208 as under. Unfortunately, the program didn't work. Tried a few numbers from 104 to 208 and got it running correctly at 180 but it failed at 200.
Could someone enlighten me?
Sub Shuffle()
Dim order(1 To 208) As Integer
Dim colCardsLeft As New Collection
Dim c As Integer
Dim rndCard As Integer
' initialise collection of cards
' To make use of handly features of collections
For c = 1 To 208
colCardsLeft.Add Str(c)
Next c
' now shuffle by placing a card in each position
' in the deck. Using the collection's remove method
' to prevent any repeats
c = 1
Randomize Timer
While colCardsLeft.Count > 0
rndCard = Int(Rnd() * colCardsLeft.Count) + 1
order(c) = CInt(colCardsLeft(rndCard))
colCardsLeft.Remove (rndCard)
c = c + 1
Wend
' take a look at the shuffle
For c = 1 To 208
Debug.Print order(c)
Next c
End Sub
Private Sub Command1_Click()
Call Shuffle
End Sub
Best wishes for a great Christmas and a happy New Year.
David