GoGreen PC TuneUp™
Learn More

Insta-Install™
this is how we code sign our software and ssl encrypt our websites from our affiliate partner SSL.com

myBlog

myBlog Home

Back to Blog MTNCOMP


Visual Basic - Load Deck of Cards into an array

Published: Wednesday, July 22, 2020 written by Andy Flagg
View Count: 32
Keywords: Visual Basic, Deck of Cards



I was just wanting to load a deck of cards into an array. nothing fancy.
 
Private Sub Form_Load()
Debug.Print "loading deck of cards"
'config suits and cards, decks and shoes this game will show me how to load a deck of cards and randomly pick one, then the next
'presume standard deck of cards, 4 suits, 13 cards per suit
'Ace through Jack, 10 through 2; ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2
'create the deck array and load it, and show it

Dim deckofcards(52)
z = 0

For x = 1 To 4
    'Debug.Print x
    Select Case x   'select suit
    
    Case 1
        suit = "H"  'hearts
    Case 2
        suit = "D"  'diamonds
    Case 3
        suit = "C"  'clubs
    Case 4
        suit = "S"  'spades
    Case Else
    End Select
    
    For y = 14 To 2 Step -1
            'Debug.Print y
            Select Case y
            Case 14
                card = "A"
            Case 13
                card = "K"
            Case 12
                card = "Q"
            Case 11
                card = "J"
            Case Else
                card = y
            End Select
            
            'Debug.Print suit, card
            deckofcards(z) = suit & card
            'Debug.Print deckofcards(z)
            z = z + 1
    Next
Next
For x = 0 To 52
    Debug.Print deckofcards(x)
Next
End Sub
 
loading deck of cards
HA
HK
HQ
HJ
H10
H9
H8
H7
H6
H5
H4
H3
H2
DA
DK
DQ
DJ
D10
D9
D8
D7
D6
D5
D4
D3
D2
CA
CK
CQ
CJ
C10
C9
C8
C7
C6
C5
C4
C3
C2
SA
SK
SQ
SJ
S10
S9
S8
S7
S6
S5
S4
S3
S2

 
 

if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.

© 2020 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.