|
-
Nov 14th, 2000, 08:25 AM
#1
Thread Starter
Hyperactive Member
Hi,
I want to do this:
A random number, rstudents, is chosen between 24 and 360.
A random number,rprojects, is chosen between 4 and 6 inclusive.
Then 4 or 6 random numbers, depending on rprojects, are chosen to add up to rstudents.
The results are printed in a picturebox. For example:
----------
rstudents = 120
rprojects = 4
20 36 54 10
--------
The problem is that there can be a delay of a good few seconds, sometimes minutes, before a result comes up. Please take a look at my code. I have a 700Mhz, so that's not the problem.
Thanks!
---------------
Option Explicit
Dim rstudents As Integer
Dim rprojects As Integer
Dim rfirst As Integer
Dim rsecond As Integer
Dim rthird As Integer
Dim rfourth As Integer
Dim rfifth As Integer
Dim rsixth As Integer
Private Sub Command1_Click()
Randomize
rprojects = Int(Rnd * 3) + 4
rstudents = Int(Rnd * 360) + 24
Picture1.Cls
Picture1.Print rstudents
Picture1.Print rprojects
Dim blDone As Boolean
Do
Randomize
rfirst = Int(Rnd * rstudents)
rsecond = Int(Rnd * rstudents)
rthird = Int(Rnd * rstudents)
rfourth = Int(Rnd * rstudents)
rfifth = Int(Rnd * rstudents)
rsixth = Int(Rnd * rstudents)
Select Case rprojects
Case 4
If rfirst + rsecond + rthird + rfourth = rstudents Then
blDone = True
Picture1.Print rfirst & " " & rsecond & " " & rthird & " " & rfourth
End If
Case 5
If rfirst + rsecond + rthird + rfourth + rfifth = rstudents Then
blDone = True
Picture1.Print rfirst & " " & rsecond & " " & rthird & " " & rfourth & " " & rfifth
End If
Case 6
If rfirst + rsecond + rthird + rfourth + rfifth + rsixth = rstudents Then
blDone = True
Picture1.Print rfirst & " " & rsecond & " " & rthird & " " & rfourth & " " & rfifth & " " & rsixth
End If
End Select
Loop Until blDone = True
End Sub
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
|