dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic Classic (6 and earlier)
Expertise: Intermediate
Sep 27, 2016

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Passing the Missing Function Value

Ever needed to pass or not pass a value to a sub (or function) having an optional argument depending on the business rules?
I mean something like this:

Function MyFunction(ByVal SomeArg As Integer) As String
    If SomeArg  0 Then
        MyFunction = NotMyFunction(SomeArg) 'OK, we can pass SomeArg
    Else
        MyFunction = NotMyFunction 'We cannot pass it. NotMyFunction will got it missing.
    End If
End Function

Instead of repeating the call to such a function or sub, you can pass it a true missing value using the function below:

Public Function Missing(Optional PlaceHolder As Variant) As Variant
    Missing = PlaceHolder
End Function

Our example would change to something like this:

Function MyFunction(ByVal SomeArg As Integer) As Integer
Dim Arg As Variant
    If SomeArg  0 Then Arg = SomeArg Else Arg = Missing
    MyFunction = NotMyFunction(Arg)
End Function

Oracy
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date