By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

substitue for vb6 IsMissing()

P: n/a
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...
Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
I think .. there is no IsMissing() in VB.NET.
Instead ... VB.NET enforces specifying of default value for optional
parameters. So you can set the optional param. default value to Nothing / -1
/ "" whatever as per the datatype and check inside the function if the value
is default / value (overrides default value) specified by the caller.
ex. -
private function ABC(Byval X as integer,Optional Byval Y as integer = -1)
.....
.....
end function

~ Kapil

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...

Nov 20 '05 #2

P: n/a
hi kapil, and thanks for the response.

i don't think you understand my post.

i specifically asked about non-reference type variables, such as Date and
Boolean. these type of variables can not be Nothing -- since they are not
reference variables it makes no sense for them to not refer to any object --
which is what Nothing means.

if i use a default value of False for an Optional Boolean type function
parameter, and then attempt to determine if the calling code supplied a
value by checking if the parameter's value is False, this leads to an
erroneous result if the calling code did supply a value , and that value =
False.

"Kapil Joshi" <ka*********@persistent.co.in> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
I think .. there is no IsMissing() in VB.NET.
Instead ... VB.NET enforces specifying of default value for optional
parameters. So you can set the optional param. default value to Nothing / -1 / "" whatever as per the datatype and check inside the function if the value is default / value (overrides default value) specified by the caller.
ex. -
private function ABC(Byval X as integer,Optional Byval Y as integer = -1)
....
....
end function

~ Kapil

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?
in vb6 we would have used the IsMissing() function ...


Nov 20 '05 #3

P: n/a
if you realy need to know if the parameter was passed or not, just create
two methods...

public sub test()
....
end sub
public sub test(value as string)
....
end sub

I suppose the 2 method will do almost the same thing, then maybe do
something like this

public sub test()
realTest("", true)
end sub
public sub test(value as string)
realTest(value, false)
end sub

private sub realTest(value as string, isDefaultString as boolean)
...
end sub

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...

Nov 20 '05 #4

P: n/a
hi dominique, and thanks for the response.

because of overloading, it appears to me that your suggestion would work.

but don't you think there's got to be a better way ?

why would the vb.net architects make it so difficult to implement this
much-used and much-needed functionality for parameters of non-reference
datatypes ?

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:e%****************@TK2MSFTNGP09.phx.gbl...
if you realy need to know if the parameter was passed or not, just create
two methods...

public sub test()
...
end sub
public sub test(value as string)
...
end sub

I suppose the 2 method will do almost the same thing, then maybe do
something like this

public sub test()
realTest("", true)
end sub
public sub test(value as string)
realTest(value, false)
end sub

private sub realTest(value as string, isDefaultString as boolean)
...
end sub

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?
in vb6 we would have used the IsMissing() function ...


Nov 20 '05 #5

P: n/a
Cor
Hi John,

I think because you cannot do MySub() when the procedure is

MySub(byval as date)

This gives an error in your IDE or compiler.

Cor

hi dominique, and thanks for the response.
because of overloading, it appears to me that your suggestion would work.
but don't you think there's got to be a better way ?

why would the vb.net architects make it so difficult to implement this
much-used and much-needed functionality for parameters of non-reference
datatypes ?

Nov 20 '05 #6

P: n/a
On 2004-01-30, John A Grandy <> wrote:
hi dominique, and thanks for the response.

because of overloading, it appears to me that your suggestion would work.

but don't you think there's got to be a better way ?
Not really...

why would the vb.net architects make it so difficult to implement this
much-used and much-needed functionality for parameters of non-reference
datatypes ?


Well, it isn't really needed in VB.NET since VB.NET forces you to give
optional parameters a default value... So, why do you care if the user
passed a value or not - your going to get one, and it should be clear to
the user what value will be passed if they don't provide a value.

Personally, I prefer to use overloads over optional parameters. The main
reason is that the value of the parameter gets compiled into the assembly
and essentially becomes part of the method contract... If you change the
default value in a future version you end up breaking old clients.

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
"He expanded his chest to make it totally clear that here
was the sort of man you only dared to cross if you had a
team of Sherpas with you. "
Nov 20 '05 #7

P: n/a
"John A Grandy" <johnagrandy-at-yahoo.com> schrieb
hi dominique, and thanks for the response.

because of overloading, it appears to me that your suggestion would
work.

but don't you think there's got to be a better way ?
IMO: No. There is overloading and you still can declare the arg as Object to
use optional args.
why would the vb.net architects make it so difficult to implement
this much-used and much-needed functionality for parameters of
non-reference datatypes ?


In VB6, IsMissing also only worked for Variants, so I don't see a change for
the worse.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8

P: n/a
* "John A Grandy" <johnagrandy-at-yahoo-dot-com> scripsit:
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?

in vb6 we would have used the IsMissing() function ...


No! 'IsMissing' worked with variants only.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9

P: n/a
<<<<
Well, it isn't really needed in VB.NET since VB.NET forces you to give
optional parameters a default value... So, why do you care if the user
passed a value or not - your going to get one, and it should be clear to
the user what value will be passed if they don't provide a value.


user? what user? why are you assuming i want this functionality in order
to process values of various UI controls ?

i'm talking about the following type of functionality ( code written
*assuming* VB.NET did not require default values for Optional parameters,
and that IsMissing() was available)

Private Sub PanelSetProperties(ByRef pPanel As Panel, Optional ByVal
pVisible As Boolean, Optional ByVal pEnabled As Boolean)

If Not pPanel Is Nothing Then

If Not IsMissing(pVisible) Then
pPanel.Visible = pVisible
End If

If Not IsMissing(pEnabled) Then
pPanel.Enabled = pEnabled
End If

End If

