Adding a PAUSE button

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Adding a PAUSE button

Post by aboredprogrammer » Mon Feb 08, 2010 6:22 am

Hello,

I have been trying to add a "pause" button feature to my dialog. For example, if the user clicks "start" the script will run, and if they want to pause the script they click pause, and when they want it to continue, they click start. I have tried this below, but I could be going in the completely wrong direction:

Label>pause
GetDialogAction>dialog1,r
Goto>Loop

Am I heading the right direction?
aboredprogrammer

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 08, 2010 4:20 pm

First - Are you aware that there is a built in "pause" featurefor Macro Scheduler? If a user presses the "Pause" key while Macro Scheduler scripts are running, all running scripts will pause until the user presses the "Pause" key a second time. There is no confirmation that scripts have paused or restarted so this might not work for you.

It appears you want to use a "Pause" button on a dialog, your script needs to go into an idle condition when the pause button is pressed. This could be accomplished by opening a modal message or dialog or by going to a loop that is broken when a button is pressed.

From what you posted, It looks to me like you've decided to use a modal dialog. One way this could be accomplished would be to have the pause button jump to a label or subroutine where you would reopen your dialog modally. opening a modal dialog stops script processing until someone presses a button on the dialog. Here's a simple example where pressing "Pause" then "Start" will start and stop your script.

Code: Select all

VBSTART
VBEND
VBEval

Dialog>Dialog1
   Caption=Pause Sample
   Width=256
   Height=166
   Top=CENTER
   Left=CENTER
   Label=msLabel1,96,24
   Button=Pause,84,88,75,25,3
EndDialog>Dialog1

//Display dialog1 non-modally
Show>Dialog1

Label>Loop
  GetDialogAction>dialog1,res1
  If>res1=2
    Exit>0
  EndIF
  If>res1=3
    Goto>Process
  EndIf
  Wait>0.01
  //display a timer for example
  VBEval>Timer,dialog1.mslabel1
Goto>Loop

Label>Process
//Change the button text
Let>Dialog1.msButton1=Start
ResetDialogAction>Dialog1
//Close the non-modal dialog
CloseDialog>Dialog1
//Display dialog1 modally
Show>Dialog1,res1
//modal dialogs close themselves when a button is pressed
  If>res1=2
    Exit>0
  EndIF
//Display dialog1 non-modally
Show>Dialog1
//Change the button text
Let>Dialog1.msButton1=Pause
ResetDialogAction>Dialog1
//Go back to the timer loop
Goto>Loop

User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Post by aboredprogrammer » Thu Feb 11, 2010 6:39 am

Hey,

Sorry for the late response JRL. I have been very busy with work lately. I haven't got around to testing the Pause button yet with the code you supplied, but I will very soon. I will let you know how it goes!

Thanks!
aboredprogrammer

User avatar
aboredprogrammer
Junior Coder
Posts: 40
Joined: Wed Jan 27, 2010 6:31 am

Post by aboredprogrammer » Thu Feb 11, 2010 9:00 pm

JRL,

I tried your code and couldn't get it working the way I had intended. However, I was messing around with stuff for about a half hour, and constructed a small code that works perfectly!

Code: Select all

Label>pause
If>dialog1.msEdit1=   Press start when ready...
Let>dialog1.msEdit1=               Paused...
RDA>dialog1
Endif
GDA>dialog1,res1
If>res1=30,about
If>res1=10,check_settings
Goto>dialogoptions
Thanks for your help!
aboredprogrammer

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts