Solved

How Many Parameters ?

Posted on 2002-07-25
7
140 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 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