By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

Simple Randomize Help

P: 24
I am on my way to making a card game but i was wondering how i would get a random card out of one of these to pop out to a picture box for a test, ty.
Expand|Select|Wrap|Line Numbers
  1. Dim arnCards(52) As String
  2. Private Sub Command1_Click()
  3.     arnCards(0) = "C-Ace"
  4.     arnCards(1) = "C-King"
  5.     arnCards(2) = "C-Queens"
  6.     arnCards(3) = "C-Jacks"
  7.     arnCards(4) = "C-10"
  8.     arnCards(5) = "C-9"
  9.     arnCards(6) = "C-8"
  10.     arnCards(7) = "C-7"
  11.     arnCards(8) = "C-6"
  12.     arnCards(9) = "C-5"
  13.     arnCards(10) = "C-4"
  14.     arnCards(11) = "C-3"
  15.     arnCards(12) = "C-2"
  16.     For i = 0 To 12
  17.         Picture1.Print '
  18.     Next
  19. End Sub
  20.  
btw i use vb6
Nov 26 '07 #1
Share this Question
Share on Google+
2 Replies


lotus18
100+
P: 866
I am on my way to making a card game but i was wondering how i would get a random card out of one of these to pop out to a picture box for a test, ty.
Expand|Select|Wrap|Line Numbers
  1. Dim arnCards(52) As String
  2. Private Sub Command1_Click()
  3.     arnCards(0) = "C-Ace"
  4.     arnCards(1) = "C-King"
  5.     arnCards(2) = "C-Queens"
  6.     arnCards(3) = "C-Jacks"
  7.     arnCards(4) = "C-10"
  8.     arnCards(5) = "C-9"
  9.     arnCards(6) = "C-8"
  10.     arnCards(7) = "C-7"
  11.     arnCards(8) = "C-6"
  12.     arnCards(9) = "C-5"
  13.     arnCards(10) = "C-4"
  14.     arnCards(11) = "C-3"
  15.     arnCards(12) = "C-2"
  16.     For i = 0 To 12
  17.         Picture1.Print '
  18.     Next
  19. End Sub
  20.  
btw i use vb6
Try to use randomize : )

Rey Sean
Nov 27 '07 #2

P: 4
Hey

Dim randomnumber As Integer
Randomize
randomnumber = Int(Rnd(1) * 52)

This will give you a random number between 0 and 51 (because from your array list you are starting using array element 0).
Then just simply use
filename = arncards(randomnumber)
to set a string a random cards name from your list.
You can adapt this in order to display the card in whatever way you wish.

Hope this helps.
Nov 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.