|
-
September 17th, 2001, 07:31 AM
#1
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
-
September 17th, 2001, 08:32 AM
#2
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
September 17th, 2001, 03:57 PM
#3
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
-
September 18th, 2001, 03:54 AM
#4
You're right
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
September 18th, 2001, 04:32 AM
#5
Re: You're right
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
-
September 18th, 2001, 04:51 PM
#6
Re: Problem with optional parameter
Have you considered making the entire parm list a single structure?
-
September 18th, 2001, 10:48 PM
#7
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 .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|