473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Pausing Code

HP
Hi,

Does anyone know if it is possible to force the code to pause during every
iteration of a FOR ... NEXT loop, and wait for the user to click a command
button for the next iteration. I need to let the user step through the
looping at his/her own pace.

Any help would be greatly appreciated.

h.
Jul 17 '05 #1
6 3040
"HP" <no****@nospam.com.au> wrote
Hi,

Does anyone know if it is possible to force the code to pause during every
iteration of a FOR ... NEXT loop, and wait for the user to click a command
button for the next iteration. I need to let the user step through the
looping at his/her own pace.

Any help would be greatly appreciated.

Don't use a For/Next loop. Make the counter a larger scope so that
you can save it between calls.

LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2
"...And the next sign of the Apocalypse will be..."
*****
On Tue, 20 Jan 2004 07:27:12 +1000, HP wrote:
Hi,

Does anyone know if it is possible to force the code to pause during every
iteration of a FOR ... NEXT loop, and wait for the user to click a command
button for the next iteration. I need to let the user step through the
looping at his/her own pace.

Any help would be greatly appreciated.

h.


If it was me, I'd have the button change a shared variable to indicate
that it's been clicked, and have your code check for that, like this:
Private wasClicked as Boolean

Sub myLoop()
For n = 1 To 9
Do Until wasClicked
DoEvents
Loop
wasClicked = False
'your code here
Next
End Sub

Sub Button1_Click()
wasClicked = True
End Sub

Alternately, you could write the code to run when the button was
clicked, and keep track of where it was using a static variable, like
this:
Sub Button1_Click()
Static x As Integer
x = x + 1 'replace 1 with the low end of your loop
If x <= 9 Then 'replace 9 with the high end of your loop
'your code here
End If
End Sub
....but then you'd have to figure out how to reinitialize the "loop" if
you ran it more than once.
Jul 17 '05 #3
"Auric__" <no*********@email.address> wrote in
If it was me, I'd have the button change a shared variable to indicate
that it's been clicked, and have your code check for that, like this:
Private wasClicked as Boolean

Sub myLoop()
For n = 1 To 9
Do Until wasClicked
DoEvents
Loop
wasClicked = False
'your code here
Next
End Sub

Sub Button1_Click()
wasClicked = True
End Sub

Go to 4, then close the app.... (if you can <g>)

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #4
"...And the next sign of the Apocalypse will be..."
*****
On Mon, 19 Jan 2004 17:35:37 -0600, Larry Serflaten wrote:
"Auric__" <no*********@email.address> wrote in
If it was me, I'd have the button change a shared variable to indicate
that it's been clicked, and have your code check for that, like this:

<snip code>
Go to 4, then close the app.... (if you can <g>)

LFS


Feh. Who ever closes apps before they're totally done? <g> It's a simple
matter to add another flag to watch for the form closing. Or just add
"End" to the form's Unload event.

But on reflection, you're right - my second snippet (which is pretty
much the same as what you suggested all of 10 minutes earlier, but I
missed until later) is probably better.
Jul 17 '05 #5
All that HP is looking for is a way to pause at each iteration of a For/Next
Loop.
What's wrong with -
For i% = 1 To 50
'Do your stuff
Answer = MsgBox("This is iteration #" & Format$(i%, "##") & Chr$(13) &
"Press OK to continue, Cancel to end", vbOKCancel + vbDefaultButton1, "Any
title")
If Answer = vbCancel Then Exit For
Next i%
"HP" <no****@nospam.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
Hi,

Does anyone know if it is possible to force the code to pause during every
iteration of a FOR ... NEXT loop, and wait for the user to click a command
button for the next iteration. I need to let the user step through the
looping at his/her own pace.

Any help would be greatly appreciated.

h.

Jul 17 '05 #6
HP
Thanks Guys ... Much appreciated ... You have given me a few good options, I
will have a think about which one suits me best!

Cheers,

hp.

"HP" <no****@nospam.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
Hi,

Does anyone know if it is possible to force the code to pause during every
iteration of a FOR ... NEXT loop, and wait for the user to click a command
button for the next iteration. I need to let the user step through the
looping at his/her own pace.

Any help would be greatly appreciated.

h.

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dr. Know | last post by:
I am working on an ASP page that writes to several databases, ranging from MDBs to x-base. One of the tasks involves using an existing highest value from the DB and incrementing it before...
15
by: jcrouse | last post by:
Here is my code: Dim sw As StreamWriter = File.CreateText(Application.StartupPath & "\mameversion.bat") sw.WriteLine(lblMameExePath.Text & " -help >""" & Application.StartupPath &...
1
by: jcrouse | last post by:
This is sort of a revisited item from about two months ago (don't get mad Cor) with additional code. I am creating a batch file called CreateMameGames.bat. I am then running that batch file to...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
2
by: BLUE | last post by:
I would like to pause an application while the GUI display a Label saying "Logging in...". System.Timers System.Windows.Forms.Timer System.Threading.Timer System.Threading ==Thread.Sleep ...
0
by: Grayzag | last post by:
Hi there, As part of my Software course, i have to create a game. Since I originally started out with python, I was used to it being really easy to create a main loop to control the game with a...
12
by: greg | last post by:
Hi, Can anyone help me with the following issue: How can I pause the execution of a program until a given file is created (by another process) in a specified directory? Any ideas would be...
3
by: Lucress Carol | last post by:
Hi everyone, I'm having troubles with pausing and continuing MFC Thread.For test purposes I've created in my MFC Dialog application a progress Bar Control, a Start Button and a Stop Button.The...
0
by: thesti | last post by:
hello, i have some jbuttons in my frame. and i have a recursive method, which will check a certain condition and if satisfied, will move one of the jbuttons location to somewhere else in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.