Hi,

My code below generates a random number from -20 to 20. When command2 is clicked, the whole number factors of that number generated are listed in Picture2.

My problem is that I don't want factors to be repeated.

For example, the random number generated in picture1, might be 6.

When command2 is clicked the factors listed will be:

-6 and -1
-3 and -2
-2 and -3
-1 and -6
1 and 6
2 and 3
3 and 2
6 and 1

You'll notice that factors are repeated, just in different order. Any ideas how I could have the above looking like:

-6 and -1
-3 and -2
1 and 6
2 and 3

Thanks for any help! I include my code below.

Dim number As Integer
Dim x As Integer

Private Sub Command1_Click()
Randomize
number = Int(Rnd * 40) - 20
Picture1.Cls
Picture1.Print number
End Sub

Private Sub Command2_Click()
Picture2.Cls
'Prevent backward For - To's like 7 to -7
'if the number generated is less than 0, for example: -7
If number < 0 Then
'd will equal -7
d = number
'and e will equal --7, i.e: +7, so we go from -7 to 7 rather than
'7 to -7, which For- To doesn't deal with
e = -number
Else:
d = -number
e = number
End If
For x = d To e
'avoid division by 0 - gives an error
If x = 0 Then
x = 1
End If
'make sure we get a whole number factor
If number Mod x = 0 Then
'print all factors
Picture2.Print x & " and " & number / x
End If
Next
End Sub