Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collections in VB6

Status
Not open for further replies.

Davidprince

Programmer
Jul 1, 2003
52
AU
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
 
A search in this forum should find some better card shuffling methods that only use arrays and can handle (theoretically) any size deck(s)
 
strongm
Thanks for the tip - I should have looked at one of my old posts first, which would have lead me to your reposted faq.
Regards
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top