Results 1 to 2 of 2

Thread: Easy random list thing

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Kent, UK
    Posts
    41

    Unhappy

    Easy random list thing --->

    How do you add a list of random numbers, say from 1 to 15, into a listbox without any repeats?

    It's has been doing my head in big time!

    Thank you for any advice...

    But please hurry, as my head is going to implode soon!
    mooney

    I am fully qualified in the following: -

    MS Visual Basic-Version Zero
    God I'm Stupid-Enterprize Edition

  2. #2
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    yup ..

    Here you go,
    just make a list on a form.. and copy this!

    Code:
    Private Sub Form_Load()
    Dim Hist(14) As Integer
    Dim cHist As Integer
    Dim I As Integer
    Dim C As Integer
    
    Randomize
    StartOver:
    I = Int(Rnd * 13.99) + 1 'Will Select 1 - 14
    
    For C = 0 To 14
    	 If Hist(C) = I Then GoTo StartOver
    Next
    	 Hist(cHist) = I
    	 cHist = cHist + 1
    	 If cHist <> 14 Then
    		  GoTo StartOver
    	 Else
    		  For C = 0 To 14
    				List1.AddItem Hist(C)
    		  Next
    	 End If
    End Sub
    
    'Code improved by vBulletin Tool (Save as...)

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