|
-
Aug 14th, 2000, 01:22 PM
#1
Thread Starter
Hyperactive Member
Hi there,
Over a month ago I posted a message on making a random number of numbers, from 4 to 8 numbers, appear in sequence:
e.g: 1,3,4,7 or 3,7,8,10,12,13 etc....
I got some useful code but it was way over my head (for the moment), so I tried to do it in a way I could relate to.
I managed to do it using the code below, but I'd appreciate it someone could help me cut it down a bit - I think the IIF statement can do it, but I don't know how.
Anyway, here it goes:
'a command button and picturebox
Private Sub Command1_Click()
Picture1.Cls
Randomize
'decide the number of numbers, from 4 to 8, to print
Dim numbertoprint As Integer
numbertoprint = Int(Rnd * 5) + 4
Dim firstofsequence As Integer
Dim secondofsequence As Integer
Dim thirdofsequence As Integer
Dim fourthofsequence As Integer
Dim fifthofsequence As Integer
Dim sixthofsequence As Integer
Dim seventhofsequence As Integer
Dim eigthofsequence As Integer
firstofsequence = Int(Rnd * 4) + 1
secondofsequence = firstofsequence + Int(Rnd * 3) + 1
thirdofsequence = secondofsequence + Int(Rnd * 3) + 1
fourthofsequence = thirdofsequence + Int(Rnd * 3) + 1
fifthofsequence = fourthofsequence + Int(Rnd * 3) + 1
sixthofsequence = fifthofsequence + Int(Rnd * 3) + 1
seventhofsequence = sixthofsequence + Int(Rnd * 3) + 1
eigthofsequence = seventhofsequence + Int(Rnd * 3) + 1
If numbertoprint = 4 Then
'Can I use the IIF statement here?
Picture1.Print firstofsequence & "," & secondofsequence & "," & _
thirdofsequence & "," & fourthofsequence
End If
If numbertoprint = 5 Then
Picture1.Print firstofsequence & "," & secondofsequence & "," & _
thirdofsequence & "," & fourthofsequence & "," & fifthofsequence
End If
If numbertoprint = 6 Then
Picture1.Print firstofsequence & "," & secondofsequence & "," & _
thirdofsequence & "," & fourthofsequence & "," & fifthofsequence & _
"," & sixthofsequence
End If
If numbertoprint = 7 Then
Picture1.Print firstofsequence & "," & secondofsequence & "," & _
thirdofsequence & "," & fourthofsequence & "," & fifthofsequence & _
"," & sixthofsequence & "," & seventhofsequence
End If
If numbertoprint = 8 Then
Picture1.Print firstofsequence & "," & secondofsequence & "," & _
thirdofsequence & "," & fourthofsequence & "," & fifthofsequence & _
"," & sixthofsequence & "," & seventhofsequence & "," & eigthofsequence
End If
End Sub
Thanks for any help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|