avlife Posted December 22, 2008 Share Posted December 22, 2008 Hi, I just want to made a simple program to display a number and increase by 1 second. But it doesn't work. Please help me to find out the porblem. Thanks for your help! my code is as below: ========================================= #Include <Timers.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $testgui=GUICreate("My GUI",400,320) $p=1 $label=guictrlcreatelabel($P,50,20,250,150) guictrlsetfont($label,120,400) GUISetState() while 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch _Timer_SetTimer($testgui,1000,"increase") WEnd func increase() GUICtrlSetData($label,$p) $P=$P+1 EndFunc Link to comment Share on other sites More sharing options...
TurionAltec Posted December 22, 2008 Share Posted December 22, 2008 (edited) Hi, I just want to made a simple program to display a number and increase by 1 second. But it doesn't work. Please help me to find out the porblem. Thanks for your help!I think there were several issues. One thing is I think it might be trying to continuously add new timers. Also if you use the "Autoit" tag in your post around the code, it makes it easier for others to read it, eg: msgbox(1,"","Hello World") I made some changes, I changed to OnEventMode, which makes polling for the close a little easier And I used an Adlib function instead of _Timer_SetTimer. Granted there's several different ways you could approach this problem. #Include <Timers.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $testgui=GUICreate("My GUI",400,320) $p=1 $label=guictrlcreatelabel($P,50,20,250,150) guictrlsetfont($label,120,400) opt("GUIOnEventMode",1) ;Setting GUIOnEventMode is easier than the polling loop you had GUISetOnEvent ($GUI_EVENT_CLOSE, "Quit") ;Will call function quit if $GUI_EVENT_CLOSE is recieved GUISetState() AdlibEnable("increase",1000) ;Adlib will run the function "increase" every 1000ms ;Much easer than _Timer_SetTimer while 1 ;Don't need anything in the While loop, ;GUIOnEventMode will just idle around in here ;If you wish to poll, you should introduce a sleep() delay to keep it from eating all the CPU time WEnd func increase() $P=$P+1 GUICtrlSetData($label,$p) EndFunc func Quit() Exit EndFunc Edited December 22, 2008 by TurionAltec Link to comment Share on other sites More sharing options...
TurionAltec Posted December 22, 2008 Share Posted December 22, 2008 Here's another option using _TimerDiff which will show proper time if you hold down (but don't select) the close button, or if the CPU is over loaded #Include <Timers.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $testgui=GUICreate("My GUI",400,320) $P=0 $label=guictrlcreatelabel($P,50,20,250,150) guictrlsetfont($label,120,400) opt("GUIOnEventMode",1) GUISetOnEvent ($GUI_EVENT_CLOSE, "Quit") GUISetState() $starttime=_Timer_Init() AdlibEnable("increase",500) while 1 WEnd func increase() $P=Int(_Timer_Diff($starttime)/1000) GUICtrlSetData($label,$p) EndFunc func Quit() Exit EndFunc Link to comment Share on other sites More sharing options...
avlife Posted December 23, 2008 Author Share Posted December 23, 2008 Hi TurionAltec, Thank you very much for your help. I tried both code, it could works normally but the CPU load will reach 50% on my dual core PC. I also tryied the example script for _Timer_SetTimer, the CPU usage is around 0% even the progress bar is moving. I believe Autoit should be able to reach my simple target with low CPU usage. If possible, please teach another way. Thank you very much for your patience. Link to comment Share on other sites More sharing options...
rasim Posted December 23, 2008 Share Posted December 23, 2008 @avlifeI tried both code, it could works normally but the CPU load will reach 50% on my dual core PC.Just insert a Sleep(50) in the While Wend loop 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