Solved

Default Values for Parameters in a Sub

Posted on 2004-04-15
4
272 Views
Last Modified: 2010-05-02
Hello Experts!

Can't really believe i'm asking this question cos it seems so obvious, but for some reason i cant find the correct syntax!

How do i set a default for a parameter in a sub?

EG

Private Sub Example(MyVariable as Integer, MySecondVariable as Integer)

and i want to put
Example , 2

If no Parameter is entered, how would i set MyVariable to 1 for example?

At the moment i'm just getting an error saying argument not optional if i leave it blank!
Cheers in advance,

Bobeo
0
Comment
Question by:Bobeo
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10836337
Private Sub Example(MyVariable as Integer,optional  MySecondVariable as Integer = 2)
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 50 total points
ID: 10836345
or
Private Sub Example(MyVariable as Integer,optional  MySecondVariable as Integer = 1)
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10836372
Private Sub Example(Optional MyVariable As Integer = 1, Optional MySecondVariable As Integer = 1)

S

0
 
LVL 3

Author Comment

by:Bobeo
ID: 10836405
Thanks Mikal613, just what i needed!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

757 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

19 Experts available now in Live!

Get 1:1 Help Now