473,378 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

substitue for vb6 IsMissing()

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
13 9357
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
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
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
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
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
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
"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
* "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
<<<<
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GujuBoy | last post by:
I am trying to transfer some code from PYTHON to C++. What is the best substitute for a LIST and TUPLE in C++. please advice.
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
4
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy...
6
by: E Pease | last post by:
I have been trying to edit the Explorer example by Dev Ashish I found on www.msvp.org (I think). I have been all over the net so I am not quite sure where the file came from. I like the way it...
6
by: henk | last post by:
Hi, I want to show a message in my vb.net program when another windows program (eg calc.exe) is stopped by a user. with pList = myProcess.GetProcesses For Each myProcess In pList I can check...
17
by: Lauren Wilson | last post by:
Does anyone know if it is possible to capture FTP responses to various FTP commands when managing an FTP session from a VBA procedure? For example, if we try to login to an FTP server and the...
4
by: briancfk | last post by:
I now converting vb6 code to vb.net code Let me descrip my problem first i got a Function e.g. Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As String, Optional ByVal...
1
by: baskarpr | last post by:
Hi. Can anyone tell the purpose/meaning of ":=" which is used in VBA ? It sounds like a smiley, lol. Example : ActiveWorkbook.Sheets("Sheet1").Copy after:=ActiveWorkbook.Sheets ("Sheet1") ...
1
by: staeri | last post by:
When loading a FormView I try to fill a third-party combo control with this code: Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As EventArgs) If FormView1.Row.RowState =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.