How to determine size of an array in a variant?

I

Ivan Starr

Hello, I have a function Parse() that I wrote in VBA years ago that parses a
string and passes back a string array in a variant.

I forget (If I ever knew) how to get the size (number of elements)
information from the variant.

Anyone know??

Thanks if you do.

Ivan


Here is the Parse routine I am using:

Public Function Parse(ParseString As String, Delim As String) As Variant
DelimLength = Len(Delim)
Rem strip off leading delims
While Mid(ParseString, 1, 1) = Delim
ParseString = Mid(ParseString, 2)
Wend
Rem strip off trailing delims
While Mid(ParseString, Len(ParseString), 1) = Delim
ParseString = Mid(ParseString, 1, Len(ParseString) - 1)
Wend

NumItems = 1
ParseStringLength = Len(ParseString)
For ctr = 1 To ParseStringLength
If Mid(ParseString, ctr, DelimLength) = Delim Then
NumItems = NumItems + 1
End If
Next ctr
NumParses = NumItems
ReDim ParseList(0 To NumParses - 1) As String
For ctr = 0 To NumParses - 1
CurrStringPos = 1
While Mid(ParseString, CurrStringPos, DelimLength) <> Delim And ctr <
NumParses - 1
CurrStringPos = CurrStringPos + 1
Wend
If ctr < NumParses - 1 Then
ParseList(ctr) = Mid(ParseString, 1, CurrStringPos - 1)
Else
ParseList(ctr) = ParseString
End If
ParseString = Mid(ParseString, CurrStringPos + 1)
Next ctr
Parse = ParseList
End Function
 
D

Douglas J. Steele

If IsNull(MyVariant) Then
intTotalElements = 0
Else
intTotalElements = UBound(MyVariant) - LBound(MyVariant) + 1
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top