Problem with optional parameter
Hi Vb Experts
I have a problem,Please try to help me if you can.
I am building an activex dll interface for a third party application. In doing so I am coding for some methods which have optional parameters.In some of the methods there are more than six to seven optional parameters. So when I make calls to those methods I have to check whether a particular parameter has been passed or not and then make a call to that method accordingly. In cases where there are a large number of optional parameters it becomes too tedious to check for all the combinations(for ex.The clent may paass the 2nd and 3rd parameter and may not pass the 4th and fifth parameter or it may be the other way round).
Is there a way out in which I can avoid such lengthy coding.(Other than declaring the parameters as variant)
Regards
Sravanthi
Re: Problem with optional parameter
(If you already know I beg your pardon for loosing your time)
This is the normal way:
When you declare an optional parameter, you can check if it has been passed with the IsMissing clause
ie:
public sub mysub(optional parm1 as string, optional parm2 as integer, optional parm3 as long,...)
if not ismissing parm1 then
...
end if
if not ismissing parm2 then
....
end if
...
end sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
Re: Problem with optional parameter
IsMissing function will only work for Variant data type. As for others, like String, Integer,Long, IsMissing will never be True.
You can set a default value for each optional parameter, but I still have no more idea on how to save codings.
Regards,
Michi
Re: Problem with optional parameter
Have you considered making the entire parm list a single structure?
Re: Problem with optional parameter
No there is no way to handle the problem u have stated . Once u have Optional parameter u need to check using IsMissing() for all the case .
There is no alternative way for that .
Cos me too faced the similar problem and i had 4 parameters .