Hi David,
the short answer is no. Just write a function to count the elements and
return that value every time you need it. The long answer is there's a
difference between declaring an array and using the Array function as you
did in your example code.
dim XArray: Array( 1,2,3,4,5 )
That statement is going to throw an error because you're doing two different
things; declaring a variable named XArray with the Dim statement, then using
the Array function inappropriately.
A standard array declaration defines the scope of the array. For example:
Dim xArray(10)
creates an array with 11 elements because arrays are 0 based.
You can also declare a dynamic array with: Dim xArray() but this can't be
used until you declare its size with the Redim statement, e.g. Redim
xArray(100)
The Array statement is essentially the same thing only different. It
predefines an array and assigns that aray to a variable. Therefore it's used
in the following manner.
Dim digits
digits = Array(0,1,2,3,4,5,6,7,8,9)
these digits would then be access in the same manner as an array, e.g. x =
digits(1) where x would equal one.
Hth,
Tom
----- Original Message -----
From: "David" <[email protected]>
Hi, listers!
In VBS, when having an array, that might hold different amounts of elements:
Is there an easy way to tell how many elements the array holds, at any time.
With strings, for instance, we have the Len function, so as to tell how many
characters the string holds. Just wondering, if there is something similar
for arrays?
The other way around, is of course, the following example code; but I find
that is to envent the wheel every time.
---sample starts---
dim XArray: Array( 1,2,3,4,5 )
dim I, Number
Number = 0
For Each I In XArray
Number = Number + 1
Next
MsgBox "Array holds " & Number & " elements."
---sample ends---
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4707 (20091221) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com