3mustgetbeers Posted June 24, 2010 Share Posted June 24, 2010 Hi Guys, I'm writing a script that will backup my dads palm. It will give a gui stating '15 seconds till palm desktop is closed. click ok to run now or cancel to abort' I have it more or less all (backup the database, compress, encrypt etc) but the buttons (ok, cancel & red X) won't work when the loop is in for the 15 second countdown - if i comment it out they work! Its probably pretty simple but I've been scratching my head for a couple of days and just don't get it. Any input is much appreciated - no matter how little if it sheds some light then thats great! Thanks Andy expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Palm Backup", 498, 271, 192, 124) $Warning = GUICtrlCreateLabel("Warning", 200, 16, 89, 28) GUICtrlSetFont(-1, 16, 800, 0, "ariel") $Text1 = GUICtrlCreateLabel("Palm is about to backup closing ALL open appointments", 48, 64, 394, 22) GUICtrlSetFont(-1, 12, 400, 0, "ariel") $Text2 = GUICtrlCreateLabel("To cancel this backup in order to save changes click 'Cancel' within", 16, 96, 465, 22) GUICtrlSetFont(-1, 12, 400, 0, "ariel") $CntDwn = GUICtrlCreateLabel("15", 232, 136, 26, 26) GUICtrlSetFont(-1, 14, 800, 0, "ariel") $Text3 = GUICtrlCreateLabel("seconds", 216, 176, 63, 22) GUICtrlSetFont(-1, 12, 400, 0, "ariel") $OK = GUICtrlCreateButton("Ok", 160, 224, 75, 25, $WS_GROUP) $Cancel = GUICtrlCreateButton("Cancel", 256, 224, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK GUIDelete($Form1) backup() Case $Cancel GUIDelete($Form1) Exit EndSwitch For $i =15 to 1 Step -1 GUICtrlSetData($CntDwn, $i) Sleep(1000) Next GUICtrlSetData($CntDwn, "0") Sleep(1000) ExitLoop WEnd Link to comment Share on other sites More sharing options...
Andreik Posted June 24, 2010 Share Posted June 24, 2010 It's simple. You need just to get messages, again, in there loop with GuiGetMsg() and if result is $Cancel or $GUI_EVENT_CLOSE do stuff... or you can use event mode [Check in help file GUISetOnEvent()]. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
3mustgetbeers Posted June 24, 2010 Author Share Posted June 24, 2010 Andreik, thanks for that. I've had a look at the help file have come up with this: For $i =15 to 1 Step -1 GUICtrlSetData($CntDwn, $i) Sleep(1000) Next If GUIGetMsg($Cancel) Then Exit ElseIf GUIGetMsg($OK) Then Backup() ElseIf GuiGetMsg($GUI_EVENT_CLOSE) Then Exit EndIf GUICtrlSetData($CntDwn, "0") Sleep(1000) ExitLoop This still doesn't work, but I don't get a syntax error either? I have mode the ifelse statements about in the for loop but to no effect? Cheers Andy Link to comment Share on other sites More sharing options...
Andreik Posted June 24, 2010 Share Posted June 24, 2010 (edited) Wrong syntax. Use in loop this style of switch. Switch GuiGetMsg() Case $Cancel [stuff] Case $GUI_EVENT_CLOSE [stuff] Case $Ok [stuff] EndSwitch Edited June 24, 2010 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
3mustgetbeers Posted June 24, 2010 Author Share Posted June 24, 2010 Andreik, cheers for your help mate, I now have While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK GUIDelete($Form1) backup() Case $Cancel GUIDelete($Form1) Exit Case $CntDwn For $i =100 to 1 Step -1 GUICtrlSetData($CntDwn, $i) Sleep(1000) Next GUICtrlSetData($CntDwn, "0") Sleep(1000) ExitLoop EndSwitch WEnd However the buttons work but now the countdown doesn't! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 25, 2010 Moderators Share Posted June 25, 2010 3mustgetbeers, You need 2 loops to make it work - look at this: While 1 ; Start the loop for the countdown For $i = 15 To 1 Step -1 ; Write countdown label GUICtrlSetData($CntDwn, $i) ; Get a timestamp $iBegin = TimerInit() ; Now run an idle loop for 1 sec checking for the buttons Do ; Check if a button is pressed Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cancel ; they do the same thing, so put them on the same line! Exit Case $OK GUIDelete($Form1) ;backup() ConsoleWrite("backup called" & @CRLF) Exit EndSwitch ; Check if we should exit the 1 sec idle loop Until TimerDiff($iBegin) > 1000 ; A second has passed so loop the countdown loop Next ; We are now out of the countdown loop GUICtrlSetData($CntDwn, "0") Sleep(1000) ExitLoop WEnd All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
3mustgetbeers Posted June 25, 2010 Author Share Posted June 25, 2010 Melba23 -> works perfect mate, wouldn't expect anything less from your good self! Thanks alot! Andreik thanks for pushing me in the right direction mate, you should enter me into the Guiness World Records - longest time taken for a penny to drop! Thanks again to both of you! Link to comment Share on other sites More sharing options...
martin Posted June 25, 2010 Share Posted June 25, 2010 (edited) Easier (IMO) if you don't use those loops at all. [autoit] #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <timers.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Palm Backup", 498, 271, 192, 124) $Warning = GUICtrlCreateLabel("Warning", 200, 16, 89, 28) GUICtrlSetFont(-1, 16, 800, 0, "ariel") $Text1 = GUICtrlCreateLabel("Palm is about to backup closing ALL open appointments", 48, 64, 394, 22) GUICtrlSetFont(-1, 12, 400, 0, "ariel") $Text2 = GUICtrlCreateLabel("To cancel this backup in order to save changes click 'Cancel' within", 16, 96, 465, 22) GUICtrlSetFont(-1, 12, 400, 0, "ariel") $CntDwn = GUICtrlCreateLabel("15", 232, 136, 26, 26) GUICtrlSetFont(-1, 14, 800, 0, "ariel") $Text3 = GUICtrlCreateLabel("seconds", 216, 176, 63, 22) GUICtrlSetFont(-1, 12, 400, 0, "ariel") $OK = GUICtrlCreateButton("Ok", 160, 224, 75, 25, $WS_GROUP) $Cancel = GUICtrlCreateButton("Cancel", 256, 224, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $MaxTime = 15;sec _Timer_SetTimer ($Form1, 1000, "Count") While 1 $nMsg = GUIGetMsg() Select case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $OK Or $MaxTime = -1 GUIDelete($Form1) backup () exit Case $nMsg = $Cancel GUIDelete($Form1) Exit EndSelect WEnd Func backup() msgbox(0,"backing up","ok") EndFunc Func Count($a, $b, $c, $d) $MaxTime -= 1 GUICtrlSetData($CntDwn, $MaxTime ) EndFunc ;==>DoWhatever [\autoit] Edited June 25, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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