|
-
May 20th, 2003, 04:06 PM
#2
There are many ways to do what I believe you're suggesting.
The fastest, easiest way, for me is something like the following:
VB Code:
Dim I_WAS_SELECTED() As Boolean
Dim SelCount As Integer
Dim MyUpper As Integer
Private Sub Command1_Click()
Randomize
Dim SELECTED_1_Thru_MyUpper As Integer '
If SelCount = MyUpper Then
Call REDIM_IT
MsgBox "Starting Over Again!"
End If
SELECTED_1_Thru_MyUpper = Int(Rnd * MyUpper )
While I_WAS_SELECTED(SELECTED_1_Thru_MyUpper ) = True
SELECTED_1_Thru_MyUpper = (SELECTED_1_Thru_MyUpper + 1) Mod MyUpper
Wend
SelCount = SelCount + 1
I_WAS_SELECTED(SELECTED_1_Thru_MyUpper ) = True
SELECTED_1_Thru_MyUpper = SELECTED_1_Thru_MyUpper + 1 '0 thru 14 equiv to 1 thru 15
MsgBox "Number " & SelCount & " Is " & (SELECTED_1_Thru_MyUpper )
End Sub
Private Sub Form_Load()
MyUpper = 15
Call REDIM_IT
End Sub
Private Sub REDIM_IT()
ReDim I_WAS_SELECTED(MyUpper - 1)
SelCount = 0
End Sub
As you can see, an array dimmed as boolean keeps track of whats been chosen. When a random selection is made, if that has been chosen already, the number is incrimented modularly, until an unchosen number is found.
Also, if all the numbers have been chosen, then you reset the arrays and the counter, and start all over again.
However, this is NOT the recommended way to do it, since it still is a time consuming process.
I believe Guv, Jim Macnemara {sp?}, MartinLiss or Plenderj have a good "shuffling" system somewhere around here.
And, I have a way useing copymem to remove elements from an array, without leaving holes, and then reinserting them back in the original order, which is definitely applicable to this problem.
-Lou
Last edited by NotLKH; May 20th, 2003 at 04:22 PM.
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
|