Results 1 to 4 of 4

Thread: This should be easy

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    6

    This should be easy

    i got 16 labels in a control array from 1 to 16, and i want the numbers 1 to 16 apear randomly in each one without any repetitions.

    Could anyone help me do this? i always end up having a few empty labels and i dont know how to fix this.

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    this should work:


    VB Code:
    1. Private Sub Command1_Click()
    2. Randomize
    3.  
    4. For i = Label1.LBound To Label1.UBound
    5.     Label1(i).Caption = "" 'empty all captions
    6. Next
    7.  
    8. For i = Label1.LBound To Label1.UBound
    9. ReRnd:
    10.     TempIndex = Round(Rnd * Label1.UBound) 'new random nr
    11.     If Label1(TempIndex).Caption = "" Then 'if caption is empty
    12.         Label1(TempIndex).Caption = i + 1 'fill it with nr
    13.     Else
    14.         GoTo ReRnd 'if caption is already filled, get a new label
    15.     End If
    16. Next
    17. End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    oh....your array is from 1-16....then you have to change the line
    Label1(TempIndex).Caption = i + 1
    to
    Label1(TempIndex).Caption = i
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    oh, and you also have to change the line:
    TempIndex = Round(Rnd * Label1.UBound)
    to
    TempIndex = Round(Rnd * (Label1.UBound - 1)) + 1
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

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