Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check if an optional var exist in a function

Status
Not open for further replies.

ExtraD

Programmer
Jul 6, 2005
41
0
0
NL
Hi,

I have a function header like this:

Private Function CostCalculation_calculateCosts(cnSQLFY As ADODB.Connection, _
cnFoxpro As ADODB.Connection, _
cnSQLFCC As ADODB.Connection, _
rp As RouteParameters, _
info As FCCMainClass, _
Optional act As Variant, _
Optional up As UnitParameters) _
As CalcCostType

How can I check if the parameters up is included? I treid the function IsMissing but he always returns FALSE. When he not available I get the message “Object variable or With block variable not set”.

Could somebody help me?

Thanx

 
I'm afraid that IsMissing only works against Variants.

Optional non-variant arguments without a default value follow the same rules as if they had just been dimensioned (e.g numerics = 0, strings = vbNullString, objects = Nothing)

So your options are to set a default value, or to write excpetion code to deal with the 'missing' parameter

To detect whether an object parameter is missing, just test whether it Is Nothing (although this cannot discriminate from the case where someone has actually passed you Nothing as the object)
 
Thanx for your replys i will go for the nothing option.

 
Which is probably for the best; the VarType solution won't really work as you might hope
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top