Simple Dialog Box Problem that I can't figure out

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ukdboyd
Newbie
Posts: 11
Joined: Wed May 25, 2005 6:09 pm

Simple Dialog Box Problem that I can't figure out

Post by ukdboyd » Fri Aug 14, 2009 2:42 pm

I'me trying to write a simple script that will show a dialog box with a progress bar and a cancel button. The purpose is to reboot the computer, or cancel the reboot. For testing purposes, ive not put the reboot line in yet.

Here's what I have:

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=400
   Height=168
   Top=300
   Left=276
   Label=SAVE YOUR WORK!! REBOOTING COMPUTER IN 15 SECONDS,46,24
   Button=CANCEL REBOOT,144,88,113,25,2
   ProgressBar=ProgressBar,80,56,233,18,0
EndDialog>Dialog1

Show>Dialog1
GetDialogAction>dialog1,r

Let>k=1
Repeat>k
  Let>Dialog1.progressbar=k
  ResetDialogAction>Dialog1
  Wait>.15
  Let>k=k+1
Until>k,100

Label>END
Exit
The script works, but I can't figure out where or how to put the line in that cancels the script when the button is pressed.

Thanks to anyone who can help me with this.

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

Post by JRL » Fri Aug 14, 2009 3:40 pm

TRy moving the GetDialogAction line down into the repeat loop and if variable "r" becomes "2" then Exit>0

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=400
   Height=168
   Top=300
   Left=276
   Label=SAVE YOUR WORK!! REBOOTING COMPUTER IN 15 SECONDS,46,24
   Button=CANCEL REBOOT,144,88,113,25,2
   ProgressBar=ProgressBar,80,56,233,18,0
EndDialog>Dialog1

Show>Dialog1
GetDialogAction>dialog1,r

Let>k=1
Repeat>k
  GetDialogAction>dialog1,r
  If>r=2
    Exit>0
  EndIf
  Let>Dialog1.progressbar=k
  ResetDialogAction>Dialog1
  Wait>.15
  Let>k=k+1
Until>k,100

Label>END
Exit

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Another option

Post by gdyvig » Fri Aug 14, 2009 3:45 pm

Here is another way to do the same thing:

Add this to the top of your sript:

Code: Select all

OnEvent>DIALOG_EVENT,Dialog1,2,CancelReboot
SRT>CancelReboot
  MDL>Cancelling reboot
  exit>0
END>CancelReboot

Posting this partly so I will remember how to do it myself.
See Fran's recent post for more examples.


Gale

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

Post by JRL » Fri Aug 14, 2009 3:51 pm

Excellent solution Gale! Much better than my suggestion. What I suggested could fail if the user picked the "Cancel" button during that one thousandth of a second between GetDialogAction and ResetDialogAction... not likely but possible. the Onevent method will never fail.

ukdboyd
Newbie
Posts: 11
Joined: Wed May 25, 2005 6:09 pm

Post by ukdboyd » Fri Aug 14, 2009 3:54 pm

Thanks! That's what was look for!

ukdboyd
Newbie
Posts: 11
Joined: Wed May 25, 2005 6:09 pm

Post by ukdboyd » Fri Aug 14, 2009 4:47 pm

Quick followup question...

Script is working fine...i've compiled it into an EXE for distribution.

When I run the executable on my computer for testing it works perfectly. However, when I run it on another computer, it runs, but the progress bar moves much slower. The script still works, the button works, the computer reboots as desired. But, rather than taking 15 seconds to run, it takes about 45 seconds.

Any ideas? FWIW, the other computer is newer and faster than the one I'm using for development, so I wouldn't think it would be a CPU problem.

Thanks again.

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

Post by JRL » Fri Aug 14, 2009 5:05 pm

Try using VBScript "timer" function.

Code: Select all

OnEvent>DIALOG_EVENT,Dialog1,2,CancelReboot
SRT>CancelReboot
  exit>0
END>CancelReboot

VBSTART
VBEND

Dialog>Dialog1
   Caption=Dialog1
   Width=400
   Height=168
   Top=300
   Left=276
   Label=SAVE YOUR WORK!! REBOOTING COMPUTER IN 15 SECONDS,46,24
   Button=CANCEL REBOOT,144,88,113,25,2
   ProgressBar=ProgressBar,80,56,233,18,0
EndDialog>Dialog1

Show>Dialog1
GetDialogAction>dialog1,r
VBEval>Timer,StartTime
Label>Start
  VBEval>Timer-%StartTime%,Totaltime
  If>Totaltime>15,END
  Let>Dialog1.progressbar={round((%TotalTime%/15)*100)}
  Let>DisplayTime={15-(round(%TotalTime%))}
  Let>Dialog1.mslabel1=SAVE YOUR WORK!! REBOOTING COMPUTER IN %DisplayTime% SECONDS
  ResetDialogAction>Dialog1
  Wait>0.01
Goto>Start

Label>END
Exit

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