Simple Randomize Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • halo combat22
    New Member
    • Oct 2007
    • 24

    Simple Randomize Help

    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.
    Code:
    Dim arnCards(52) As String
    Private Sub Command1_Click()
        arnCards(0) = "C-Ace"
        arnCards(1) = "C-King"
        arnCards(2) = "C-Queens"
        arnCards(3) = "C-Jacks"
        arnCards(4) = "C-10"
        arnCards(5) = "C-9"
        arnCards(6) = "C-8"
        arnCards(7) = "C-7"
        arnCards(8) = "C-6"
        arnCards(9) = "C-5"
        arnCards(10) = "C-4"
        arnCards(11) = "C-3"
        arnCards(12) = "C-2"
        For i = 0 To 12
            Picture1.Print '
        Next
    End Sub
    btw i use vb6
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by halo combat22
    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.
    Code:
    Dim arnCards(52) As String
    Private Sub Command1_Click()
        arnCards(0) = "C-Ace"
        arnCards(1) = "C-King"
        arnCards(2) = "C-Queens"
        arnCards(3) = "C-Jacks"
        arnCards(4) = "C-10"
        arnCards(5) = "C-9"
        arnCards(6) = "C-8"
        arnCards(7) = "C-7"
        arnCards(8) = "C-6"
        arnCards(9) = "C-5"
        arnCards(10) = "C-4"
        arnCards(11) = "C-3"
        arnCards(12) = "C-2"
        For i = 0 To 12
            Picture1.Print '
        Next
    End Sub
    btw i use vb6
    Try to use randomize : )

    Rey Sean

    Comment

    • the tin man
      New Member
      • Oct 2007
      • 4

      #3
      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(random number)
      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.
      Last edited by Killer42; Nov 27 '07, 09:54 PM.

      Comment

      Working...