Length of a variant string

J

John

Hi

I am getting an array (as a variant) from split function as below;

Dim arr
arr = Split(srcStr, ",")

How do I find the number of elements in the array?

Thanks

Regards
 
D

Dirk Goldgar

John said:
Hi

I am getting an array (as a variant) from split function as below;

Dim arr
arr = Split(srcStr, ",")

How do I find the number of elements in the array?

Thanks

Regards

Assuing you're using the default array base of 0, the number of elements
can be calculated as

UBound(arr) + 1

The lowest element subscript is LBound(arr) and the highest is
UBound(arr). Unless you've used the Option Base 1 statement,
LBound(arr) will be 0. If srcStr is a zero-length string, UBound(arr)
will be -1.
 
Top