Results 1 to 5 of 5

Thread: Random Numer

  1. #1

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Random Numer

    how do i generate random number in vb ?

  2. #2
    Addicted Member makster246's Avatar
    Join Date
    Dec 2004
    Location
    nottingham
    Posts
    187

    Re: Random Numer

    first in the forms load event write:

    "randomize"

    then when you wish to call a random number write:

    "variablex = rnd()* 100" '<----will give you a random number 1 - 100


    hope it helps

    rob

  3. #3
    Member manavo's Avatar
    Join Date
    Feb 2002
    Posts
    33
    Alter ego

  4. #4
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Exclamation Re: Random Numer

    here's a handy little piece of code:

    VB Code:
    1. Public Function RandomNumber(Min as Double, Max as Double, Optional WholeNumber as Boolean = True)
    2.     If WholeNumber = True then
    3.         RandomNumber = Int(Rnd() * (Max - Min) + Min)
    4.     Else
    5.         RandomNumber = Rnd() * (Max - Min) + Min
    6.     End If
    7. End Function
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  5. #5

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Resolved Re: Random Numer

    job done, but da last code is more helpful !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width