View Full Version : visual basic :8 numbers
alaios
05-01-2003, 09:31 PM
Hi i have 8 numbers ...1,2,3,4,5,6,7,8
Do u know the easiest way to put them in a random order with visual basic?
sir pannels
05-02-2003, 12:31 AM
hmm, sort them into arrays and then call a random one, er lol... dont know how tho not random part tho, try searching for sorting or random variables in VB in google or such like?
im sure one of the VB gurus here know however :)
Phantom
05-02-2003, 03:42 AM
Dim x as Integer
x = Rnd(1 <= x <= 8)
I haven't coded in VB for awhile, so I'm not quite sure about the Rnd function. I do know that Rnd picks a random number (between 0 and 1, unless otherwise specified). I'm not sure if I have it right though. 1 <= x <= 8 though is the way to go for that :-P
oracleguy
05-02-2003, 07:53 PM
Actually you do it like,
Randomize
intX=int((rnd*UpperBound)+LowerBound)
Now if you are just doing the numbers 1-8 then you can use the afore mentioned method, however if you have a 8 numbers that could contain random values, you can do something like this
Dim strNumbers as String, aryNumbers() as Integer, intX as integer
strNumbers="1,4,5,7,9,12,2,14"
aryNumbers()=Split(strNumbers, ",")
Randomize
intX=aryNumbers(int(rnd*ubound(aryNumbers))+0))
Try that out.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.