Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how best to pick random elements from an array?

Status
Not open for further replies.

pduncan

IS-IT--Management
Jun 20, 2003
203
US
let say I have 2 arrays - each array has 3 unique elements.

example:
arrayA("A", "B", "C")
arrayB("1", "2", "3")

I am assuming I would declare the arrays in a module ?

I want to press a button on a form which would open a msgbox (calls function) that would display a random selection from array A and a random selection from Array B.


like:

B2 - or - C1 - etc


can someone please help point me in the right direction?

Thanks, PDUNCAN
 
Look up RND() in VBA help.
Depending on how many elements your arrays have, you would set the range of the Random Function accordingly, don't forget arrays are zero based.
also since the Rnd() returns a SINGLE datatype, you will want to use the Int() function in conjunction with the Rnd()

& from the calling procedure, use Randomize.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top