AutoHotkey Community

It is currently May 27th, 2012, 12:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: August 27th, 2011, 9:03 pm 
Offline

Joined: March 16th, 2008, 6:48 pm
Posts: 161
Location: Brooklyn
I've written several functions, which I reuse. Is it possible to make it so that the parameters I pass are optional? If they are not passed, it could revert to a default value. For example, in one of my functions, I have two optional parameters. So currently, if I want to call it, I have to write the following

Code:
extractFunction("","")  ; - - -  To use default values

or
Code:
extractFunction("2","1")  ; - - -  To use custom values


Is it possible to do something where the person calling the values doesn't need to know that there are 2 parameters? IE, just this

Code:
extractFunction()

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2011, 9:21 pm 
You forgot to read the "functions" help page in the manual? Right?

Code:
extract(15)

extractFunction(arg1=10, arg2="hello") {
 ;function body
 msgbox, %arg1%`n%aurg2%
}


Read the help file page, for a certain limitation of default values


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2011, 9:21 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Code:
ExtractFunction()   ; default values
ExtractFunction("alpha", "beta")   ; custom values

ExtractFunction(x="DefaultX", y="DefaultY") {
   MsgBox, % x "`n" y
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2011, 3:18 am 
Offline

Joined: March 16th, 2008, 6:48 pm
Posts: 161
Location: Brooklyn
I normally read the documentation, but didn't think to do so here. I could do without the attitude, but I appreciate the help. Thanks, it's exactly what I needed.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad, MSN [Bot] and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group