Solved

# Generate random image placements without reusing the placement

Posted on 2004-10-30

Ok so here's my code

spin is a button

P1 is a picture array and there are 4 of them

timer1 is a timer

Private Sub spin_Click()

If spin.Caption = "SPIN" Then

spin.Caption = "STOP"

Else

spin.Caption = "SPIN"

End If

If Timer1.Enabled = True Then

Timer1.Enabled = False

Else

Timer1.Enabled = True

End If

End Sub

Private Sub Timer1_Timer()

For i = 0 To 3

If P1(i).Left = "2520" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "3720" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "5280" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

ElseIf P1(i).Left = "6480" Then

P1(i).Left = Rnmp

P1(i).Top = Rnmp

End If

Randomize

Rnmp = Int(Rnd * 4) + 1

Select Case Rnmp

Case "1"

P1(i).Top = "4680"

P1(i).Left = "2520"

Case "2"

P1(i).Top = "3480"

P1(i).Left = "3720"

Case "3"

P1(i).Top = "3480"

P1(i).Left = "5280"

Case "4"

P1(i).Top = "4680"

P1(i).Left = "6480"

End Select

Next i

l1.Caption = P1(0).Left & " " & P1(0).Top

l2.Caption = P1(1).Left & " " & P1(1).Top

l3.Caption = P1(2).Left & " " & P1(2).Top

l4.Caption = P1(3).Left & " " & P1(3).Top

End Sub

l1, l2, l3 and l4 are labels that show the positions of the pictures and they DO show that the pictures are overlapping

What happens with this code is the 4 pictures start in designated places, which are equivalent to each of the 4 cases. Picture one starts where case 1 is, picture 2 where case 2 is, etc.

The problem arises when I start "spinning" or moving the images. I want them to move to one of the case points other than where they start, and NOT overlapping another image where they currently do. They need to pick their own unused space and then keep moving to a different one.

How is this possible?

Thanks in advance,

Mike