Sign in to follow this  
Followers 0
nullschritt

function not declaring default variable value?

5 posts in this topic

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

 

Share this post


Link to post
Share on other sites



#4 ·  Posted (edited)

func _messagego($enckey)

if not IsDeclared("enckey") Then $enckey = "Default"


endfunc

so it works

Edited by Edano
1 person likes this

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0