Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: autoanswer auto answer 2nd wbt second winbatch
First see the command aMsgTimeout in the Shell operations Extender. This function can do just that...
In this example, if the user does not respond by the preset time, then the default answer is taken.
This code will automatically press a dialog button in WinBatch after a 10 second time out. It is good for demonstration programs, or to continue a process when WinBatch is unattended.
Basically the trick is to launch a second batch file that will press the button after 10 seconds, if nobody presses it manually. With a little bit of clever code, we do not actually need a second WBT file, but rather run the first WBT file again with special parameters so that it executes different code. This keeps the total number of files to worry about smaller.
This code is designed for use with WinBatch, but it would only take minor modifications to make it a compiled EXE file (see the commented out line):
; File name DEMO1.WBT ; This top part here is the button pushing code If Param0>=3 ;If we have three or more parameters If strupper(Param1)=="PRESSBUTTON" ;and param1 is PRESSBUTTON TimeDelay(10) ; wait ten seconds if strupper(Param2)=="CHILD" ; Now if param2 is child if !WinExistChild(param3,param4) then exit ; See if child is around SendKeysChild(param3,param4,"~") ;Yes, send an ENTER else ;Parent if !WinExist(param3) then return ; Is parent around SendKeysTo(param3,"~") ; Send an ENTER endif exit endif Message("Ooops","Bad Parameters") ;Something went wrong exit endifThe following is the real code to execute Right before the AskLine statement that we wish to automatically press the OK button after 10 seconds, whe launch this script again with special parameters.
;PARAMETERS: ;PRESSBUTTON to activate the code above ;PARENT to tell the code above that the AskLine Window is a PARENT-style window ; "Hello There" the title of the Window is question Run(WinExeName(""),`demo1.wbt PRESSBUTTON PARENT "Hello There"`) ; Or for a compiled version ; Run(WinExeName("",`PRESSBUTTON PARENT "Hello There"`) ;Now we do our askline.... A=AskLine("Hello There","Enter your name","John Doe") if A=="John Doe" then display(5,"Default Anser taken",A) else display(5,"New Answer Provided",A)The first time the script runs there are no parameters and it should go about its normal work.
When it get ready to putup an auto-answer message box it wants to run a different process to do it. So you could have a completely different script do it. But then you have to lug two seperate scripts around for one task.
Or in a smarter script, you can have the original script detect when it is supposed to do something else - via passed parameters - and do something completely different - like push buttons - and then only have one WBT file which is more versatile to lug around.
To figure this all out, add DEBUG(1) at the top of the script and watch it like a hawk.
The first example deals with the "Box-" commands and allows to press several buttons within a time that is given by MaxWait.
The second runs and controls the other program, TimedDialog2.wbt", which has to be in the same directory and works with the "Dialog - " commands. Within a time given by MaxWait2 the user can enter a line.
To put more stress on your users, you can use counters with both boxes (or dialogs or whatever you may call them). :-)
;************************************** TestDialog.wbt ************************************* ; ; This gives two examples of timed input-boxes. The first one deals with the "Box-" commands ; and allows to press several buttons within a time that is given by MaxWait. ; The second runs another program, "TestDialog2.wbt", which has to be in the same directory ; and works with the "Dialog - " commands. Within a time given by MaxWait2 the user can enter a ; line. To put more stress on your users, you can use counters with both boxes ; (or dialogs or whatever you may call them). :-) ; Best wishes from Germany, Hannes Frischat, frischat@dynamic.fkp.uni-hannover.de ; ; P.S.: Be sure that TestDialog2.wbt is in place ... ; ;******************************************************************************************* Decided = @FALSE MaxWait = 10 BoxKoo = "200,200,700,700" TextKoo = "100,100,900,400" ButtonKoo1 = "100,600,300,900" ButtonKoo2 = "400,600,600,900" ButtonKoo3 = "700,600,900,900" BoxesUp(BoxKoo,@Normal) ;this opens the first box BoxCaption(1,"TimedDialog 1") BoxButtonDraw(1,1,"Choice 1",ButtonKoo1) BoxButtonDraw(1,2,"Choice 2",ButtonKoo2) BoxButtonDraw(1,3,"Choice 3",ButtonKoo3) BoxDataTag(1,"tag1") IntControl(54,"TimedDialog 1",1,0,0) For n = 1 to MaxWait ;counter Gosub message1 TimeDelay(1) IF Decided == @TRUE then break Next BoxDestroy(1) IF Decided == @FALSE Answer = "You did not choose anything" ELSE Answer = 'You choose "%Choice%".' ENDIF Display(3,"Answer",Answer) ;SecondDialog Entered = @FALSE Nobody = @FALSE MaxWait2 = 15 run("TimedDialog2.wbt","") ;starts the input-menu BoxesUp("400,300,600,500",@normal) ;this is the counter BoxCaption(1,"Login") BoxDataTag(1,"tag2") BoxDrawText(1,"0,0,1000,1000","Enter your name - %MaxWait% seconds left",@TRUE,21) WinActivate("Login") For n = 1 to MaxWait2 ;this loop counts m = MaxWait2 - n + 1 BoxDataClear(1,"tag2") BoxDrawText(1, "0,0,1000,1000","Enter your name - %m% seconds left.",@TRUE,21) WinActivate("TimedDialog2") TimeDelay(1) IF !WinExist("TimedDialog2") THEN Goto Entered NEXT While WinExist("TimedDialog2") ;if no button was pressed SendKeysTo("TimedDialog2","{ESCAPE}") ;IntControl(47,"TimedDialog2",0,0,0) ;should close the window but doesnīt work here Nobody = @TRUE TimeDelay(1) ENDWHILE TimeDelay(1) IF Nobody == @TRUE BoxDestroy(1) Display(3,"Nobody there?","You didnīt enter your name") ENDIF EXIT :Entered ;If button was pressed BoxDestroy(1) TimeDelay(1) Name = IniReadPvt("LOGIN","NAME","","TimedDialog.ini") IniWritePvt("LOGIN","NAME","","TimedDialog.ini") ;to delete the input If Name != "" then Message("Login",'Your name is "%Name%"') EXIT :message1 IF BoxButtonStat(1,1) PressedButton = 1 Gosub Decision ENDIF IF BoxButtonStat(1,2) PressedButton = 2 Gosub Decision ENDIF IF BoxButtonStat(1,3) PressedButton = 3 Gosub Decision ENDIF BoxDataClear(1,"tag1") m = MaxWait - n + 1 BoxDrawText(1,"0,0,1000,1000","Make up your mind! You got %m% seconds left.",@TRUE,21) drop(m) RETURN :Decision Decided = @TRUE Switch PressedButton Case 1 Choice = "Choice 1" break Case 2 Choice = "Choice 2" break Case 3 Choice = "Choice 3" break ENDSWITCH RETURN
;********************************** TimedDialog2.wbt ************************************* ; ; This belongs to TimedDialog.wbt and should be in the same directory. ; HF ; TimedDialog2Format=`WWWDLGED,5.0` TimedDialog2Caption=`TimedDialog2` TimedDialog2X=100 TimedDialog2Y=170 TimedDialog2Width=235 TimedDialog2Height=80 TimedDialog2NumControls=3 TimedDialog201=`82,6,144,DEFAULT,VARYTEXT,RememberText,"Please insert your name."` ;This can be StaticText as well TimedDialog202=`82,36,66,DEFAULT,EDITBOX,EditText,"Guest"` TimedDialog203=`82,60,66,DEFAULT,PUSHBUTTON,DEFAULT,"OK",1` ButtonPushed=Dialog("TimedDialog2") IniWritePvt("LOGIN","NAME",EditText,"TimedDialog.ini") RETURN
Article ID: W13131
Filename: Automatically Answer a Dialog Box.txt
File Created: 2001:01:23:10:55:12
Last Updated: 2001:01:23:10:55:12