array of unknown length

Results 1 to 2 of 2

Thread: array of unknown length

  1. #1
    jenny Guest

    Default array of unknown length

    how do i declare and populate an array of unknown length in vbs?

  2. #2
    Join Date
    Dec 1969

    Default RE: array of unknown length

    You mean an array you can dynamically add to, as needed?<BR><BR>You need to create a function to help you:<BR><BR>&#060;%<BR>myArrayInUse = -1 &#039 say no elements of array are in use<BR>Dim myArray( ) &#039 NOTE: no size!<BR>ReDim myArray( anyNumericalExpression ) &#039 maybe start with 100? whatever...<BR><BR>Function addElementToMyArray( element )<BR>&nbsp;&nbsp;&nbsp;&nbsp;If myArrayInUse &#062;= UBound( myArray ) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;ReDim Preserve myArray( myArrayInUse + 100 ) &#039 or + whatever is reasonable<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;myArrayInUse = myArrayInUse + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;myArray( myArrayInUse ) = Element<BR>End Function<BR><BR>%&#062;<BR><BR>If you are using VBS version 5, you could wrap all of this up in a nice CLASS (that is, a dynamic array class).<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts