Results 1 to 2 of 2

Thread: syntax for for nested loops

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    4
    I have a pool of ten numbers, I need to test that none are identical. each number in an element of an array. The numbers are random, but the problem I run into is that sometimes they are identical numbers. How can I get around this?

    MrBeta

  2. #2
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Try this:
    Code:
       Dim aiNumbers(1 To 10) As Integer
       Dim iTemp As Integer
       Dim iElement As Integer
       Dim idx As Integer
       
       Randomize
       
       Do
          iTemp = Rnd(100) * 100
       
          For idx = LBound(aiNumbers) To UBound(aiNumbers) Step 1
          
             If iTemp = aiNumbers(idx) Then
                iTemp = -1
                Exit For
             End If
          
          Next idx
          
          If iTemp <> -1 Then
             iElement = iElement + 1
             aiNumbers(iElement) = iTemp
             Debug.Print aiNumbers(iElement)
          End If
       
       Loop While iElement < 10
    Hope this is what you were looking for.

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