First I would abandon your variable Indo
. In which case, I’d use a Enum
:
Enum Movimento
Cima
Baixo
Esquerda
Direita
End Enum
And declare a variable called mov
:
Dim mov as Movimento
In this case, the Sub
would have to, instead of a If
, one Select Case
:
Select Case mov
Case Movimento.Cima
Picture1.Left = Picture1.Top - 10
'Se bateu em cima, vai pra esquerda
If Picture1.Top >= ScaleHeight - Picture1.Height Then
mov = Movimento.Esquerda
Picture1.Top = ScaleHeight - Picture1.Height
Exit Do
End If
Case Movimento.Baixo
Picture1.Left = Picture1.Top + 10
'Se bateu em cima, vai pra esquerda
If Picture1.Top >= ScaleHeight - Picture1.Height Then
mov = Movimento.Direita
Picture1.Top = ScaleHeight - Picture1.Height
Exit Do
End If
Case Movimento.Esquerda
Picture1.Left = Picture1.Left + 10
'Se bateu no lado direito, vai pra baixo
If Picture1.Left >= ScaleWidth - Picture1.Width Then
mov = Movimento.Baixo
Picture1.Left = ScaleWidth - Picture1.Width
Exit Do
End If
Case Else ' Ou seja, Movimento.Direita
Picture1.Left = Picture1.Left - 10
'Se bateu no lado esquero, sobe.
If Picture1.Left <= 0 Then
mov = Movimento.Cima
Picture1.Left = 0
Exit Do
End If
End Select
This code will definitely need some adjustment, but it has the general idea.
Could you tell us why it doesn’t work?
– Leonel Sanches da Silva
Gypsy I want the image to circulate in all corners of the form( the image should go around on the form without the preferred timer in Excel.vba or vb6). it is possible to create a cycle able to do this I have a test related to it I appreciate the help.
– user7752
imagine that you have a ball initially the ball is in the lower left corner but you have to move up then to the right side, then down back to the left side (as if you were going around the house and back to the starting position )how would this look using a select,for,while, or other loop statement. Access or Excel.vba
– user7752