Results 1 to 4 of 4

Thread: [RESOLVED] I need to add a random number BETWEEN 10 - 30 to a List?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Resolved [RESOLVED] I need to add a random number BETWEEN 10 - 30 to a List?

    I need to add a random number BETWEEN 10 - 30 to a List?

    How would I do this?
    8 gigs/ram (hey why not)
    300 gig HD x2
    Windows XP 64

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: I need to add a random number BETWEEN 10 - 30 to a List?

    Randomize a value between 0 - 20 and add ten, then include this value into the listbox.

    List1.AddItem (Fix(Rnd * 21) + 10)

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: I need to add a random number BETWEEN 10 - 30 to a List?

    You could try this.

    VB Code:
    1. Private Function RandomNum(ByVal Lowest As Long, ByVal Highest As Long) As Long
    2.     RandomNum = Int((Highest - Lowest) * Rnd + Lowest)
    3. End Function
    4.  
    5. Private Sub Command1_Click()
    6.     list1.AddItem CStr(RandomNum(10, 30))
    7. End Sub
    8.  
    9. Private Sub Form_Load()
    10.     Randomize
    11. End Sub

    Didn't test it but it should work.

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: I need to add a random number BETWEEN 10 - 30 to a List?

    Quote Originally Posted by Merri
    Randomize a value between 0 - 20 and add ten, then include this value into the listbox.

    List1.AddItem (Fix(Rnd * 21) + 10)
    Yea or you could just do that.

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