Dialog with timeout if no button pressed

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Dialog with timeout if no button pressed

Post by obfusc88 » Wed Mar 14, 2007 8:44 pm

I am trying to make a Dialog that will pop up and wait for OK button to be pressed. If not pressed in x seconds, then it will go away by itself. This will be put into StartUp folder, so must go away and not hang up waiting if unattended.

I am using %Delay% fot the wait period.

The following seems to run OK except when i press OK and it uses ONEVENT. It sends an error message that it cannot find the label "Continue". I added a line to GoTo>Continue in the middle to check the label was spelled correctly and that works good.

Code: Select all

//Use Dialog Box

Let>Delay=5
Dialog>Dialog1
   Caption=Friendly Reminder
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=250
   Top=134
   Left=42
   Label=     Just a note to remind you about company policies regarding computer usage.%CRLF%%CRLF%     Thank you.  Have Fun!
   Button=OK,50,142,30,20,3
   Default=OK
EndDialog>Dialog1

Show>Dialog1
GetTime>Start

//Goto>Continue         This line is to test label can be found

Label>loop1
OnEvent>DIALOG_EVENT,Dialog1,3,Continue

GetTime>Finish

VBSTART
VBEND
VBEval>DateDiff("s","%Start%","%Finish%"),Pause

If>%Pause%<%Delay%,loop1

Label>Continue
CloseDialog>Dialog1
this is the first time I have tried something like that and used examples for the forum and from the help sections. maybe there is a better way to make this happen? thank you for your help

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

Post by JRL » Wed Mar 14, 2007 8:59 pm

This should make your script work:

Code: Select all

/Use Dialog Box

Let>Delay=5
Dialog>Dialog1
   Caption=Friendly Reminder
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=250
   Top=134
   Left=42
   Label=     Just a note to remind you about company policies regarding computer usage.%CRLF%%CRLF%     Thank you.  Have Fun!,5,5
   Button=OK,50,142,30,20,3
   Default=OK
EndDialog>Dialog1

Show>Dialog1
GetTime>Start

//Goto>Continue         This line is to test label can be found

OnEvent>DIALOG_EVENT,Dialog1,3,Continue
Let>Complete=0
Label>loop1
If>Complete=1,Finished
GetTime>Finish

VBSTART
VBEND
VBEval>DateDiff("s","%Start%","%Finish%"),Pause

If>%Pause%<%Delay%,loop1

SRT>Continue
Let>Complete=1
END>Continue

Label>Finished
CloseDialog>Dialog1
This would do the same thing and be easier:

Code: Select all

/Use Dialog Box

Let>Delay=5
Dialog>Dialog1
   Caption=Friendly Reminder
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=250
   Top=134
   Left=42
   Label=     Just a note to remind you about company policies regarding computer usage.%CRLF%%CRLF%     Thank you.  Have Fun!,5,5
   Button=OK,50,142,30,20,3
   Default=OK
EndDialog>Dialog1

Show>Dialog1
Wait>%Delay%
CloseDialog>Dialog1

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Wed Mar 14, 2007 9:11 pm

thank you for answer so fast from JRL

I haven't tried the first example yet, but the second one does not work. I had that in a first draft doing this. That one stays open for the full Delay period. I want to be able to click OK to make go away before full delay. Message may be longer, may be 30+ seconds. If you change Delay you will see what I mean, clicking on OK does not close Dialog.

I will now try the first sample you provided. thank you

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Wed Mar 14, 2007 9:22 pm

i just tried example number 1 and that one did work. thank you for your help. now i need to go understand how you did that.

Two more questions:
1. do you think i can add a "second" count down till disappears? Eg: "Will disappear in 30 seconds .....,(29,28,27......etc.)
2. can i make OK button invisible until first five seconds gone by to prevent closing in less than 5 seconds? EG: only visible from 6-30 seconds of 30 second delay.

i don't mean to be greedy, am willing to work for results. thank you again to JRL for making this work now.

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

Post by JRL » Wed Mar 14, 2007 9:24 pm

Oops too big of a hurry. Try this instead:

Code: Select all

/Use Dialog Box

Let>Delay=5
Let>k=0

Dialog>Dialog1
   Caption=Friendly Reminder
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=250
   Top=134
   Left=42
   Label=     Just a note to remind you about company policies regarding computer usage.%CRLF%%CRLF%     Thank you.  Have Fun!,5,5
   Button=OK,50,142,30,20,3
   Default=OK
EndDialog>Dialog1

Show>Dialog1

Label>Loop1
GetDialogAction>dialog1,r1
If>r1=3,Finished
Wait>1
add>k,1
If>k=%Delay%,Finished
Goto>Loop1
Label>Finished
CloseDialog>Dialog1

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

Post by JRL » Wed Mar 14, 2007 9:28 pm

