Solved

How Many Parameters ?

Posted on 2002-07-25
7
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

688 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