Move images on VB6

Asked

Viewed 1,443 times

0

Option Compare Database

Private Sub Command0_Click()
    Do Until Me.Width < 4000
        Let Image1.Left = Image1.Left - 5
    DoEvents
    Loop
End Sub

Just like this allows you to move the image from the right side to the left how to make the image to rotate the entire fomulário,Without stopping with a button and without using the timer? Someone has an effective idea of how to do this?

  • 1

    Could you tell us why it doesn’t work?

  • 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.

  • 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

2 answers

1

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.

  • I tried to adjust this but it did not work yet not core

0

For what I wanted this would look like this:

Option Compare Database
Dim i As Integer
Private Sub Command1_Click()

For i = 1 To 900
Me.Width = 1000
Let Image3.left = Image3.left - 5
DoEvents
Next
For i = 900 To 1200
Me.Width = 1000
Let Image3.top = Image3.top + 5
DoEvents
Next
For i = 1800 To 2700
Me.Width = 1000
Let Image3.left = Image3.left + 5
DoEvents
Next
For i = 2700 To 3000
Me.Width = 1000
Let Image3.top = Image3.top - 5
DoEvents
Next
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.