Friday, November 19, 2010

How do you generate integers in VB?

More specifically I need to generate 50 random integers in 1 textbox. I figured out how to generate one, but not 50. Any help appreciated!How do you generate integers in VB?
dim iRnd(50) as integer

sub rndSub

' Initialize the random-number generator.

Randomize()

' Generate random value between 1 and 100.

Dim value As Integer

dim i as integer



for i = 0 to 49

iRnd(i) = (Int((100 * Rnd()) + 1) ' iRnd is global, so after exiting the sub you can access it

next i

end subHow do you generate integers in VB?
You'll need to use an array. Sorry, I don't know VB syntax (thank goodness). I think they use something called ';dim';. But I advise anyone using VB to stop immediately and switch to something like C++, C# or Java (all are free). But, if you really need to know this, Google is your friend. Search for ';VB array';, ';Visual Basic array'; or ';Visual Basic dim';. HTH

No comments:

Post a Comment