End Sub
extend this for more parameters/properties than just two, and this is a very
nice little sub to have because it allows me to make calls like

PanelSetProperties(,False) 'disable a panel without affecting (or even
knowing or caring about) its visible status

PanelSetProperties(True) 'make a panel visible without affecting (or even
knowing or caring about) its enabled status


Nov 20 '05 #10

P: n/a
there aren't any variants in vb.net

so i think that my analogy is valid

the point is the following:

in vb6 it was possible to write a function/sub so that a parameter of any
datatype could be declared so that it was possible to perform a check inside
the function as to whether or not a value had been specified in the calling
code. yes, i know we had to use variants, but the vartype function could be
applied to determine the underlining datatype. you are being unnecessarily
pedantic.

further, it was possible to specify multiple optional parameters so that in
the calling code any combination of parameters could be left out of the
arguments list, if desired.

if vb.net it is no longer possible to write such a function. i this
particular area, we have gone backwards in -- a practical sense.

*practical* is the key word here ... PRACTICAL ... ok???? a word that seems
to have escaped the vb.net architects. every day i have to write yards of
code to do what could be accomplished in much less code in vb6.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bv************@ID-208219.news.uni-berlin.de...
* "John A Grandy" <johnagrandy-at-yahoo-dot-com> scripsit:
for a function parameter of a non-reference datatype ... such as date or
boolean ....

how to determine if the parameter was not specified in the calling code ?
in vb6 we would have used the IsMissing() function ...


No! 'IsMissing' worked with variants only.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #11

P: n/a
John,
in vb6 it was possible to write a function/sub so that a parameter of any
datatype could be declared so that it was possible to perform a check inside the function as to whether or not a value had been specified in the calling code. Remember that all datatypes ultimately derive from Object, which means:
if vb.net it is no longer possible to write such a function. i this
particular area, we have gone backwards in -- a practical sense. In VB.NET it is most certainly possible! To declare a function that accepts
"any data type" you define the parameter as Object, if you make an Object
parameter Optional, then you need to use Nothing as the default value. To
check to see if the parameter is missing you would then check

However!!! Do you write a single function that accepts a single parameter
that you then attempt to determine the parameter type of, this is what
Overloading is for, you write individual functions that accept specific
types, and find problems at compile time, instead of possible at run time.
This way if your function only accepts x, y, and z types you write three
functions that specifically accept those types, at compile time if you try
to pass w, you will get a compile error. If you want to know the parameter
was not "passed" declare an overload that does not accept a value!
*practical* is the key word here ... PRACTICAL ... ok???? a word that seems to have escaped the vb.net architects. every day i have to write yards of
code to do what could be accomplished in much less code in vb6. In my experience once you have the "proverbial AHA!" on OOP (overloading in
this case) then you will find that VB.NET is very practical and the VB6
method was not so practical.

Hope this helps
Jay

"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl... there aren't any variants in vb.net

so i think that my analogy is valid

the point is the following:

in vb6 it was possible to write a function/sub so that a parameter of any
datatype could be declared so that it was possible to perform a check inside the function as to whether or not a value had been specified in the calling code. yes, i know we had to use variants, but the vartype function could be applied to determine the underlining datatype. you are being unnecessarily
pedantic.

further, it was possible to specify multiple optional parameters so that in the calling code any combination of parameters could be left out of the
arguments list, if desired.

if vb.net it is no longer possible to write such a function. i this
particular area, we have gone backwards in -- a practical sense.

*practical* is the key word here ... PRACTICAL ... ok???? a word that seems to have escaped the vb.net architects. every day i have to write yards of
code to do what could be accomplished in much less code in vb6.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bv************@ID-208219.news.uni-berlin.de...
* "John A Grandy" <johnagrandy-at-yahoo-dot-com> scripsit:
for a function parameter of a non-reference datatype ... such as date or boolean ....

how to determine if the parameter was not specified in the calling
code
?
in vb6 we would have used the IsMissing() function ...


No! 'IsMissing' worked with variants only.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Nov 20 '05 #12

P: n/a
"John A Grandy" <johnagrandy-at-yahoo.com> schrieb
there aren't any variants in vb.net

so i think that my analogy is valid

the point is the following:

in vb6 it was possible to write a function/sub so that a parameter of
any datatype could be declared so that it was possible to perform a
check inside the function as to whether or not a value had been
specified in the calling code. yes, i know we had to use variants,
but the vartype function could be applied to determine the
underlining datatype. you are being unnecessarily pedantic.
Right, but using "As Object" instead of "As Variant", you can do the same
now. Instead of the Variant sub type, you can now use TypeOf to check the
type, or use "Is Nothing" to check if the arg has been passed.
further, it was possible to specify multiple optional parameters so
that in the calling code any combination of parameters could be left
out of the arguments list, if desired.
Still possible:

test(1, , Me)
test(2, o2:=Me)
'...
Sub test( _
ByVal x As Integer, _
Optional ByVal o1 As Object = Nothing, _
Optional ByVal o2 As Object = Nothing)

If o1 Is Nothing Then
MsgBox("o1 is nothing")
End If

End Sub

if vb.net it is no longer possible to write such a function. i
this particular area, we have gone backwards in -- a practical
sense.

*practical* is the key word here ... PRACTICAL ... ok???? a word
that seems to have escaped the vb.net architects. every day i have
to write yards of code to do what could be accomplished in much less
code in vb6.


The only practical drawback I see is that you have to write "= Nothing" for
each optional parameter. This default value, VB6 assumed on it's own, but
that's only a little more to type in, so I don't see a big problem.
--
Armin

Nov 20 '05 #13

P: n/a
IsMissing() is no longer supported and a default value must be provided
when using the optional keyword.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.