N
new2access123 via AccessMonster.com
Determining if s a parameter has been passed to a function
When I create a function the first thing I like to do in the function is
check thatr all the parameters have been passed. In FoxPro or C# I would
check for an empty string or NULL. I did some checking and found this…
Typed variables (that is, all variables other than variants) which do not
refer to objects and which have not been set, are initialized in VBA,
depending on their type:
- zero for numeric types
- zero-length string for string types
Only a Variant type variable can be NULL or EMPTY and detected with the
IsEmpty() or IsNull() functions
A parameter can only be Missing if it is untyped (declared as Optional Var2
or Optional Var2 As Variant), and will only be Missing if it is not supplied
by the calling code. To check if a parameter is missing use the IsMissing()
function.
So it sounds like the only way to know if a parameter has been passed is to
pass all parameters as variants and use IsMissing(). But I have also learned
from a thread here that it is bad form not to pass strongly type the input
parameters. On the other hand if I pass strongly type the input parameters
and a numeric parameter value, for example, is zero. I will not be able to
detect if the parameter was not passed or if VBA defaulted it.
Is there a technique I am messing?
Do I use bad form and make parameters variants?
Or do I not check?
How do you pros handle this?
Thanks
When I create a function the first thing I like to do in the function is
check thatr all the parameters have been passed. In FoxPro or C# I would
check for an empty string or NULL. I did some checking and found this…
Typed variables (that is, all variables other than variants) which do not
refer to objects and which have not been set, are initialized in VBA,
depending on their type:
- zero for numeric types
- zero-length string for string types
Only a Variant type variable can be NULL or EMPTY and detected with the
IsEmpty() or IsNull() functions
A parameter can only be Missing if it is untyped (declared as Optional Var2
or Optional Var2 As Variant), and will only be Missing if it is not supplied
by the calling code. To check if a parameter is missing use the IsMissing()
function.
So it sounds like the only way to know if a parameter has been passed is to
pass all parameters as variants and use IsMissing(). But I have also learned
from a thread here that it is bad form not to pass strongly type the input
parameters. On the other hand if I pass strongly type the input parameters
and a numeric parameter value, for example, is zero. I will not be able to
detect if the parameter was not passed or if VBA defaulted it.
Is there a technique I am messing?
Do I use bad form and make parameters variants?
Or do I not check?
How do you pros handle this?
Thanks