Results 1 to 2 of 2

Thread: Shuffling a Deck of cards?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184

    Post

    Hi

    could someone help me to do this...

    I Have a string var. Array with 60 different Places to hold info (It's a Type called Deck .. Ie... Deck1.Card1 = "Ace"


    How Can I tell it to switch Those Randomly with out alot of fuss.. (You know shuffle the deck) maybe with a api somehow..

    Thankyou all..

    Evan

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    This is not a complete answer to your problem, and most likely there is a better way to do even this, but the following will result in MyCollection containing a set of 60 non-repeating numbers from 1 to 60.
    Code:
        Dim nTry As Integer
        Dim nAddCount As Integer
        Dim bFound As Integer
        Dim nDummy As Integer
    
        Dim MyCollection As New Collection
        
        Randomize
        
        Do Until nAddCount = 60
            nTry = Int((60 - 1 + 1) * Rnd + 1)
            On Error Resume Next
            nDummy = MyCollection.Item(CStr(nTry))
            bFound = (Err = 0)
            If bFound Then
                Err.Clear
            Else
                MyCollection.Add nTry, CStr(nTry)
                nAddCount = nAddCount + 1
            End If
        Loop
    ------------------
    Marty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width