1. do you think i can add a "second" count down till disappears? Eg: "Will disappear in 30 seconds .....,(29,28,27......etc.)
Yes, search for examples of changing the label in a dialog.
2. can i make OK button invisible until first five seconds gone by to prevent closing in less than 5 seconds? EG: only visible from 6-30 seconds of 30 second delay.
Invisible... how about Greyed out. Search for "greyed out"

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Wed Mar 14, 2007 9:38 pm

OK, now i understand what i did wrong. the last parameter of OnEvent must be a SubRoutine, just as stated in the Help. i used a label there. somewhere I thought it said label OR subroutine. your script changed Continue to a subroutine instead of a label. That is good because now i can see that i could string a list of OnEvents together, and whichever one happened first would run the subroutine and bring me back to same section of the script. i think i understand and thanks for the lesson.

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

Post by JRL » Wed Mar 14, 2007 9:43 pm

Also take the OnEvent(s) out of the loop. Execute them once... not over and over again.

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Wed Mar 14, 2007 10:27 pm

thank you again JRL. i just came back to ask some questions about the first sample you provided. when i single stepped it was doing some funny things, the ONEVENT kept firing. now i see that you pointed out removal from the loop-that makes sense, shame on me. now i see your most recent example, #3, and tried that out. that one appears to be working perfectly when i single step and when i run real time. and the log makes sense.

so now it is on to countdown and greyed out OK box. i will bring back final results so i can make a contribution in payment for yours. hope i don't need to bother you again, thank you for the hints.

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Thu Mar 15, 2007 12:20 am

making progress (pun) by using progressbar. but with progress bar enabled the clicking on OK does not close down any more. Help does indicate that labels can be changed. i tried using %k% in the label for "countdown seconds" but it did not appear to change so i decided to try a progress bar instead. here is the current script with the progress bar:

Code: Select all

Let>MyCaption=   Friendly Reminder
Let>MyLabel=Just a note to remind you about company policies regarding computer usage.%CRLF%Thanks for helping, have a good day.

//Use Dialog Box

Let>Delay=10
Let>k=0

Dialog>Dialog1
   Caption=%MyCaption%
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=250
   Top=134
   Left=42
   Label=%MyLabel% %CRLF%%CRLF%   Thank you.  Have Fun!%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%   Reminder will disappear in a few seconds.,5,5
   Button=OK,20,160,30,20,3
   ProgressBar=Countdown,220,180,200,20,0
   Default=OK
EndDialog>Dialog1

Show>Dialog1

Label>Loop1
GetDialogAction>dialog1,r1
If>r1=3,Finished

Wait>.5
Add>k,.5

If>k=%Delay%,Finished

// New stuff for Progress Bar -------------
Let>Pct={%k%/%Delay%*100}
Let>Dialog1.Countdown=%Pct%
ResetDialogAction>Dialog1
//  --------------------------------------------

Goto>Loop1

Label>Finished
CloseDialog>Dialog1
So, how to have progress bar AND be able to click on buttons? And after this is done i will be wanting to add a button to freeze dialog until OK is cllcked, overriding the delay to allow more time to read. also looking at importing a server based document for MyLabel. this will become part of login script allowing new messages to come up at login but only need to be maintained in a single server based document.

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Thu Mar 15, 2007 1:18 am

While waiting for some feedback, i continued and added a Pause button and fixed the labels to include a countdown of remaining seconds. but the Progress Bar will not work along with the buttons. so i have commented out the progress bar for now. the current script is here:

Code: Select all

Let>MyCaption=   Friendly Reminder

Let>MyLabel=   Just a note to remind you about company policies regarding computer usage.%CRLF%%CRLF%    Details are in J:\Data\Word\Common\ComputerUsage.doc.%CRLF%%CRLF%   Seconds remaining = %Remaining%.

Let>Delay=10
Let>k=0

Dialog>Dialog1
   Caption=%MyCaption%
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=300
   Top=134
   Left=42
   Label=%MyLabel% %CRLF%%CRLF%   Thank you.  Have Fun!%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%   Reminder will disappear in a few seconds.,5,5
   Button=Close,20,160,70,20,3
   Button=Pause,100,160,70,20,4
   ProgressBar=Countdown,220,180,200,20,0
   Default=Close
EndDialog>Dialog1

Show>Dialog1

Label>Loop1
GetDialogAction>dialog1,Action
If>%Action%=4,Freeze
If>%Action%=3,Finished

// Using .5 vs. 1 for smoother Progress Bar
Wait>.5
Add>k,.5

If>%k%=%Delay%,Finished
Let>Remaining=%Delay%-%k%
Let>Pct={%k%/%Delay%*100}
Let>Dialog1.Countdown=%Pct%
//ResetDialogAction>Dialog1       //Progress Bar stops button responses
Goto>Loop1

Label>Freeze
GetDialogAction>dialog1,Action
If>%Action%=3,Finished
Goto>Freeze

