Results 1 to 3 of 3

Thread: [RESOLVED] Random Images

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    22

    Resolved [RESOLVED] Random Images

    Need help with random this images.
    How to place random image (0 to 8 control array) to picturebox (0 to 8 control array)?

    I tried this code, but not working perfectly

    Private Sub Command1_Click()
    Dim i As Integer
    For i = 0 To 8
    Picture1(i).Picture = Image1(Rnd * 8).Picture
    Next i
    End Sub

    Thanks..

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Random Images

    Picture1(i).Picture = Image1(Int(Rnd * 9)).Picture

    If you want non-repeating random number so each image is only copied once maybe try something like this...
    Code:
    Private Sub Form_Load()
        Randomize
    End Sub
    
    Private Sub Command1_Click()
        Dim ByteCheck() As Byte, MyNum As Integer, Counter As Integer
        Const MaxNum = 9 ' 0 to 8
        ReDim ByteCheck(MaxNum)
        
        While Counter < MaxNum
            MyNum = Int(Rnd * MaxNum)
            If ByteCheck(MyNum) = 0 Then
                Picture1(Counter).Picture = Image1(MyNum).Picture
                ByteCheck(MyNum) = 1
                Counter = Counter + 1
            End If
        Wend
    
    End Sub
    Last edited by Edgemeal; Apr 6th, 2009 at 01:08 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    22

    Re: Random Images

    Many thanks Edgemeal..
    It works now..

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