Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB Question

Options
  • 28-01-2002 9:12pm
    #1
    Registered Users Posts: 1,182 ✭✭✭


    Just wondering if any of ye code guru's could tell me how to generate a random number between 1 and 100 in VB!?
    Cheers,

    Beef. :)


Comments

  • Registered Users Posts: 707 ✭✭✭d4r3n


    Randomize
    MsgBox Int((High - Low + 1) * Rnd) + Low


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Randomize : MsgBox Int(100 * Rnd) + 1


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Randomize

    Shouldn't that be Randomize Timer ? Wouldn't the radomize reset the seed with the same value all the time? or did they change that for VB?


  • Registered Users Posts: 16,409 ✭✭✭✭Trojan


    Originally posted by Hobbes
    Randomize

    Shouldn't that be Randomize Timer ? Wouldn't the radomize reset the seed with the same value all the time? or did they change that for VB?

    Maybe that's in an older version. Just Randomize should work fine with VB5 or 6.


    Rand(range start, range end) should do fine.
    dim x%, y%
    
    Randomize
    
    x = Rnd
    y = Rand(1, 100)
    

    Al.


  • Registered Users Posts: 1,182 ✭✭✭Beef


    Sher it worked fine! Cheers!(Just Randomize works btw)
    :D


  • Advertisement
  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Shouldn't that be Randomize Timer ? Wouldn't the radomize reset the seed with the same value all the time? or did they change that for VB?

    Randomize Timer is still allowed for backwards compatibility, but Randomize with no argument is taken to be equivalent.


Advertisement