Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Passing null or Optional values to functions in VB6

Posted on 2005-03-28
Medium Priority
Last Modified: 2008-03-03
I have written a DLL function that takes 11 parameters, However all eleven parameters may not allways be needed.
How can I call my function in a way that I dont have to specify emtpy strings. ie like this:

     X = myFunction(Val1, Val2, Val3, , , , , , , Val10, Val11)

Currently I have to do this :

     X = myFunction(Val1, Val2, Val3, "", "", 0, 0, "", 0, Val10, Val11)

MSDN says:
An argument can only be omitted from a call to a user-defined procedure if it was declared Optional in the procedure declaration. Either supply the argument in the call or declare the parameter Optional in the definition.

I have tried:
Optional Val1 As String
Val1 As Optional String
Val1 As String Optional, etc

Please advise,
Question by:gjok
LVL 27

Accepted Solution

Dabas earned 500 total points
ID: 13642621

True, you can declare a parameter as optional, but once you have done so, all parameters AFTER that one must also be declared optional. If you want ALL parameters to be optional then your declarion should be:

Public Function myFunction(Optinal Val1 as String, Optional Val2 as String, Optional Val3 as String.... Optional Val11 as String) as Whatever


Author Comment

ID: 13642641
Many thanks, that works great!

Featured Post

Technology Partners: 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

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

580 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