Solved

How Many Parameters ?

Posted on 2002-07-25
7
138 Views
Last Modified: 2010-05-02
I have a function with 2 optional paramters

Public Sub ShowContact(ID As Long, Optional lClientNum As Long, Optional bShowButtons As Boolean = False)


The value of lClientNum can = 0 at times

Sometimes I dont need the lClientNum parameter -

So I need a way to test and see if I have passed lClientNum as a parameter - testing for 0 wont work

Please help

DWE
0
Comment
Question by:DWE
7 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 7177008
ismissing(lClientNum)
0
 
LVL 5

Accepted Solution

by:
bob_online earned 50 total points
ID: 7177094
IsMissing works in VB6 but not vb.net.

A better approach, assuming lClientNum is always positive is

Public Sub ShowContact(ID As Long, Optional lClientNum As Long  = -1, Optional bShowButtons As Boolean = False)

If lClientNum >= 0 Then
  do it

End If

The default value for an optional parameter does NOT have to be 0.

0
 
LVL 1

Expert Comment

by:MrRoper
ID: 7177150
Hmm Bob, In vb.net you should be overloading the sub (i.e. writing to versions, one with one parameter and one with two) and therefore do not need to use optional parameters

Use ismissing for vb6
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DWE
ID: 7177169
Thanks guys

Have a great evening

DWE
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 7177171
As bop_online said - use a different value for your default and then test for that value to indicate if the entry is there.

IsMissing will NOT work given your sub declaration, because IsMissing will only work on variant arguments, so you could use:

Public Sub ShowContact(ID As Long, Optional lClientNum As Variant, Optional bShowButtons As Boolean = False)

  If IsMissing(lClientNum) ...


But then you'd have to cast lClientNum to actually use (which may not be a problem), eg:

  If val(lClientNum) = 0 then...




The third (least useful) option is to add another argument which says whether or not to use lClientNum, eg:

Public Sub ShowContact(ID As Long, Optional bUseClientNum as Optional = False, Optional lClientNum As Long, Optional bShowButtons As Boolean = False)

   If bUseClientNum then
      doit



0
 

Author Comment

by:DWE
ID: 7177177
thanks for the additional information - it is appreciated

DWE
0
 
LVL 5

Expert Comment

by:bob_online
ID: 7177452
You're right, IsMissing only works with variants -- I han't had enough coffee yet this morning...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now