bestsmr Posted November 19, 2010 Share Posted November 19, 2010 why this code freeze my program and show error???? ********************* *****start code****** ********************* #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Timers.au3> opt("MustDeclareVars",1) global $g,$l $g = GUICreate("timmer") $l=GUICtrlCreateLabel("text",100,100,100) GUISetState() _Timer_SetTimer($g,1000,"_update") While 1 sleep(1000) ;_update() WEnd func _update() GUICtrlSetData($l,@HOUR&":"&@MIN&":"&@SEC) EndFunc ********************* *****end code******** ********************* but this code run "ok!" ********************* *****start code****** ********************* #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Timers.au3> opt("MustDeclareVars",1) global $g,$l $g = GUICreate("timmer") $l=GUICtrlCreateLabel("text",100,100,100) GUISetState() ;_Timer_SetTimer($g,1000,"_update") While 1 sleep(1000) _update() WEnd func _update() GUICtrlSetData($l,@HOUR&":"&@MIN&":"&@SEC) EndFunc ********************* *****end code******** ********************* and what meaning of "#forceref" thanks Link to comment Share on other sites More sharing options...
SadBunny Posted November 19, 2010 Share Posted November 19, 2010 In your code, the _update() function is never called because the call is commented out:While 1sleep(1000);_update()WEndHaven't looked into the rest of your code, but this would just make your program sleep for a second, and then go back to sleeping for a second, until hell freezes over. That's no freeze but just an infinite wait loop Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 19, 2010 Share Posted November 19, 2010 @SadBunny: There is nothing wrong with that part, bestsmr expects the timer to call the function, not the loop. @bestsmr: You must define your timer function to handle the four incoming parameters, even if you don't use them: #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Timers.au3> Opt("MustDeclareVars", 1) Global $g, $l $g = GUICreate("timmer") $l = GUICtrlCreateLabel("text", 100, 100, 100) GUISetState() _Timer_SetTimer($g, 1000, "_update") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ;_update() WEnd Func _update($hWnd, $Msg, $iIDTimer, $dwTime) #forceref $hWnd, $Msg, $iIDTimer, $dwTime GUICtrlSetData($l, @HOUR & ":" & @MIN & ":" & @SEC) EndFunc ;==>_update This version works and also includes a way to exit the script. The Syntax Check will give you warnings for declaring variables that are never used. The #ForceRef directive prevents those variables from triggering that warning. It doesn't change anything functional about the script. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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