473,387 Members | 1,453 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,387 software developers and data experts.

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 6127
On Aug 07 2004, 08:26 am, "Gerry Abbott" <pl****@ask.ie> 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(arguament 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*****@cloud99.net> wrote in message
news:Xn****************************@127.0.0.1...
On Aug 07 2004, 08:26 am, "Gerry Abbott" <pl****@ask.ie> 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(vbNullString) gives False
IsEmpty(vbNullString) gives False
Len(vbNullString) 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.ie> wrote:
Thanks Dimitri,
vbNullString worked fine
I had tried Isnull(arguament 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*****@cloud99.net> wrote in message
news:Xn****************************@127.0.0.1.. .
On Aug 07 2004, 08:26 am, "Gerry Abbott" <pl****@ask.ie> 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
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
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...
5
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,...
4
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...
13
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. ...
13
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...
4
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? ...
12
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.