Solved

How Many Parameters ?

Posted on 2002-07-25
7
137 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

759 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

21 Experts available now in Live!

Get 1:1 Help Now