What is the proper method to know whether the optional arguments are supplied or Not?

What I took the thread to mean was as follows.

say you have a function

function funccheckdate(startdate as date, optional enddate)

rereading the thread seems to imply that the function header as above is fine
ismissing(enddate) will return true or false, depending whether the argument was passed


BUT - say you incorrectly put
function funccheckdate(startdate as date, optional enddate as date)

then the very fact that you inadvertently included the type qualification, means then this can NEVER return true for ismissing

Yes ... that is correct ... but I would say "included a non-variant type qualification" .. because you can include the type qualification of Variant.

function funccheckdate(startdate as date, optional enddate as variant)

And IsMissing() will function as expected.

And yes to some degree this is splitting hairs, but if I were just starting VBA, the ambiguities need to be removed in the commentaries.

-----

Note that as I re-read some of my reply's, it seems they can be interpreted as if I am trying to provoke negativity by being direct! ... Please know that I am not trying to do anything of the sort! ... Just talking technical :D
 
Yes ... that is correct ... but I would say "included a non-variant type qualification" .. because you can include the type qualification of Variant.

function funccheckdate(startdate as date, optional enddate as variant)

And IsMissing() will function as expected.

And yes to some degree this is splitting hairs, but if I were just starting VBA, the ambiguities need to be removed in the commentaries.

-----

Note that as I re-read some of my reply's, it seems they can be interpreted as if I am trying to provoke negativity by being direct! ... Please know that I am not trying to do anything of the sort! ... Just talking technical :D



---------
Just to say - I edited my previous note AFTER testing it - I think this is so perverse, and not at all obvious. I'm off to check how i've coded my optional arguments now. - (I dont use them very often, but I have used them)
 
Like Brent, I too think it is important to reply to questions in as technically correct fashion as we can.

The original poster may be confused by the answer but at least they can examine the post in detail at their leisure. They can pull it apart, check reference material and even ask further questions on the subject.

But if a reply is imprecise the original poster could easily become more confused because they would have to understand the mistakes which were made in the reply.

In a sense, mistakes are more difficult to understand than the facts, as semantic as the facts may be.
 
Last edited:
Hello Dave ...

>> If you dont include the type <<

Just to varify, Did you know that if a variable is not declared to a specific type, VBA will give it the Variant type?

The following statements yield the same resultant type for "someVariable":

Dim someVariable As Variant

Dim someVariable
 
Hello Dave ...

>> If you dont include the type <<

Just to varify, Did you know that if a variable is not declared to a specific type, VBA will give it the Variant type?

The following statements yield the same resultant type for "someVariable":

Dim someVariable As Variant

Dim someVariable



do you mean me?

I didnt expect to get into this discussion, It was nothing to do with understanding the difference between a variant, and other variable types

To repeat, I just had not considered that

optional somedata

and

optional somedata as string

would/might not both work in exactly the same manner, (which ChrisO pinted out early in the thread), and on checking I did find a few instances where I had used the latter construct, but had still tried to use ismissing.

Not a mistake I will make again.

Nuff said.
 

Users who are viewing this thread

Back
Top Bottom