Subject Re: how to handle missing optional arguments in a function
From Ken Mayer <dbase@nospam.goldenstag.net>
Date Thu, 1 Oct 2020 13:40:17 -0700
Newsgroups dbase.getting-started

On 10/1/2020 1:26 PM, Gaetano wrote:
>
>
> Hi All,
>
> I have customized one webclass.cc function to add a text msg to
> the errorMessage function:
>
> Function errorMessage( oErr, cMsg, cTitleBackColor, cTitleTextColor )
>
> if you supply less than the total count of arguments, how does dBase
> know which argument is supplied and which is omitted?
>
> In other words, if I only want to supply cMsg or only a cTitleTextColor
> but no cTitleBackColor, how to I do that? Is there a standard
> placeholder for empty arguments?
>
> would something like the following work?
>
> errorMessage(,"my message",,"red")
>
> If I have to test for argument types, how do I reference the "first
> argument"?

Best idea is to put optional ones at the end.

Look at pCount() or argCount() (number of parameters passed to the
function -- the two functions do the same thing)

ArgVector( n ) returns the value of the argument numbered "n"

In your code you can always check to see if the parameter has a type:

if type( "oErr" ) == "U"
    // do what you need to if this is left out
endif

And so on ...

But seriously, the way most routines work is the required parameters are
ALWAYS first, the optional ones come after.

Ken

--
*Ken Mayer*
Ken's dBASE Page: http://www.goldenstag.net/dbase
The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm