?
Solved

Default Values for Parameters in a Sub

Posted on 2004-04-15
4
Medium Priority
?
283 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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 Month16 days, 15 hours left to enroll

862 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