PDA

View Full Version : Default values for function parameters



ErosOlmi
18-05-2007, 07:46
We are working on adding the possibility to indicate default values for numeric parameters passed BYVAL in function calling.
To be more clear, it will be possible something like that:



uses "console"
'---Define a function with 2 mandatory BYVAL params having default values
' 3rd param is optional again with default value
' 4th param is again optional but no default value so its value in function will be 0 if not passed
function MyFunction(p1 as long = 100, p2 as long = 200, optional p3 as long = -1, p4 as quad)
console_writeline p1, p2, p3, p4
end function

console_writeline "--- many possible ways to call functions will be avaibale"
MyFunction(,)
MyFunction(,,)
MyFunction(,,2000)
MyFunction(,123,2000)
MyFunction(765,,2000)
MyFunction(765,,-150, 45)
console_waitkey


that will produce the following output:


--- many possible ways to call functions will be avaibale
100 200 -1 0
100 200 -1 0
100 200 2000 0
100 123 2000 0
765 200 2000 0
765 200 -150 45


We will start with numeric params but if all ok we will move to string params.

Stay tuned.
Eros

kryton9
18-05-2007, 21:05
That is a very nice addition. You are making it to nice to program in thinBasic, it is making it hard for me to study other languages!!

ErosOlmi
19-06-2007, 10:20
This is now included in official release.