dcsimg
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
Expertise: Advanced
Jul 30, 1997

WEBINAR:

On-Demand

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


More Versatile Array Parameters

You can write a single procedure that accepts any type of array as an argument by using a variant parameter. Within the procedure, address the array using the usual syntax:
 
' return the number of items
Function ItemCount(anArray As Variant) _
        As Long
ItemCount = UBound(anArray) - _
        LBound(anArray) + 1
' the first element is 
' anArray(LBound(anArray))
End Function
You can even pass a matrix with any number of dimensions; in order to understand how many dimensions, you must iterate on the UBound or LBound functions until an error occurs:
 
Function ItemCount(anArray As Variant) _

        As Long
Dim items As Long, i As Integer
On Error Resume Next
items = UBound(anArray) - _
        LBound(anArray) + 1
For i = 2 to 999
        items = items * (UBound(anArray, _
                i) - LBound(anArray, i) + 1)
        If Err Then Exit For
Next
ItemCount = items
End Function
Francesco Balena
 
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