Funktionsaufruf

Previous topic - Next topic

WPShadow

Hi,

ich bastle momentan an einem Projekt und mir ist folgendes aufgefallen:

Wenn ich eine Funktion erstelle, in der gewisse Werte "vordefiniert" sind

Code (glbasic) Select

FUNCTION test: a = 1, b = 2, c = 3

ENDFUNCTION


dann ist es zwar möglich, die Function ohne eingetragenen Wert aufzurufen

Code (glbasic) Select

test()


jedoch bereitet es mir leichte Probleme, wenn ich z.B. nur den Wert von c ändern will.

Der Aufruf

Code (glbasic) Select

test(,,3)


funktioniert in dem Fall ja nicht.

Wie kann ich da vorgehen? Muss ich eigentlich sämtliche Werte mit angeben, wenn ich einen geänderten Wert angeben möchte?

lg

W.
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

hardyx

#1
Yes, you must to specify all the parameters if you want to pass the last (c).

test(1,2,3)

If you are designing the function, you can put the more used parameters at the beggining.

WPShadow

Ich weiß, daß eine Function soweit normal funktioniert...

Was ich mich gefragt habe, ist, ob man da nicht irgendwie einen Dummy - Wert einfügen kann (oder leer lassen) um nicht alles vor ausfüllen zu müssen.

Code (glbasic) Select

// for example

test(dummy, dummy, 5)

// or

test( , , 5)



Leider gibt es, soweit ich weiß, die Möglichkeit ja nicht, oder?
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

hardyx

#3
No, there is no way to put only the third parameter.

It's like optional parameters in Visual Basic (and many languages):
http://msdn.microsoft.com/en-us/library/vstudio/ssaskzyc%28v=vs.100%29.aspx

"You can define more than one optional parameter, but all the optional parameters must be at the end of the parameter list. All the required parameters must precede every optional parameter."

WPShadow

ok, then I've to work with TYPEs  =D

thx for your help  :good:

AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est