Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine Number of elements in array?

Status
Not open for further replies.

tfayer

Technical User
Aug 4, 2002
41
US
How do I determine the number of elements in array?
 
What if the array ellements are strings. Such as using the Split Function on the string "one two thre" delimetter = " ". I want it two return the value of 3.
 
Exactly what problem are you seeing?
Did you actually try the solution given?

Using JohnYingling's solution works fine for me:
Code:
Dim myString As String
Dim myAry() As String
Dim myCount As Long
myString = "one two three"
myAry = Split(myString, " ")
myCount = UBound(myAry) - LBound(myAry) + 1
MsgBox myCount
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
It is o.k. for the trivial (single dimension).

Code:
Public Function basNumAryElem(MyAry() As Variant) As Long

    'Michael Red    11/22/02

    Dim MyProd As Double
    Dim Idx As Integer

    On Error GoTo ErrTrap

    MyProd = 1
    Idx = 1

    While True = True
        MyProd = MyProd * UBound(MyAry, Idx)
        Idx = Idx + 1
    Wend
    
ErrTrap:
    basNumAryElem = MyProd
End Function
Public Function basTestumAryElem() As Long

    Dim MyArray(2, 3, 4, 5, 6) As Variant
    basTestumAryElem = basNumAryElem(MyArray())

End Function
MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top