Results 1 to 25 of 25

Thread: [RESOLVED] Randomize forms in VB6

Threaded View

  1. #5

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    12

    Re: Randomize forms in VB6

    Quote Originally Posted by Lenggries View Post
    In terms of randomization, what you are trying to do is called random selection without replacement. This basically means you are trying to do the equivalent of putting 40 numbers into a hat and pulling them out WITHOUT replacing them.
    Exactly. Thank you for the correct term. I really have been trying to figure out what it's called. I've been referencing it as a pseudo-random.

    Code:
    Private Sub cmdNext_Click()
    
    Dim arrValues(40) As Long
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim lngTemp As Long
    
    'seed the array with numbers 1 - 40
    For i = 1 To 40
       arrValues(i) = i
    Next i
    
    'shuffle it 7 times
    For i = 1 To 7
       'iterate through the deck
       For j = 1 To 40
          'get random location to swap with
          k = Rand(1, 40)
    
          'swap the values
          lngTemp = arrValues(j)
          arrValues(j) = arrValues(k)
          arrValues(k) = lngTemp
       Next j
    Next i
    
    For i = 1 To 40
       Select Case arrValues(i)
          Case 1
             frm1.Show
          Case 2
             frm2.Show
          Case 3
             frm2.Show
          Case 4
             frm4.Show
    etc..
          Case 40
             frm40.Show
    Note... this only gets you a random list. Reorganizing your forms is another matter entirely. Good luck
    That works perfectly! Thank you. Now, this probably what you meant in your last sentence, but is there a command or block of code to only have one appear at a time? If I run it now, I get 41 screens and then it freezes and I have to force quit.
    Last edited by vdriscoll; Mar 19th, 2010 at 03:07 PM.

Tags for this Thread

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