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 ... 13 9273
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 ...
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 ...
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 ...
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 ...
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 ?
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. "
"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
* "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>
<<<<
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
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>
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>
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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")
...
|
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 =...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |