Floppy Posted March 10, 2009 Share Posted March 10, 2009 (edited) Hi, I have this script: #include <GuiConstants.au3> GUICreate("test") $label2=GUICtrlCreateLabel("",20,20,100,20) GUISetState() $m=GUIGetMsg() Do Sleep(1000) GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) Until $m=$GUI_EVENT_CLOSE If $m=$GUI_EVENT_CLOSE Then Exit Why if I click Close button, doesn't the clock stop and doesn't the window close? bye Edited March 10, 2009 by FSoft Link to comment Share on other sites More sharing options...
ajag Posted March 10, 2009 Share Posted March 10, 2009 maybe because the line $m=GUIGetMsg() isn't inside the do-loop... A-Jay Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
ajag Posted March 10, 2009 Share Posted March 10, 2009 but i think you should look for 'GUIOnEventMode' help Opt("GUIOnEventMode", 1) ; We want the program working on events option. Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
Floppy Posted March 11, 2009 Author Share Posted March 11, 2009 I tried both solutions...but it does NOT works! Link to comment Share on other sites More sharing options...
Authenticity Posted March 11, 2009 Share Posted March 11, 2009 #include <GuiConstants.au3> Opt('GuiOnEventMode', 1) GUICreate("test") GUISetOnEvent($GUI_EVENT_CLOSE, '_EXIT') $label2 = GUICtrlCreateLabel("",20,20,100,20) GUISetState() While 1 Sleep(1000) GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) WEnd Func _EXIT() GUIDelete() Exit EndFunc Link to comment Share on other sites More sharing options...
CodyBarrett Posted March 11, 2009 Share Posted March 11, 2009 while & Wend?.... [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Bert Posted March 11, 2009 Share Posted March 11, 2009 #include <GuiConstants.au3> GUICreate("test") $label2=GUICtrlCreateLabel("",20,20,100,20) GUISetState() $x=0 while 1 Sleep(5) $x = $x+1 $m=GUIGetMsg() if $x = 5 then GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $x=0 EndIf If $m=$GUI_EVENT_CLOSE Then Exit wend The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2009 Moderators Share Posted March 11, 2009 FSoft,It does not work for 2 reasons:1. You never poll GUIGetMsg in the loop, so how is AutoIt supposed to know you have clicked on anything?2. The vast majority of your time in the loop is spent in the Sleep(1000) when the script is unresponsive. So even if you were to poll GUIGetMsg you woudl be very unlikely to get a response.This will do what you want:#include <GuiConstantsEx.au3> GUICreate("test") $label2=GUICtrlCreateLabel("",20,20,100,20) GUISetState() Do GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() While TimerDiff($begin) < 1000 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd Until 1 = 2But there is a better way get your label to update without a flicker - look here.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...
CodyBarrett Posted March 11, 2009 Share Posted March 11, 2009 correct me if im wrong but uhh... while its in sleep doesnt it que the msg untill its done the sleep? [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2009 Moderators Share Posted March 11, 2009 CodyBarrett,I did try before posting. ;-)The length of the Sleep seems critical. Have a play with this simple code with the Sleep set at various values:GUICreate("Test", 200, 200) $hBut = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit Case $hBut ConsoleWrite("Pressed" & @CRLF) EndSwitch Sleep(1000) WEndFor me it works fine with Sleep(100). At 500 it appears to stack some button presses and reject others. At 1000 it is pretty much unresponsive. So I can only suppose that Sleep means exactly that - minus the snoring!Perhaps one of the gurus can enlighten us further?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...
Floppy Posted March 12, 2009 Author Share Posted March 12, 2009 FSoft, It does not work for 2 reasons: 1. You never poll GUIGetMsg in the loop, so how is AutoIt supposed to know you have clicked on anything? 2. The vast majority of your time in the loop is spent in the Sleep(1000) when the script is unresponsive. So even if you were to poll GUIGetMsg you woudl be very unlikely to get a response. This will do what you want:#include <GuiConstantsEx.au3> GUICreate("test") $label2=GUICtrlCreateLabel("",20,20,100,20) GUISetState() Do GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() While TimerDiff($begin) < 1000 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd Until 1 = 2 But there is a better way get your label to update without a flicker - look here. M23 I have one button: I want to press it once to start the clock and twice to stop it. I tried this, but the clock doesn't start: While Not GUIGetMsg()=$go If @SEC<>$curr_sec Then GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $curr_sec=@SEC EndIf If GUIGetMsg()=$GUI_EVENT_CLOSE Then Exit WEnd Any solution? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 12, 2009 Moderators Share Posted March 12, 2009 FSoft, Look at this:#include <GuiConstantsEx.au3> GUICreate("test", 200, 200) $label2=GUICtrlCreateLabel("",20,20,100,20) $button = GUICtrlCreateButton("Start", 20, 100, 80, 30) GUISetState() $fTimer = False While 1 If $fTimer Then GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() While TimerDiff($begin) < 1000 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer GUICtrlSetData($button, "Start") GUICtrlSetData($label2, "") EndSwitch WEnd Else Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer GUICtrlSetData($button, "Stop") EndSwitch EndIf WEnd You have been around here for a while - you should be able to solve these simple problems on your own by now. :-) 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...
Floppy Posted March 13, 2009 Author Share Posted March 13, 2009 (edited) What is the variable $fTimer for? ------------ Sometimes, if I click quickly, the clock doesn't start...why? Edited March 13, 2009 by FSoft Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 13, 2009 Share Posted March 13, 2009 If you are calling GUIGetMsg you don't even need Sleep. GUIGetMsg in AutoIt will use a small sleep every time. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2009 Moderators Share Posted March 13, 2009 FSoft,$fTimer is a boolean (True/False) variable which is set according to the state of the timer: True means timer running/label visible - False means timer off/label invisible. This flag variable then determines which While...WEnd loop to use and so what happens when the button is clicked. You need this kind of logic because you said you only wanted one button - if you use two buttons, then each button can have its own series of commands. As an aside, one of the nice things about boolean variables is that you can change their state by using Not as you can see in the script. Here is another way of coding the same thing. In this script the label exists all the time, but you only see it when you start the timer:#include <GuiConstantsEx.au3> GUICreate("Timer Test", 200, 200) $label2 = GUICtrlCreateLabel("",20,20,100,20) GUICtrlSetState(-1, $GUI_HIDE) $button = GUICtrlCreateButton("Start", 20, 100, 80, 30) GUISetState() $fTimer = False $begin = TimerInit() While 1 If TimerDiff($begin) > 1000 Then GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer If $fTimer Then GUICtrlSetData($button, "Stop") GUICtrlSetState($label2, $GUI_SHOW) Else GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) EndIf EndSwitch WEndI must say I prefer this script to the earlier one.As to why the timer does not start if you click too quickly - do you mean nothing happens at all? If so, then AutoIt/Windows has not recognised the click as valid.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...
Floppy Posted March 14, 2009 Author Share Posted March 14, 2009 FSoft, $fTimer is a boolean (True/False) variable which is set according to the state of the timer: True means timer running/label visible - False means timer off/label invisible. This flag variable then determines which While...WEnd loop to use and so what happens when the button is clicked. You need this kind of logic because you said you only wanted one button - if you use two buttons, then each button can have its own series of commands. As an aside, one of the nice things about boolean variables is that you can change their state by using Not as you can see in the script. Here is another way of coding the same thing. In this script the label exists all the time, but you only see it when you start the timer:#include <GuiConstantsEx.au3> GUICreate("Timer Test", 200, 200) $label2 = GUICtrlCreateLabel("",20,20,100,20) GUICtrlSetState(-1, $GUI_HIDE) $button = GUICtrlCreateButton("Start", 20, 100, 80, 30) GUISetState() $fTimer = False $begin = TimerInit() While 1 If TimerDiff($begin) > 1000 Then GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer If $fTimer Then GUICtrlSetData($button, "Stop") GUICtrlSetState($label2, $GUI_SHOW) Else GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) EndIf EndSwitch WEnd I must say I prefer this script to the earlier one. As to why the timer does not start if you click too quickly - do you mean nothing happens at all? If so, then AutoIt/Windows has not recognised the click as valid. M23 Thanks for reply. But the problem is the same. If I click too quickly, nothing happens. Then, if I click again the clock hides. Why? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 14, 2009 Moderators Share Posted March 14, 2009 FSoft,If I click too quickly, nothing happens. Then, if I click again the clock hides.That does not make sense.Look at the script I posted last. The clock is hidden at start, so your click must work if the clock appears. If the clock appears, it runs - because it is running all the time. If you say the the clock disappears when you click a second time - it must logically have been running beforehand. So I do not see how your first click does nothing - and then the second click does. The second click cannot do anything until the first has shown the clock.What does the button text say at each point? As you can see from the script, this changes to reflect what the button will do when next clicked - it says "Stop" when the clock is displayed and "Start" when it is hidden.Anyway the solution is in your hands and is very simple - do not click quickly! :-)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...
Floppy Posted March 15, 2009 Author Share Posted March 15, 2009 FSoft,That does not make sense.Look at the script I posted last. The clock is hidden at start, so your click must work if the clock appears. If the clock appears, it runs - because it is running all the time. If you say the the clock disappears when you click a second time - it must logically have been running beforehand. So I do not see how your first click does nothing - and then the second click does. The second click cannot do anything until the first has shown the clock.What does the button text say at each point? As you can see from the script, this changes to reflect what the button will do when next clicked - it says "Stop" when the clock is displayed and "Start" when it is hidden.Anyway the solution is in your hands and is very simple - do not click quickly! :-)M23On the GUI I created three inputbox, the first for hour, the second for minutes and the third for seconds.How can I hide the clock when the hours, the minutes and the seconds match? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 15, 2009 Moderators Share Posted March 15, 2009 FSoft, Please post the code you are using now. It is very difficult to offer sensible advice if you are not using the code which was last posted! 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...
Floppy Posted March 15, 2009 Author Share Posted March 15, 2009 FSoft, Please post the code you are using now. It is very difficult to offer sensible advice if you are not using the code which was last posted! M23 I'm using the same code: Here it is: expandcollapse popup#include <GuiConstantsEx.au3> GUICreate("Timer Test", 200, 200) $label2 = GUICtrlCreateLabel("",20,20,100,20) GUICtrlSetState(-1, $GUI_HIDE) $button = GUICtrlCreateButton("Start", 20, 100, 80, 30) $hour=GUICtrlCreateInput("",20,150,20,20) $min=GUICtrlCreateInput("",50,150,20,20) $sec=GUICtrlCreateInput("",80,150,20,20) GUISetState() $fTimer = False $begin = TimerInit() While 1 If TimerDiff($begin) > 1000 Then GUICtrlSetData($label2,@HOUR&":"&@MIN&":"&@SEC) $begin = TimerInit() EndIf If $label2=GUICtrlRead($hour)&":"&GUICtrlRead($min)&":"&GUICtrlRead($sec) Then GUICtrlSetState($label2, $GUI_HIDE) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button $fTimer = Not $fTimer If $fTimer Then GUICtrlSetData($button, "Stop") GUICtrlSetState($label2, $GUI_SHOW) Else GUICtrlSetData($button, "Start") GUICtrlSetState($label2, $GUI_HIDE) EndIf EndSwitch WEnd I don't know why it doesn't work! 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