how to stop repeating the same image showing out in the image list

Private Sub frmStart1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Call Timer.Start()
        Dim rd As New Random
        Dim c As Integer
        Dim lop As Integer = 0

        c = rd.Next(0, 4)

        Dim pb1 As Image = ImageList1.Images(c)
        c = rd.Next(0, 4)
        Dim pb2 As Image = ImageList1.Images(c)
        c = rd.Next(0, 4)
        Dim pb3 As Image = ImageList1.Images(c)
        c = rd.Next(0, 4)
        Dim pb4 As Image = ImageList1.Images(c)
        c = rd.Next(0, 4)
        Dim pb5 As Image = ImageList1.Images(c)

        Me.Pic1.Image = pb1
        Me.Pic2.Image = pb2
        Me.Pic3.Image = pb3
        Me.Pic4.Image = pb4
        Me.Pic5.Image = pb5

    End Sub
5 Years
Discussion Span
Last Post by on93

Why don't you try using an if statement to check if any of the picture box contains that image and if it does then it will to back and insert a new image eg. using the Example: and goto Example.

Does that make sense?

Votes + Comments
that can work...

You have to call Randomize() at the top or you will get the same sequence of numbers every time. Because you are working with such a small set of numbers (by the way, using (0,4) gets you a number from 0 to 3) you will very likely get duplicates. What you can do is generate a list of possible numbers such as {0,1,2,3,4} then generate a random number from 0 to list.Count - 1. That random number will be the index into the list. Once you pick that number you can remove it from the list thus ensuring it will not be repeated.


how to use the if else statement to compare the image ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.