Help!!!!Dealing with VBscript Array~!!!!!!!!

Results 1 to 3 of 3

Thread: Help!!!!Dealing with VBscript Array~!!!!!!!!

  1. #1
    Join Date
    Dec 1969

    Default Help!!!!Dealing with VBscript Array~!!!!!!!!

    Here&#039s what i want to do:<BR>I want to declare a 2 dimenional dynamic array with no size(if possible) then would like to Redim that array to expand the row and colum when ever i want. can someone show me some code to do that?<BR><BR>

  2. #2
    Duc Guest

    Default RE: Help!!!!Dealing with VBscript Array~!!!!!!!!

    It&#039s preety simple just do it like in VB however there is a trick into it you can only redim on one demision. For example let say if you have something like this.<BR>Array(A)(B) <BR>Where A and B are the size I think you can only reside B or A, you can&#039t redim both of them so keep that in mind in your design.<BR>I hope this help. If you need more information look on the left of the sreen there is a link to VB Script reference you might want to download it.<BR>Duc

  3. #3
    Join Date
    Dec 1969

    Default This is in the ASPFAQs...

    Well, Duc has the right idea but he has scrambled the syntax some.<BR><BR>&#060;%<BR>Dim myArray( ) &#039 no sizes!<BR>...<BR>columns = 4<BR>rows = 1 + Int( Rnd * 10 ) &#039 emphasizing that this is *any* number!<BR>...<BR>ReDim myArray( columns, rows )<BR>...<BR>&#039 TADA! So far, so good. Now what happens if <BR>&#039 you want to change the size again? <BR>&#039 If you do *not* want to *keep* the data that is<BR>&#039 in the array, just do ReDim to your heart&#039s content.<BR>&#039<BR>&#039 BUT if you want to keep the data but just add more<BR>&#039 space, then you can do this:<BR>&#039<BR>ReDim Preserve myArray( columns, 2 * rows )<BR>&#039<BR>&#039 Look at that carefully: I did *NOT* change the number of "columns"!<BR>&#039 I can&#039t! VBScript will not let me use "Preserve" and also change<BR>&#039 the number of columns. I can *only* change the LAST dimension<BR>&#039 of the array.<BR>&#039<BR>&#039 NOTE: You can change an array&#039s size without "knowing" its<BR>&#039 current size, thanks to the UBound function:<BR>&#039<BR>ReDim Preserve myArray( UBound(myArray,1), 2 * UBound(myArray,2) )<BR>&#039<BR>&#039 Do you see that? UBound returns the "Upper BOUND" of the specified<BR>&#039 dimension of the array. As noted, we can&#039t change dimension 1,<BR>&#039 but we can change the last dimension (in this case, dimension 2).<BR>&#039<BR>%&#062;<BR><BR>VBScript allows three, four, five, etc., dimensional arrays. You are not limited to two dimensions. But it is still true that ReDim Preserve can *not* be used to change any dimension but the last one.<BR><BR>Hokay?<BR><BR>**************<BR><BR>Af ter typing all this, I just remembered that this is in the ASPFAQs! Click on the little "ASPFAQs" link at the top of this page, then find the "Arrays" category in the FAQs, then find this question and Scott&#039s answer. Sigh. Silly me.<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