WundaGirl Posted June 14, 2010 Share Posted June 14, 2010 Hello I found this code and I want it to run a command when the timer is at the end of the countdown or cancel if the button is pressed. I was wondering if someone could help me understand how to make that happen currently if the user hits cancel the countdown timer is stopped but the script continues execute the run command. How can I make so that when someone hits cancel. thanks Obviously I a new to this. Thanks #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3 ;milliseconds for timer, start the timer and label text $ms = 10000 ;3601000 $timer = TimerInit() $labeltext = "The IT department is applying updates to your computer..." ; ;gui window with text, Install Now button and timer window GUICreate("Software Updates", 350, 330, -1, -1, $WS_DLGFRAME, $WS_EX_TOPMOST) $Cancel = GUICtrlCreateButton ("Cancel", 100, 250, 150, 50) $Label = GUICtrlCreateLabel($labeltext, 10, 10, 330, 200) $Input = GUICtrlCreateInput("", 140, 225, 75, 20, BitOr($SS_CENTER, $ES_READONLY)) GUISetState (@SW_SHOW) ; ;wait for timer to expire or for Install Now button to be clicked ;each time around the loop, it will update the timer displayed on the screen ; While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Cancel) ; $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) If GUIGetMsg() = $Cancel then ExitLoop GUICtrlSetData($Input, $time) ; WEnd Run("calc.exe") Link to comment Share on other sites More sharing options...
anixon Posted June 14, 2010 Share Posted June 14, 2010 Hello I found this code and I want it to run a command when the timer is at the end of the countdown or cancel if the button is pressed. I was wondering if someone could help me understand how to make that happen currently if the user hits cancel the countdown timer is stopped but the script continues execute the run command. How can I make so that when someone hits cancel. thanks Obviously I a new to this. Thanks #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3 ;milliseconds for timer, start the timer and label text $ms = 10000 ;3601000 $timer = TimerInit() $labeltext = "The IT department is applying updates to your computer..." ; ;gui window with text, Install Now button and timer window GUICreate("Software Updates", 350, 330, -1, -1, $WS_DLGFRAME, $WS_EX_TOPMOST) $Cancel = GUICtrlCreateButton ("Cancel", 100, 250, 150, 50) $Label = GUICtrlCreateLabel($labeltext, 10, 10, 330, 200) $Input = GUICtrlCreateInput("", 140, 225, 75, 20, BitOr($SS_CENTER, $ES_READONLY)) GUISetState (@SW_SHOW) ; ;wait for timer to expire or for Install Now button to be clicked ;each time around the loop, it will update the timer displayed on the screen ; While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Cancel) ; $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) If GUIGetMsg() = $Cancel then ExitLoop GUICtrlSetData($Input, $time) ; WEnd Run("calc.exe") Link to comment Share on other sites More sharing options...
GEOSoft Posted June 14, 2010 Share Posted June 14, 2010 Hello I found this code and I want it to run a command when the timer is at the end of the countdown or cancel if the button is pressed. I was wondering if someone could help me understand how to make that happen currently if the user hits cancel the countdown timer is stopped but the script continues execute the run command. How can I make so that when someone hits cancel. thanks Obviously I a new to this. Thanks #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3 ;milliseconds for timer, start the timer and label text $ms = 10000 ;3601000 $timer = TimerInit() $labeltext = "The IT department is applying updates to your computer..." ; ;gui window with text, Install Now button and timer window GUICreate("Software Updates", 350, 330, -1, -1, $WS_DLGFRAME, $WS_EX_TOPMOST) $Cancel = GUICtrlCreateButton ("Cancel", 100, 250, 150, 50) $Label = GUICtrlCreateLabel($labeltext, 10, 10, 330, 200) $Input = GUICtrlCreateInput("", 140, 225, 75, 20, BitOr($SS_CENTER, $ES_READONLY)) GUISetState (@SW_SHOW) ; ;wait for timer to expire or for Install Now button to be clicked ;each time around the loop, it will update the timer displayed on the screen ; While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Cancel) ; $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) If GUIGetMsg() = $Cancel then ExitLoop GUICtrlSetData($Input, $time) ; WEnd Run("calc.exe") expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3 ;milliseconds for timer, start the timer and label text $ms = 10000 ;3601000 $timer = TimerInit() Local $iRun = True $labeltext = "The IT department is applying updates to your computer..." ; ;gui window with text, Install Now button and timer window GUICreate("Software Updates", 350, 330, -1, -1, $WS_DLGFRAME, $WS_EX_TOPMOST) $Cancel = GUICtrlCreateButton ("Cancel", 100, 250, 150, 50) $Label = GUICtrlCreateLabel($labeltext, 10, 10, 330, 200) $Input = GUICtrlCreateInput("", 140, 225, 75, 20, BitOr($SS_CENTER, $ES_READONLY)) GUISetState (@SW_SHOW) ; ;wait for timer to expire or for Install Now button to be clicked ;each time around the loop, it will update the timer displayed on the screen ; While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Cancel) ; $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) If GUIGetMsg() = $Cancel then $iRun = False ExitLoop EndIf GUICtrlSetData($Input, $time) ; WEnd If $iRun Then Run("calc.exe") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
JohnOne Posted June 14, 2010 Share Posted June 14, 2010 At first glance I would sayWhile (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Cancel)needs to beWhile (TimerDiff($timer) < $ms) Or (GUIGetMsg() <> $Cancel) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
anixon Posted June 14, 2010 Share Posted June 14, 2010 (edited) You can simply set a variable flag set by the cancel process and then have the 'Run' conditional upon the process flag as set. .......... Local $SetFlag = 0 If GUIGetMsg() = $Cancel then $SetFlag = 1 Exitloop Endif Wend If $SetFlag = 0 Then Run("Calc.exe)" Ant.. Edited June 14, 2010 by anixon Link to comment Share on other sites More sharing options...
WundaGirl Posted June 14, 2010 Author Share Posted June 14, 2010 HI anixon I tried adding this Local $SetFlag = 0 If GUIGetMsg() = $Cancel then $SetFlag = 1 Exitloop Endif Wend If $SetFlag = 0 Then Run("Calc.exe)" I got this message (39) : ==> Error parsing function call. Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2010 Share Posted June 14, 2010 At a glance: this line is badly formatted => If $SetFlag = 0 Then Run("Calc.exe)" Should be => If $SetFlag = 0 Then Run("Calc.exe") Whether it solves your problem, I'm not sure. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2010 Share Posted June 14, 2010 GEOSofts solution works fine. It just misses a closing (>) tag on the 4th line. => #include <EditConstants.au3> operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
WundaGirl Posted June 14, 2010 Author Share Posted June 14, 2010 Geosoft Your solution works perfectly thank you. Link to comment Share on other sites More sharing options...
GEOSoft Posted June 14, 2010 Share Posted June 14, 2010 You're most welcome George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
GEOSoft Posted June 14, 2010 Share Posted June 14, 2010 GEOSofts solution works fine. It just misses a closing (>) tag on the 4th line. => #include <EditConstants.au3> You thought you caught me didn't you? Actually I should have noticed it mising in the original code but all I did was a C&P and then made the obvious changes. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2010 Share Posted June 14, 2010 (edited) Not really. I noticed that after I looked for a second time. There still seems to be some odd behaviour though. It intermittently seems to not be working. That could have something to do with hitting the cancel button at an inconvenient moment. Or it could just be my computer, but I doubt that. I'm trying to figure out why, or if it's just me. Run it a few times hitting the cancel button at different time intervals and see if the calculator starts. I think I've figured it out.This line => While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Cancel)expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> ;milliseconds for timer, start the timer and label text $ms = 10000 ;3601000 $timer = TimerInit() Local $iRun = True $labeltext = "The IT department is applying updates to your computer..." ; ;gui window with text, Install Now button and timer window GUICreate("Software Updates", 350, 330, -1, -1, $WS_DLGFRAME, $WS_EX_TOPMOST) $Cancel = GUICtrlCreateButton ("Cancel", 100, 250, 150, 50) $Label = GUICtrlCreateLabel($labeltext, 10, 10, 330, 200) $Input = GUICtrlCreateInput("", 140, 225, 75, 20, BitOr($SS_CENTER, $ES_READONLY)) GUISetState (@SW_SHOW) ; ;wait for timer to expire or for Install Now button to be clicked ;each time around the loop, it will update the timer displayed on the screen ; While (TimerDiff($timer) < $ms) ; $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) If GUIGetMsg() = $Cancel then $iRun = False ExitLoop EndIf GUICtrlSetData($Input, $time) ; WEnd If $iRun Then Run("calc.exe")Update: Also added the line => Local $iRun = True Edited June 14, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
GEOSoft Posted June 14, 2010 Share Posted June 14, 2010 Not really. I noticed that after I looked for a second time. There still seems to be some odd behaviour though. It intermittently seems to not be working. That could have something to do with hitting the cancel button at an inconvenient moment. Or it could just be my computer, but I doubt that. I'm trying to figure out why, or if it's just me. Run it a few times hitting the cancel butten at different time intervals and see if the calculator starts. I think I've figured it out.No time to play with it at the moment. I'm busy uploading a bug fix version of the PCRE Toolkit. Maybe later.I suspect that if either of us was to sit and re-write the whole thing, there wouldn't be a problem. It's easy to overlook something when you're just reading someone elses code. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2010 Share Posted June 14, 2010 I suspect that if either of us was to sit and re-write the whole thing, there wouldn't be a problem. It's easy to overlook something when you're just reading someone elses code.It's nice of you to show confidence in me. Anyway I just changed one line of code above, and it seems stable. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
GEOSoft Posted June 14, 2010 Share Posted June 14, 2010 (edited) It's nice of you to show confidence in me. Anyway I just changed one line of code above, and it seems stable.And why wouldn't I be confident? You've been around for 6 years and I've had ample opportunity to see what you can do.Good to see it's stable now.Edit: BTW, some of that credit should go to JohnOne as well since he is the first to point out that bad line. Edited June 14, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2010 Share Posted June 14, 2010 (edited) Thanks, I was just tinkering again with it. Broke it and fixed it again. Edit: BTW, some of that credit should go to JohnOne as well since he is the first to point out that bad line.So he did! I hadn't noticed that. Edited June 14, 2010 by czardas operator64 ArrayWorkshop 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