Label>Finished
CloseDialog>Dialog1
Goto>End

Label>End
I changed OK to Close, and added Pause button. also added a line showing remaining seconds. will probably forget about progress bar, used it because i could not figure out remaining seconds update. so don't really need it any longer, but would like to know if it could still be done, and how. thank you for help, still have more to do.

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

Post by JRL » Thu Mar 15, 2007 1:50 pm

You seem to be learning quickly and you're doing a good job of working for yourself and asking for assistance, rather than asking for someone to write the script for you. That said, here's a rewrite of the last script you posted. Only a couple of changes but in my mind they're important to get you set off in the right direction.

Added Freeze and Thaw subroutines that set a flag (variable named Frozen) that can be tested in the main loop. This allows the program to continue running. As you had it the program would halt and the only available option was to close. For this script that might be fine but for future reference and to make this dialog more interesting use flags.

The problem you had with the progress bar causing the the buttons to fail was the location of the ResetDialogAction in relation to the Wait>.5. As you had them positioned the dialog would wait for a half of a second (during which time you were clicking a button) and at the end of the half second the dialog was reset. Resetting the dialog made the Action variable equal to zero. You had a millisecond long window of opportunity to pick a button and have the action of the button execute followed by a half second window of opportunity for the button selection to be reset to zero before any action could take place. The odds were against you. I simply moved the wait>.5 to occur after the ResetDialogAction so the the odds were back in your favor.

Notice how the button names change and why. Also notice that the button and label references are numbered (dialog1.msbutton1, dialog1.msbutton2) and that the order of the numbering corresponds to the position of the button or label in the dialog definition. This is important to know because if you change or rearrange the dialog you might also need to change the names of the references to the button or label objects. Also note that a ResetDialogAction is required for the object rename to show up in the dialog.

Try this:

Code: Select all

Let>MyCaption=   Friendly Reminder

Let>MyLabel=   Just a note to remind you about company policies regarding computer usage.%CRLF%%CRLF%    Details are in J:\Data\Word\Common\ComputerUsage.doc.%CRLF%%CRLF%   Seconds remaining = %Remaining%.

Let>Delay=10
Let>k=0
Let>Frozen=0

Dialog>Dialog1
   Caption=%MyCaption%
   Max=0
   Min=0
   Close=0
   Resize=0
   Width=445
   Height=300
   Top=134
   Left=42
   Label=%MyLabel% %CRLF%%CRLF%   Thank you.  Have Fun!%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%%CRLF%   Reminder will disappear in a few seconds.,5,5
   Button= ,20,160,70,20,3
   Button=Pause,100,160,70,20,4
   ProgressBar=Countdown,220,180,200,20,0
   Default=Close
EndDialog>Dialog1

Show>Dialog1

Label>Loop1
GetDialogAction>dialog1,Action
If>Frozen=0
  If>%Action%=4,Freeze
EndIf
If>Frozen=1
  If>%Action%=4,Thaw
EndIf
If>%k%>4
  If>%Action%=3,Finished
  Let>Dialog1.msbutton1=Close
EndIf

If>Frozen=0
// Using .5 vs. 1 for smoother Progress Bar
  Add>k,.5
  If>%k%=%Delay%,Finished
  Let>Remaining=%Delay%-%k%
  Let>Pct={%k%/%Delay%*100}
  Let>Dialog1.Countdown=%Pct%
  ResetDialogAction>Dialog1
EndIf
Wait>.5
Goto>Loop1

SRT>Freeze
  Let>Frozen=1
  Let>Dialog1.msbutton2=Continue
  Let>Action=0
  ResetDialogAction>dialog1
END>Freeze
SRT>Thaw
  Let>Frozen=0
  Let>Dialog1.msbutton2=Pause
  Let>Action=0
  ResetDialogAction>dialog1
END>Thaw

Label>Finished
CloseDialog>Dialog1
Goto>End

Label>End

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Thu Mar 15, 2007 3:07 pm

thank you again to JRL. i thought i was all done and going to live with what i had but now you have given me homework to do. i am grateful to you for that. i have not tested your script yet but i understand your explanation about placement of WAIT command. i am not sure about the names and numbers and renaming, but will read your comments as i go through the lines. It sounds like you fixed the progress bar by moving WAIT and are suggesting "generic" good practices re the field names, etc.

Looking ahead to the next step of replacing MyLabel with the contents of a server based text file, i have a few questions ... should they become separate threads? YES.... i will do that and i will let you know how your changes above worked out for me.

obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Thu Mar 15, 2007 10:44 pm

the script that you provided works terrific. now i only need to move the buttons and progress bar and other visual alignment things. the progressbar works, the Close button is only there after 5 seconds, and the Pause is a real pause vs. mine that actually halted. this one pauses and continues with a different label on the same button. so different from my basic beginning.

i did start another thread for resizing Dialog window. thank you again to JRL for the excellent results.

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