• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

loop function

Hey guys,
i have a simple code to make a button slide from one side of a form to another then back to its original position:

Private Sub Command1_Click()
While Command2.Left - 1560
Command2.Left = Command2.Left - 1
DoEvents
Wend
Command2.Left = 4320
End Sub

What i want is a loop function so that this will occur again and again untill the program is ended.

I have a feeling that it is something like this:
Private Sub Command1_Click()
While Command2.Left - 1560
Command2.Left = Command2.Left - 1
DoEvents
Wend
Command2.Left = 4320
****loop until EOF****
End Sub

or something like that.... if you can give me the code for the loop that would be great, thanks.

- Pratty
0
pratty
Asked:
pratty
1 Solution
 
Ryan ChongCommented:
>>While Command2.Left - 1560 ??

try:
While Command2.Left - 1560 > 4320 or add any comparison
0
 
navneet77Commented:
An easy way will be to add a timer in the form and do something like this

Private Sub Command1_Click()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
Timer1.Interval = 0

Do While Command2.Left > 0
DoEvents
Command2.Left = Command2.Left - 1
Loop
Command2.Left = 4320
Timer1.Interval = 1
End Sub

this will move the button for ever until the application is closed
0
 
navneet77Commented:
And pratty if you find that the application do not end when you close the form then you can try this

Dim frmunload As Boolean
Private Sub Command1_Click()
Timer1.Interval = 1
End Sub

Private Sub Form_Unload(Cancel As Integer)
frmunload = True
End Sub

Private Sub Timer1_Timer()
Timer1.Interval = 0

Do While Command2.Left > 0 And Not frmunload
DoEvents
Command2.Left = Command2.Left - 1
Loop
Command2.Left = 4320
If Not frmunload Then
Timer1.Interval = 1
Else
Unload Me
End If
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
FischermaenCommented:
Hi,

try this

Private Sub Command1_Click()
While Command2.Left - 1560
Command2.Left = Command2.Left - 1
DoEvents
if Command2.Left = 1 then Command2.Left = 4320
Wend
End Sub
0
 
cocomobasicCommented:
try this;

Private Sub Command1_Click()
While Command2.Left - 1560
Command2.Left = Command2.Left - 1
DoEvents
Wend
Command2.Left = 4320

'just add this line to your original code
Call Command1_Click       ' call the event again

End Sub
0
 
redfordbCommented:
Private Sub Command1_Click()
    Command2.Left = Me.ScaleWidth - Command2.Width
    While Command2.Left > 0
        While Command2.Left > 0
            Command2.Left = Command2.Left - 1
            DoEvents
        Wend
        Command2.Left = Me.ScaleWidth - Command2.Width
    Wend
End Sub
0
 
CleanupPingCommented:
pratty:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
pratty, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 
YensidModCommented:
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now