This example uses the Mod operator to determine the value of a randomly selected card where card 1 is the ace (1) of clubs and card 52 is the king (13) of spades. Since the values recur in a sequence of 13 cards within 4 suits, we can use the Mod function to determine the value of any given card number.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
cval$ = "Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King"
Randomize
card% = Random(1,52)
value = card% Mod 13
If value = 0 Then value = 13
CardNum$ = Item$(cval,value)
If card% < 53 Then suit$ = "Spades"
If card% < 40 Then suit$ = "Hearts"
If card% < 27 Then suit$ = "Diamonds"
If card% < 14 Then suit$ = "Clubs"
msg1 = "Card number " & card% & " is the "
msg1 = msg 1& CardNum & " of " & suit$
MsgBox msg1
End Sub
|