Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Default values in functions

Author
Message
Pipes
20
Years of Service
User Offline
Joined: 17th Sep 2004
Location:
Posted: 7th Mar 2009 03:39
Is it possible to construct functions with default values in DBPro?For instance the user calls the function but doesn't specify any values in the parameters. The function uses the default values set up by the programmer thereby making the parameter optional. i.e...

FUNCTION myFunction(a = 1, b = 2, c = 3)

value = a + b + c

ENDFUNCTION value

Function call ...

myFunction(23)

The parameters b & c are optional in this case or...

myFunction()... all the parameters are optional.

I've had DBPro for a number of years but have never used it. I was an avid Blitz3D Basic user where these type of functions are routine as in many programming languages. I just can't seem to get it to work in DBPro. I could set up some default values in the function body but that seems pretty lame to me. Thanks for any help in advance.

Pipes

Contempt Prior to Investigation = Everlasting Ignorance
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 7th Mar 2009 10:57
I don't know, but the usual way to go around such things is to declare more than one signature for the function name with various parameters.
For example:

And so on.

I'm unsure whether DBPro would allow these duplicate names though.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 7th Mar 2009 12:37
Oh yeah, the most efficient way to do that is of course that you have one "source" function which takes all the parameters, then the signatures for the ones with less simply call that one (and, if required, forwards its return value) with the default values as parameters.
Like so:


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Mar 2009 16:12
DBP will always give a "the name .. is duplicated" error.

I don't think it's possible...

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Mar 2009 16:30
A convention I use where I can't give a different meaningful name to related functions is to follow the function name with an underscore and the number of parameters.

@Pipes,
DBPro has no default values for parameters, and no function overloading. You'll need to use Rudolpho's suggestion (with my amendment or similar), deal with having the extra parameters specified each time, or even possibly write a preprocessor that will fill in the defaults for you before passing the final source to the compiler.

Pipes
20
Years of Service
User Offline
Joined: 17th Sep 2004
Location:
Posted: 7th Mar 2009 23:35
Thanks for the replies. Bummer Dude! No default parms. Perhaps that could end up as a suggestion for future updates.

Thanks again

pipes

Contempt Prior to Investigation = Everlasting Ignorance

Login to post a reply

Server time is: 2024-11-25 10:35:46
Your offset time is: 2024-11-25 10:35:46