?
Solved

Passing null or Optional values to functions in VB6

Posted on 2005-03-28
2
Medium Priority
?
247 Views
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,
John
0
Comment
Question by:gjok
[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 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 500 total points
ID: 13642621
John:

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

Dabas
0
 
LVL 2

Author Comment

by:gjok
ID: 13642641
Many thanks, that works great!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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