-
Feb 22nd, 2012, 11:28 AM
#1
Thread Starter
New Member
object moving help(vb 6)
i need help in thisss. i have a task that to move a Button in vb6 to move that in rectangular motion ..
i m able to move it only once to move it in rectangular path.. soo i need hellp to move it constantly on the form if any1 can plz help??
here is the code frm code window
Private Sub Timer1_Timer()
Dim a
a = Command1
If Command1.Top > 5000 Then
Timer1.Interval = 0
Else
Command1.Top = Command1.Top + 100
End If
End Sub
Private Sub Timer2_Timer()
If Timer1.Interval = 0 Then
Command1.Left = Command1.Left + 100
End If
End Sub
Private Sub Timer3_Timer()
If Command1.Left > 6000 Then
Timer2.Interval = 0
End If
End Sub
Private Sub Timer4_Timer()
If Timer2.Interval = 0 Then
Command1.Top = Command1.Top - 100
End If
End Sub
Private Sub Timer5_Timer()
If Command1.Top < 240 Then
Timer4.Interval = 0
End If
End Sub
Private Sub Timer7_Timer()
If Timer4.Interval = 0 Then
Command1.Left = Command1.Left - 100
End If
End Sub
Private Sub Timer8_Timer()
Timer7.Interval = 0
test
End Sub
-
Feb 22nd, 2012, 01:09 PM
#2
Re: object moving help(vb 6)
Can't really tell what you are trying to do but you surely do not need 8 timers to do it.
1 timer and a little conditional logic should do the trick.
-
Feb 22nd, 2012, 01:09 PM
#3
Re: object moving help(vb 6)
You only need 1 timer, not 8.
1) Use a static or form-level variable to keep track of current direction the button is moving
2) Based on that direction, check for movement boundary & change direction as needed
Code:
Dim m_Direction As Long
Private Sub Timer1_Timer()
Select Case m_Direction
Case 0 ' left
If Command1.Left - 100 =< 240 Then
Command1.Left = 240
m_Direction = m_Direction + 1 ' change directions
Else
Command1.Left = Command1.Left - 100
End If
Case 1 ' up
... fill in this part
Case 2 ' right
... fill in this part
Case 3 ' down
If Command1.Top + 100 >= 5000 Then
Command1.Top = 5000
m_Direction = 0 ' start over
Else
Command1.Top = Command1.Top + 100
End If
End Select
End Sub
-
Feb 22nd, 2012, 01:48 PM
#4
Re: object moving help(vb 6)
Try this
vb Code:
Private Enum MovingDirection MovingUp MovingRight MovingDown MovingLeft End Enum Private Type MovingBound MinTop As Long MinLeft As Long MaxTop As Long MaxLeft As Long MovingStep As Long End Type Private CurrentDirection As MovingDirection Private MovingArea As MovingBound Private Sub Form_Load() CurrentDirection = MovingUp MovingArea.MinTop = 1000 MovingArea.MinLeft = 1000 MovingArea.MaxTop = 4000 MovingArea.MaxLeft = 6000 MovingArea.MovingStep = 200 Command1.Top = MovingArea.MinTop Command1.Left = MovingArea.MinLeft Timer1.Interval = 100 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() If CurrentDirection = MovingUp Then Command1.Top = Command1.Top - MovingArea.MovingStep If Command1.Top <= MovingArea.MinTop Then CurrentDirection = MovingRight End If ElseIf CurrentDirection = MovingRight Then Command1.Left = Command1.Left + MovingArea.MovingStep If Command1.Left >= MovingArea.MaxLeft Then CurrentDirection = MovingDown End If ElseIf CurrentDirection = MovingDown Then Command1.Top = Command1.Top + MovingArea.MovingStep If Command1.Top >= MovingArea.MaxTop Then CurrentDirection = MovingLeft End If ElseIf CurrentDirection = MovingLeft Then Command1.Left = Command1.Left - MovingArea.MovingStep If Command1.Left <= MovingArea.MinLeft Then CurrentDirection = MovingUp End If End If End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|