Solved

How Many Parameters ?

Posted on 2002-07-25
7
142 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

730 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