GW provides DynamicArray objects as well.  One caveat on
Scripting.Dictionary objects:  If you use the .count property, be
aware that just attempting to look up an element will cause it to
exist, thus increasing the element count.  If you don't like that, use
the .exists() method to avoid referencing things that aren't there
yet.

On Tue, Dec 22, 2009 at 10:21:36PM -0500, Chip Orange wrote:

   David,



   in addition to your other good answers, there's the uBound() function,
   which will allow for you dimensioning an array differently at
   different times by always returning the upper bound of the array
   index.



   also, if you have varying numbers of elements to store, instead of
   redimensioning arrays to handle this, you could look into scripting
   dictionaries.  they are an object, you use
   createObject("scripting.dictionary"), which act something like
   arrays.  they have many advantages over arrays, including they can
   hold any number of elements, and you don't have to dimension them
   ahead of time.



   they are slower to access, so some functions which access arrays many
   thousands of times would run noticeably slower with a dictionary.
   they do however have a .count property, which will tell you how many
   elements they currently have.



   hth,



   Chip
     _________________________________________________________________

   From: David [mailto:[email protected]]
   Sent: Tuesday, December 22, 2009 4:07 AM
   To: Scripting List WE
   Subject: VBScript - how many elements in an array

   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---

-- 
Doug Lee, Senior Accessibility Programmer
SSB BART Group - Accessibility-on-Demand
mailto:[email protected]  http://www.ssbbartgroup.com
"While they were saying among themselves it cannot be done,
it was done." --Helen Keller

Reply via email to