gregnottage Posted November 3, 2006 Share Posted November 3, 2006 Hi, I'm trying to write a script that displays a box with two buttons. Depending on which of the buttons is pressed, I want different actions to be taken. What I'm also trying to do is have a default action taken after a period of time (25 seconds) has elapsed. Here is what I have so far: ---------------------------------------------------------------- expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Koda\Forms\ITStart.kxf $Form1 = GUICreate("ITS Applications", 211, 203, 333, 219) $Button1 = GUICtrlCreateButton("&Weekly Restart", 8, 152, 81, 41, 0) $Button2 = GUICtrlCreateButton("&Daily Restart", 122, 152, 81, 41, 0) $Group1 = GUICtrlCreateGroup("Weekly or Daily?", 8, 8, 193, 129) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("Do you want to start the Weekly or Daily Applications? This will affect Infopath and whether it opens a previously worked on file or starts a new report. The script will timeout in 25 seconds and default to the Weekly Application startup. Thanks and have a nice day;-)", 16, 24, 176, 108) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $msg = "" While 1 $szName = GUIGetMsg() Switch @error Case 2 $msg = "Timeout " ContinueCase Case 1; Continuing previous case $msg &= "Cancellation" Case 0 Switch $szName Case $GUI_EVENT_CLOSE Exit Case $Button1 msgbox(0, "Weekly Restart", "Weekly Restart button was pressed") ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\ITS.exe") Exit Case $Button2 msgbox(0, "Daily Restart", "Daily Restart button was pressed") ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\DailyITS.exe") Exit Case Else $msg = "Others" EndSwitch Case Else $msg = "Something went horribly wrong." EndSwitch WEnd Msgbox(0, "Timeout Reached", "Timeout Reached") ; run("C:\Program Files\AutoIt3\Scripts\ITSupport\Daily_ITS.exe") ---------------------------------------------------------------- It displays the box fine and all the buttons work, but I can't get my head around the timeout and then the default action. Please can you help me work this out. Many Thanks, Greg. Link to comment Share on other sites More sharing options...
cppman Posted November 3, 2006 Share Posted November 3, 2006 expandcollapse popupAdLibEnable("_Timeout", 25000) #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Koda\Forms\ITStart.kxf $Form1 = GUICreate("ITS Applications", 211, 203, 333, 219) $Button1 = GUICtrlCreateButton("&Weekly Restart", 8, 152, 81, 41, 0) $Button2 = GUICtrlCreateButton("&Daily Restart", 122, 152, 81, 41, 0) $Group1 = GUICtrlCreateGroup("Weekly or Daily?", 8, 8, 193, 129) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("Do you want to start the Weekly or Daily Applications? This will affect Infopath and whether it opens a previously worked on file or starts a new report. The script will timeout in 25 seconds and default to the Weekly Application startup. Thanks and have a nice day;-)", 16, 24, 176, 108) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $msg = "" While 1 $szName = GUIGetMsg() Switch @error Case 2 $msg = "Timeout " ContinueCase Case 1; Continuing previous case $msg &= "Cancellation" Case 0 Switch $szName Case $GUI_EVENT_CLOSE Exit Case $Button1 msgbox(0, "Weekly Restart", "Weekly Restart button was pressed") ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\ITS.exe") Exit Case $Button2 msgbox(0, "Daily Restart", "Daily Restart button was pressed") ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\DailyITS.exe") Exit Case Else $msg = "Others" EndSwitch Case Else $msg = "Something went horribly wrong." EndSwitch WEnd Msgbox(0, "Timeout Reached", "Timeout Reached") ; run("C:\Program Files\AutoIt3\Scripts\ITSupport\Daily_ITS.exe") Func _Timeout() ;Put your main timeout function here MsgBox(0, "", "") AdLibDisable() EndFunc Miva OS Project Link to comment Share on other sites More sharing options...
Valuater Posted November 3, 2006 Share Posted November 3, 2006 (edited) here is your script with a time-out expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Koda\Forms\ITStart.kxf $Form1 = GUICreate("ITS Applications", 211, 203, 333, 219) $Button1 = GUICtrlCreateButton("&Weekly Restart", 8, 152, 81, 41, 0) $Button2 = GUICtrlCreateButton("&Daily Restart", 122, 152, 81, 41, 0) $Group1 = GUICtrlCreateGroup("Weekly or Daily?", 8, 8, 193, 129) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("Do you want to start the Weekly or Daily Applications? This will affect Infopath and whether it opens a previously worked on file or starts a new report. The script will timeout in 25 seconds and default to the Weekly Application startup. Thanks and have a nice day;-)", 16, 24, 176, 108) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $msg = "" $begin = TimerInit() While 1 $dif = Round(TimerDiff($begin) / 1000) If $dif >= 25 Then MsgBox(0,0,"timed out ") $begin = TimerInit() ; do other stuff EndIf $szName = GUIGetMsg() Switch @error Case 2 $msg = "Timeout " ContinueCase Case 1; Continuing previous case $msg &= "Cancellation" Case 0 Switch $szName Case $GUI_EVENT_CLOSE Exit Case $Button1 msgbox(0, "Weekly Restart", "Weekly Restart button was pressed") ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\ITS.exe") Exit Case $Button2 msgbox(0, "Daily Restart", "Daily Restart button was pressed") ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\DailyITS.exe") Exit Case Else $msg = "Others" EndSwitch Case Else $msg = "Something went horribly wrong." EndSwitch WEnd Msgbox(0, "Timeout Reached", "Timeout Reached") ; run("C:\Program Files\AutoIt3\Scripts\ITSupport\Daily_ITS.exe") 8) EDIT:... now you have two approaches Edited November 3, 2006 by Valuater Link to comment Share on other sites More sharing options...
flyingboz Posted November 3, 2006 Share Posted November 3, 2006 One approach would be to utilize a global variable w/ the amount of time elapsed since your timer set, and testing that value in each message loop rather than attempting to implement as a gui message. #include <GUIConstants.au3> ; == GUI generated with Koda == $DelAForm1 = GUICreate("DelAForm1", 622, 444, 192, 125) $Button1 = GUICtrlCreateButton("AButton1", 152, 64, 113, 49, 0) GUISetState(@SW_SHOW,$DelAForm1) $time_elapsed = TimerStart() $timeout_seconds = 3 While 1 If TimerDiff($time_elapsed) > $timeout_seconds * 1000 then Exit -$timeout_seconds $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
Valuater Posted November 3, 2006 Share Posted November 3, 2006 with ... TimerStart() did you mean... TimerInit() 8) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now