473,698 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optional arguaments and IsMissing function


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 returns false.?

Am is missing something here?

Thanks,

----------------------------------------------------------------------------
----------------
Public Function myFunctionl(One As String, Two As String, Optional Three As
String) As String
Dim RiskNO As Integer
If IsMissing(Three ) Then
RiskNO = Val(One) * Val(Two)
else
RiskNO = Val(three)
End If
do something here
End function
----------------------------------------------------------------------------
--------------------
Gerry Abbott
Nov 13 '05 #1
4 6178
On Aug 07 2004, 08:26 am, "Gerry Abbott" <pl****@ask.i e> wrote in
news:DT******** **********@news .indigo.ie:

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 returns false.?

Am is missing something here?

Thanks,

-----------------------------------------------------------------------
----- ----------------
Public Function myFunctionl(One As String, Two As String, Optional
Three As String) As String

<snip>

IsMissing() function only works for optional arguments declared as Variant.
So you may want to change your function signature as

Public Function myFunctionl(One As String, Two As String, Optional
Three As Variant) As String

If the argument is declared as a string, test for its equality to
vbNullString instead of using IsMissing().

--
remove a 9 to reply by email
Nov 13 '05 #2
Thanks Dimitri,
vbNullString worked fine
I had tried Isnull(arguamen t name) but that did not work

Can someone explain whats the difference betweeen the Isnull function and
the vbnullstring test. ?

Regards,
Gerry

"Dimitri Furman" <df*****@cloud9 9.net> wrote in message
news:Xn******** *************** *****@127.0.0.1 ...
On Aug 07 2004, 08:26 am, "Gerry Abbott" <pl****@ask.i e> wrote in
news:DT******** **********@news .indigo.ie:

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 returns false.?

Am is missing something here?

Thanks,

-----------------------------------------------------------------------
----- ----------------
Public Function myFunctionl(One As String, Two As String, Optional
Three As String) As String <snip>

IsMissing() function only works for optional arguments declared as

Variant. So you may want to change your function signature as

Public Function myFunctionl(One As String, Two As String, Optional
Three As Variant) As String

If the argument is declared as a string, test for its equality to
vbNullString instead of using IsMissing().

--
remove a 9 to reply by email

Nov 13 '05 #3
The number of types of nothing in VB/VBA can be really confusing, and is tied
up with the various data types.

Null is equivalent to a Null value in a database field. Null is not equal to
anything else including Null, and most operations performed on Null with
another value result in Null - the exception being the explicit string
concatenation operator & which treats Null the same as a blank string. Null
also acts like its own data type with only one possible value, Null.

1 + Null gives Null
"A" + Null gives Null
"A" & Null gives "A"
(Null = Null) gives Null
(0 = Null) gives Null
If 0 = Null Then ... raises invalid use of Null error
If IsNull(Null) ... executes the code in the If block
IsNull(Empty) gives False
Len(Null) gives Null
Empty is the default value for a Variant variable, and is interchageable for
various other default values. Used in arithmetic, it acts as a zero. Used in
string operations, it acts as a blank string, etc. Like Null, Empty also acts
like a data type with one possible value, Empty. This is compatable with the
behavior of BASIC for an uninitialized value.

1 + Empty gives 1
"A" + Empty gives "A"
"A" & Empty gives "A"
(Empty = Empty) gives True
(0 = Empty) gives True
("" = Empty) gives True
If 0 = Empty Then ... executes the code in the If block
IsEmpty(Empty) gives True
IsEmpty(Null) gives False
Len(Empty) gives 0
vbNullString is actually a string that points to address zero, and it was
created for the purpose of passing a null string pointer to a DLL call. Folks
have discovered, though, that VB/VBA treats this as equivalent to the empty
string "", but processes it faster in some cases.

(vbNullString = "") gives True
IsNull(vbNullSt ring) gives False
IsEmpty(vbNullS tring) gives False
Len(vbNullStrin g) gives 0

