Visual Basic - Load Deck of Cards into an array
by Mountain Computers Inc., Publication Date: Wednesday, July 22, 2020
View Count: 1383, Keywords: Visual Basic, Deck of Cards, Hashtags: #VisualBasic #DeckofCards
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.
© 2024 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.