AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Calling a function with omitted parameters

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Andi



Joined: 11 Feb 2005
Posts: 157
Location: Germany, Niestetal

PostPosted: Sat Apr 23, 2005 1:09 pm    Post subject: Calling a function with omitted parameters Reply with quote

Is there a way to omit parameters, when you call a function?

Code:

x = 1
z = 2
add(x, , z) ;this does not work and brings an error: Blank parameter


When I understand it right, you have to pass always a blank var.

Code:

x = 1
y=
z = 2
add(x, y, z) ;and it works
Back to top
View user's profile Send private message
mario_a



Joined: 12 Dec 2004
Posts: 51

PostPosted: Sat Apr 23, 2005 1:24 pm    Post subject: Reply with quote

Try calling the function like this :

Code:
add(x, "", z)


i.e. an empty pair of double quotes for the blank parameter.

HTH,
Mario
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sat Apr 23, 2005 2:03 pm    Post subject: Reply with quote

Yes, empty quotes is how you would pass a blank value. There is a plan to add default parameters to a future version, which would allow some parameters to become optional. For example:
Code:
Add(X, Y, Z = 0)
{
    return X + Y + Z
}

; And call it with only two parameters to keep Z's zero default:
Result := Add(3, 2)
Back to top
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sat Apr 23, 2005 5:08 pm    Post subject: Reply with quote

Code:
MsgBox, % Add(124, Null, 12)
MsgBox, % Hello("World", Null)
MsgBox, % Hello(USERNAME, " How are You`?")
MsgBox, % Add(2, Null, Null)


Add(x, y, z)
{
if y =
  y = 0
if z =
  z = 12
Return x + y + z
}

Hello(x, y)
{
Return "Hello "x ". " y
}
Back to top
View user's profile Send private message Visit poster's website
Andi



Joined: 11 Feb 2005
Posts: 157
Location: Germany, Niestetal

PostPosted: Sat Apr 23, 2005 9:13 pm    Post subject: Reply with quote

Thank you for your answers.

I what to mention, that the way corrupt suggested, requires that the var null is really an empty var (null = ). When "null = 0" it doesn't work. Twisted Evil
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sun Apr 24, 2005 2:49 pm    Post subject: Reply with quote

Andi wrote:
I what to mention, that the way corrupt suggested, requires that the var null is really an empty var (null = ). When "null = 0" it doesn't work. Twisted Evil
I would consider that to be expected and consistent behaviour. If a variable named Null isn't assigned a value this shouldn't become an issue Wink.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group