Jump to content

function not declaring default variable value?


Go to solution Solved by Edano,

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...