Doomscape Posted December 18, 2011 Posted December 18, 2011 Hello! i want to make a timer for my installation program. like how much time it took to install it in seconds, 60 secs converted to min and 60 mins to hours.also my STOP button doesnt work cause "program" is going on another loop like =While 1$nMsg = GUIGetMsg()Switch $nMsgCase $GUI_EVENT_CLOSEExitCase $button2 <---- this doesnt work after i press button1Exitcase $button1"loops here"
Developers Jos Posted December 18, 2011 Developers Posted December 18, 2011 That means you need to change you logic and not use a closed loop without checking whether a control is pressed. It is always a lot more helpful when you post a scriptlet that demonstrates the issue and we can work with and show you how it could be done. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Doomscape Posted December 18, 2011 Author Posted December 18, 2011 Well how to make a timer, i guess you dont need example script for it? eh $timer = 0 and somewhere $timer = $timer + 1 but i cant make it do it like every tick.
Developers Jos Posted December 18, 2011 Developers Posted December 18, 2011 post something we can work with... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Mikeman27294 Posted December 18, 2011 Posted December 18, 2011 (edited) Here you go. I'm a killer for not comenting my code, but I have gone a bit overboard here. But I guess it doesn't hurt, does it? This should give you a decent idea what to do. You can also use buttons and other GUI Controls with it, this is just to demonstrate a timer and GUI On Event Mode to make your script a little easier to write. Opt("GuiOnEventMode", 1) ;I use on event mode because I find that it makes writing my scripts easier Global $Seconds = 0 Global $Minutes = 0 Global $Hours = 0 ;Declaring the required functions as global or the script will crash Global $GuiArray[2] ;I use Arrays for each different GUI just as a personal preference $GuiArray[0] = GUICreate("Timer", 64, 32, -1, -1, 0x80000000) ;Creating a GUI with the WS_POPUP style $GuiArray[1] = GUICtrlCreateLabel("0h:0m:0s", 10, 10) GUISetOnEvent(-3, "_Exit") ;When the GuiEvent for on event mode is GUI_EVENT_CLOSE the script calls the exit function GUISetBkColor(0x000000, $GuiArray[0]) ;Makes the background black for easier viewing against bright backgrounds GUICtrlSetColor($GuiArray[1], 0xF0F0F0) ;Makes the text visible as white GUISetState(@SW_SHOW, $GuiArray[0]) ;Shows the GUI AdlibRegister("_Timer", 1000) ;Registers the function "_Timer" to run every second While 1 ;AdLibRegister and GuiOnEvent mode dont keep the script running, so use a while loop. WEnd Func _Timer() ;The timer function, Use as you wish. $Seconds += 1 If $Seconds = 60 Then $Minutes += 1 If $Minutes = 60 Then $Hours += 1 $Minutes = 0 EndIf $Seconds = 0 EndIf GUICtrlSetData($GuiArray[1], $Hours&"h:"&$Minutes&"m:"&$Seconds&"s") ;Sets the GUI Label to the current time. EndFunc Func _Exit() ;Exit function called by the GUI Event GUI_EVENT_CLOSE Exit EndFunc Also, by using GuiOnEvent mode, you can call each GUI Control's appropreate function no matter what the script is doing, and after completing that function, it will return straight back to where it was before running the function. Edited December 18, 2011 by Mikeman27294
Moderators Melba23 Posted December 18, 2011 Moderators Posted December 18, 2011 Mikeman27294,by using GuiOnEvent mode, you can call each GUI Control's appropreate function no matter what the script is doingNot strictly true - look at the Interrupting a running function tutorial in the Wiki. 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
Mikeman27294 Posted December 18, 2011 Posted December 18, 2011 (edited) I wasnt 100% sure but I was quite confident. Thanks for the heads up, I will take a look.EDITWell for the sake of correcting myself then, here is what the page on the wiki has to say;"AutoIt queues function calls in both OnEvent and MessageLoop modes. This means that it waits until a function is finished and the code is back in your idle While...WEnd loop before running the next."In short, the function calls are queued.Thanks Melba23. Edited December 18, 2011 by Mikeman27294
Moderators Melba23 Posted December 18, 2011 Moderators Posted December 18, 2011 Mikeman27294,You did not read far enough into the tutorial. You can interrupt a function with an OnEvent call "as long as the function is started within the main code and not by an OnEvent call". So you were more correct than you think. 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
Mikeman27294 Posted December 18, 2011 Posted December 18, 2011 Haha thanks. I'll just smile and pretend I knew that the whole time
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