WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

AskYesNo with TimeOut

Keywords: 	   AskYesNo

Question:

I just started to play with WinBatch to replace a DOS batch system and I need to replace the CHOICE command. CHOICE asks a question (I am asking Yes or No) and waits for a key stroke. If nothing happens after a specified number of seconds it reverts to a default.

I have not come accross a replacement. Display() will not work because I can not determine if a key was pressed. AskYesNo() will not work because there is no timeout. Any ideas?

Answer:

Basically the following script does the job.

WinBatch does not have a built-inb TimeOut feature on any of the user input functions, so you have to craft your own.

; Written by Todd Thorson Comdisco Distributed Services
WHITE="255,255,255"
RED="255,0,0"
PURPLE="255,0,255"
CYAN="0,255,255"
DKBLUE="0,0,128"
BLUE="0,0,255"
LTGRAY="192,192,192"
GRAY="128,128,128"
GREEN="0,255,0"
YELLOW="255,255,0"
FAMILY=16
FONT="Bookman Old Style"
DKGRAY="64,64,64"
BLACK="0,0,0"
WASH=1
:Main
Wash=1
BoxesUp("0,0,1000,1000",@NORMAL)
BoxColor(1,"0,0,127",WASH)
BoxCaption(1,"Put a Caption Here")
BoxDrawRect(1,"0,0,1000,1000",1)
BoxTextFont(1,"%font%",150,80,0|0)
BoxTextColor(1,"255,255,0")
BoxTextFont(1,"%font%",35,50,0|0)
BoxDrawText(1,"200,300,800,350","Make a Choice here",@FALSE,1)
BoxDrawText(1,"200,850,800,900","You must answer within 10 seconds",@FALSE,1)
BoxButtonDraw(1,1, "&Yes", "300,700,500,750") 
BoxButtonDraw(1,2, "&No", "600,700,800,750") 
iBox=0
Timer=0
while iBox == 0
If Timer == 40 then goto DoNothing
Delay(0.25)
Timer=Timer+1
for x=1 to 2
if BoxButtonStat(1,x) then iBox=x
next
end while
if iBox
BoxDataClear(1,"TOP")
switch iBox
case 1
goto DoYes
break
case 2
goto DoNo
break
EndSwitch
EndIf

:DoYes
Message("Test","You clicked the 'YES' Button")
goto END

:DoNo
Message("Test","You clicked the 'NO' Button")
goto END

:DoNothing
Message("Test","You didn't click anything!")
goto END

:END

Article ID:   W13129
Filename:   AskYesNo with TimeOut.txt
File Created: 1999:04:15:16:51:56
Last Updated: 1999:04:15:16:51:56