| View previous topic :: View next topic |
| Author |
Message |
Andi
Joined: 11 Feb 2005 Posts: 157 Location: Germany, Niestetal
|
Posted: Sat Apr 23, 2005 1:09 pm Post subject: Calling a function with omitted parameters |
|
|
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 |
|
 |
mario_a
Joined: 12 Dec 2004 Posts: 51
|
Posted: Sat Apr 23, 2005 1:24 pm Post subject: |
|
|
Try calling the function like this :
i.e. an empty pair of double quotes for the blank parameter.
HTH,
Mario |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Sat Apr 23, 2005 2:03 pm Post subject: |
|
|
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 |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2436
|
Posted: Sat Apr 23, 2005 5:08 pm Post subject: |
|
|
| 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 |
|
 |
Andi
Joined: 11 Feb 2005 Posts: 157 Location: Germany, Niestetal
|
Posted: Sat Apr 23, 2005 9:13 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2436
|
Posted: Sun Apr 24, 2005 2:49 pm Post subject: |
|
|
| 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.  | 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 . |
|
| Back to top |
|
 |
|