nullschritt Posted July 26, 2013 Posted July 26, 2013 Hello, I am having a slight problem, do not know if it's an autoit bug or what, but when I try to declare a default value for a function them call it via guictrlsetonevent, the variable is not declared. I have tried pretty much everything I can think of, setting it to default, true, false, numbers, and strings, and it's always the same error. func _messagego($enckey = "Default") if not IsDeclared($enckey) Then $enckey = $activekey Else endif endfunc "Y:SIMNetworkingoutgoing.au3" (4) : ==> Variable used without being declared.: if not IsDeclared($enckey) Then if not IsDeclared(^ ERROR
JohnOne Posted July 26, 2013 Posted July 26, 2013 You can not call a function using parameters Says the help file. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JohnOne Posted July 26, 2013 Posted July 26, 2013 I might be totally off here, but just for giggles try this func _messagego($enckey = "Default") #forceref $enckey if not IsDeclared($enckey) Then $enckey = $activekey Else endif endfunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Solution Edano Posted July 26, 2013 Solution Posted July 26, 2013 (edited) func _messagego($enckey) if not IsDeclared("enckey") Then $enckey = "Default" endfunc so it works Edited July 26, 2013 by Edano nullschritt 1 [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]
kylomas Posted July 26, 2013 Posted July 26, 2013 (edited) nullschritt, Functions can contain no parms, required parms or optional parms. Optional parms can have a default value. Autoit provides two ways to say that you want the default value, specify a '-1' or DEFAULT (keyword) for the parm in the calling function. The only tricky part is that all preceding parameters must be specified in the function call. Run the following to see if this makes more sense. _messagego(-1) _messagego(999) _messagego(default) _messagego() ; function is defined with an optional parameter having a default value of 'test' func _messagego($enckey = 'test') if $enckey = -1 or $enckey = default then $enckey = 'test' ; <--- enforces value specified in func call if user calls with -1 or "default" ConsoleWrite($enckey & @LF) endfunc kylomas edit: spelling Edited July 26, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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