473,421 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

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.
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
2 1294
lotus18
866 512MB
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
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

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

Similar topics

3
by: Gaffer | last post by:
Hello Is there a way in which I can make certain parts of Html on my website random so that each viewer will see different material if they refresh the page or come back onto the website later?...
1
by: Ellen Manning | last post by:
I've got an A2K database with a report that generates any number of random medical record numbers. The user inputs how many numbers they want and report uses the Randomizer function found on "The...
2
by: Rich | last post by:
Here is what I am trying for randomizing 2 numbers in the same subroutine so that they are not equal to each other: Dim j As Integer, k As Integer j = New System.Random().Next(0, 10) k = New...
1
by: Badass Scotsman | last post by:
Hello, This code is supposed to generate a random string each run, however I have had it live on a few sites, and it seems to create repeat strings all over the place. ...
6
by: mrtaka79 | last post by:
Okay, first of all, I'm a complete noob, so go easy on me. I have this code that works perfectly for me. The only thing I want to add is to randomize the pictures/links that show up. Can anyone...
1
by: VBSTUDENT | last post by:
I am just wondering if there is a way to randomize the aritmetic operators in code, I know how to randomize numbers but I am not sure if it is possible to randomize operators. Any help would be...
5
by: aaragon | last post by:
Hi everyone, I wrote a very simple function to try to understand the casting of variables in C++. The function is function foo() { std::vector<inttest(100); randomize(test); unsigned long...
7
by: aaragon | last post by:
Hi everyone, The idea is quite simple: generate a container with random values in it. For that, I decided to create a class that I called RandomContainer that inherits from a container (with...
1
by: EddyLLC | last post by:
I am using Randomize to generate a random number for each file I create. The program works fine on the development machine but no file are created when I tested on a clean machine. Am I missing a...
5
by: gggram2000 | last post by:
Hi, I'ved spent two full days trying to find a solution, I can randomize numbers between two ranges and it works fine, But my problem is when i want to randomize five numbers that I got. eg. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.