?
Solved

loop function

Posted on 2003-03-06
9
Medium Priority
?
225 Views
Last Modified: 2010-08-05
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
Comment
Question by:pratty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8078363
>>While Command2.Left - 1560 ??

try:
While Command2.Left - 1560 > 4320 or add any comparison
0
 
LVL 2

Expert Comment

by:navneet77
ID: 8078416
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
 
LVL 2

Expert Comment

by:navneet77
ID: 8078476
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
Independent Software Vendors: 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!

 
LVL 1

Expert Comment

by:Fischermaen
ID: 8078587
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
 

Expert Comment

by:cocomobasic
ID: 8086391
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
 
LVL 3

Expert Comment

by:redfordb
ID: 8102528
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
 

Expert Comment

by:CleanupPing
ID: 8900595
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9074133
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9165907
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question