devxlogo

More Versatile Array Parameters

More Versatile Array Parameters

You can write a single procedure that accepts any type of array as an argument by using a variantparameter. Within the procedure, address the array using the usual syntax:

 ' return the number of itemsFunction ItemCount(anArray As Variant) _        As LongItemCount = 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 LongDim items As Long, i As IntegerOn Error Resume Nextitems = UBound(anArray) - _        LBound(anArray) + 1For i = 2 to 999        items = items * (UBound(anArray, _                i) - LBound(anArray, i) + 1)        If Err Then Exit ForNextItemCount = itemsEnd Function
See also  Redefining Energy Management: Advanced Solutions for Modern Buildings
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist