?
Solved

Default Values for Parameters in a Sub

Posted on 2004-04-15
4
Medium Priority
?
280 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
[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
  • 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 200 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

Industry Leaders: 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!

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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