Click to See Complete Forum and Search --> : Problem with optional parameter


sravanthi
September 17th, 2001, 07:31 AM
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

Cimperiali
September 17th, 2001, 08:32 AM
(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

michi
September 17th, 2001, 03:57 PM
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

Cimperiali
September 18th, 2001, 03:54 AM
Gurus next generation:
Kdev, michi, Ghost306, Clearcode, Berta,....
;-)

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

sravanthi
September 18th, 2001, 04:32 AM
Hi
Thank you for the suggestions.But my problem is still not solved.
I a familiar with both the ways.But they do not help me since I can neither declares my variables as variant nor can I give them default values.Since if I give default values also I have to check the values of all such variables in different combinations.Which would again be tedoius.I want to know if there is a way to avoid such lengthy coding?
Regards
Sravanthi

DSJ
September 18th, 2001, 04:51 PM
Have you considered making the entire parm list a single structure?

anjali_0000
September 18th, 2001, 10:48 PM
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 .