Re: Need help in Optional keyword

Andrew Gayter <[email protected]> Thu, 25 Jul 2002 16:32:39 +0100
Newsgroups gmane.comp.windows.devel.vbcom
Message-ID <[email protected]>
In distributed applications that require marshal by value functionality
it is acceptable to use variants, when no other data type will suffice.
Before Nt4.0 sp4 we couldn't marshal udts, as the universal marshaller
didn't, at that time, understand how to marshal them. Variants are still
acceptable when also wanting to marshal complex data, as they can
contain arbitrary data in the form of single or multi-dimensional
arrays.

Variants have been removed from VB.NET, as managed languages abide by
what is called the Common Type System (CTS). As the types in .NET are
themselves derived from a common class, object, any type defined within
the CTS is inherently compatible with its base type. Because of this
fact it rendered the variant unnecessary, as the new type classes
replace the variants functionality i.e. to store different data types.
In .NET the object type can be used in the same way as a variant, for
the reasons just mentioned.

The variant has only received so much attention as it doesn't promote
strong type-checking and because it always takes up 16 bytes (if I
remember correctly) of memory no matter what it contains. As already
mentioned the object type in .NET can obviously store different types,
thus no strong type checking (and issues concerning value types and
object types known as boxing). The only obvious difference between
object and variant is the default usage of 16 bytes.

Interesting optional parameters are not actually recommended in .NET, as
the optional value gets compiled into the client side assembly. This
means if you change the optional value in the component, you have to
recompile the client. The solution here is to use overloaded methods.
One method that takes no params (or the required ones) and anther that
includes all the params etc - static binding and method forwarding takes
care of the rest.

Unfortunately, we haven't got method overloading in vb6, so my solution
would be for all VB6 applications to undergo massive migration and
porting to VB.NET and use method overloading as a solution to optional
params :-)))

A





-----Original Message-----
From: Technical discussion of VBCOM [mailto:[email protected]]
On Behalf Of Jesse Sanders
Sent: 25 July 2002 16:00
To: [email protected]
Subject: Re: [VBCOM] Need help in Optional keyword

Mark,

If your application is a single user app, where all components run on
one
machine, it wont be a big deal.  If your application is multi-user and
distributed across multiple machines, using variants is out of the
question.
  As you already know, variants are gone from .NET as well.  If your app
is
going to be distributed then I would strongly recommend that you
reconsider.
  If not, then who cares... it will never be an issue.

HTH,

Jesse


>From: Mark Burns <[email protected]>
>Reply-To: Technical discussion of VBCOM <[email protected]>
>To: [email protected]
>Subject: Re: [VBCOM] Need help in Optional keyword
>Date: Mon, 22 Jul 2002 11:58:38 -0400
>
>Jesse,
>
>I gotta go with Andrew with this one.
>Using variant optional parameters and ismissing() is the only way to
>ascertain whether the parameter was passed in or not. With your
>suggested method how would you ever be able to tell whether or not the
>vbNullString value was actually supplied in the method/function/sub
call
>or not? No how/no way to do it.
>
>Now as to how to reconcile the desire to be able to use ismissing with
>the strong desire to avoid use variants... It's one 'o those
>irresistable force/immovable object conundrums.
>
>Regards,
>- Mark
>
>
> > -----Original Message-----
> > From: Technical discussion of VBCOM
> > [mailto:[email protected]] On Behalf Of Jesse Sanders
> > Sent: Monday, July 22, 2002 10:28 AM
> > To: [email protected]
> > Subject: Re: [VBCOM] Need help in Optional keyword
> >
> >
> > Set default values for your optional parameters and check to
> > see if they are
> > still set to the default....
> >
> > i.e., byval optional strConnString as string = vbnullstring
> >
> > if strConnString = vbNullString then
> >     '-- No conn string was passed in
> > else
> >     '-  Do whatever
> > end if
> >
> > HTH,
> >
> > Jesse
> >
> >
> >
> > >From: "P. S. Manikandan" <[email protected]>
> > >Reply-To: Technical discussion of VBCOM <[email protected]>
> > >To: [email protected]
> > >Subject: [VBCOM] Need help in Optional keyword
> > >Date: Fri, 19 Jul 2002 01:16:35 -0700
> > >
> > >Hi...
> > >          I have one function with three parameters. First one is
> > >mandatory , second and third parameters are optional. Now i
> > want to find
> > >out whether value is passed for the optional parameters or
> > not...how can i
> > >do this...any suggestions..
> > >
> > >Regards
> > >Manikandan
> > >
> > >You can read messages from the VBCOM archive, unsubscribe
> > from VBCOM, or
> > >subscribe to other DevelopMentor lists at
http://discuss.develop.com.
> >
> >
> > _________________________________________________________________
> > Send and receive Hotmail on your mobile device:
http://mobile.msn.com
> >
> > You can read messages from the VBCOM archive, unsubscribe
> > from VBCOM, or
> > subscribe to other DevelopMentor lists at
http://discuss.develop.com.
> >
> >
>
>You can read messages from the VBCOM archive, unsubscribe from VBCOM,
or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

You can read messages from the VBCOM archive, unsubscribe from VBCOM, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the VBCOM archive, unsubscribe from VBCOM, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.