One difference between vbNullString and Null is that vbNullString (or "") is a
string type. String variables can only hold string data, so a string variable
can hold these values, but it cannot hold Null or Empty because these are not
string type data.
Missing is a special value/type a Variant can have indicating that an optional
parameter was not supplied. There's very little you can to with a Missing
other than check if it is missing using IsMissing without generating an error,
however, you can assign it to another variant, and you can pass it to an
optional argument of another procedure. Since strings can contain only string
type data, they cannot have a value of Missing.
Nothing is an object reference that's not referencing any object. Since a
Variant can contain any object reference, it can contain Nothing, meaning it
has an object reference, but that reference is not to any existing object.
Any object variable (such as dbs As DAO.Database) can contain either a
reference to an object of its specific type or Nothing, meaning it has not
been initialized or it has been cleared by setting it back to Nothing.

Object references are not values, and if you try to treat them as values, VB
will try to find a default value property of the object to use as its value.
Since Nothing does not point to an object at all, it can never be treated as a
Value, but you can do pretty much anything you want with it as a refrence
including set some other Variant or object variable to its reference (which is
Nothing). The "Is" operator is used to compare 2 references to each other,
and using "Is" to compare 2 Nothing references gives True.

(Nothing Is Nothing) gives True
(Nothing = 0) raises "Invalid use of object) error
(New VBA.Collection Is Nothing) gives False
On Sat, 7 Aug 2004 19:37:15 +0100, "Gerry Abbott" <pl****@ask.i e> wrote:
Thanks Dimitri,
vbNullString worked fine
I had tried Isnull(arguamen t name) but that did not work

Can someone explain whats the difference betweeen the Isnull function and
the vbnullstring test. ?

Regards,
Gerry

"Dimitri Furman" <df*****@cloud9 9.net> wrote in message
news:Xn******* *************** ******@127.0.0. 1...
On Aug 07 2004, 08:26 am, "Gerry Abbott" <pl****@ask.i e> wrote in
news:DT******** **********@news .indigo.ie:
>
> 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 returns false.?
>
> Am is missing something here?
>
> Thanks,
>
>
>
> -----------------------------------------------------------------------
> ----- ----------------
> Public Function myFunctionl(One As String, Two As String, Optional
> Three As String) As String

<snip>

IsMissing() function only works for optional arguments declared as

Variant.
So you may want to change your function signature as

Public Function myFunctionl(One As String, Two As String, Optional
Three As Variant) As String

If the argument is declared as a string, test for its equality to
vbNullString instead of using IsMissing().

--
remove a 9 to reply by email


Nov 13 '05 #4
Many Thanks Steve,

That is an excellent description of several issues which were confusing to
me. I have printed this and pinned it to my notice board of reference
information.
Why us microsoft help not like this!
Regards,

Gerry
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
36586
by: JT | last post by:
how can i declare a function that will accept an optional parameter? something like: function newFunc(strValue1, strValue2) --where strValue2 is optional. thanks much.
4
4103
by: Darryl Kerkeslager | last post by:
Here's the function: Public Function SaveToServer(tableName As String, prefix As String, _ changed As Date, Optional recordID As Variant) As Boolean and here's the function call that doesn't work: success = SaveToServer("obligation", "obl", Me!updated, Me.txtID)
5
9501
by: (Pete Cresswell) | last post by:
I've dabbled in "Optional" over the last few days and think I'm coming down against using it. Seems to me like it makes the code harder to read and more complicated. Instead of using Optional, I'm making the parm a Variant and passing Null when it's not used.... then checking for "If Len(theParmValue & "") > 0... to see if it is present. That way I can eliminate checks for IsMissing(theParmValue)...
4
2669
by: MLH | last post by:
The following function declaration confuses me... Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean I tried pasting it and its code into an Access 2.0 module. I was unsuccessful. I had to remove the following... "Public" "Optional ByRef" "As Boolean"
13
2513
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. I've done this before with Modules, and saw that <gasp> they behave just like sealed classes with only static members. Anyway, it looks like Optional Parameters are nothing but a way to tell the compiler to write some overloads for you. So, in...
13
9408
by: John A Grandy | last post by:
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 ...
4
5943
by: Joe HM | last post by:
Hello - I realize that there is no more IsMissing function in VB.NET but how can I have a boolean argument that is optional and in the code I need to determine whether it was passed it or not? I use the Single.NaN to set the default values for some of my optional single arguments so that I can determine whether an argument was passed it ... but that does not work for booleans.
12
2665
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be avoided. I'd like to hear your various opinions on this matter.
7
7056
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1 As Integer = 0, _ Optional ByVal Arg2 As Integer = 0, _ Optional ByVal Arg3 As Integer = 0) ' Call my SQL proc with the same signature
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.