Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Creating and Referencing Multidimensional arrays

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,39872
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Creating and Referencing Multidimensional arrays
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Creating and Referencing Multidimensional arrays - 11/17/2006 9:42:19 AM   
  thepip3r

 

Posts: 21
Score: 0
Joined: 10/21/2006
Status: offline
I'm just confused because I'm obviously calling the code wrong but every tutorial I find makes it seem like I'm referencing the multidimensional arrays correctly so I don't knwo what I'm doing wrong.  Can anyone help me out please??


      

Attempt 1 works great which tells me that my multidimensional array is working the way I want it to be but Attempt 2 tells me:

Microsoft VBScript runtime error: Subscript out of range

...and I can't figure out why?  Any pointers?
 
 
Post #: 1
 
 RE: Creating and Referencing Multidimensional arrays - 11/17/2006 9:48:00 AM   
  dm_4ever


Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Dim aProgList(1) ' you just need to add this and i think it will work like you want it to.

aProgList(0) = "DRA, Directory and Resource Administrator, C:\Program Files\NetIQ\DRA\UserConsole.exe"
aProgList(1) = "Remedy, Action Request System - Remedy User, C:\Program Files\AR System\User\aruser.exe"
x = 0

For Each str In aProgList
   ReDim Preserve aExpProg(x)
   aExpProg(x) = Split(str,", ")
   x = x + 1
Next

' Attempt 1
For Each item In aExpProg
   WScript.Echo item(0)
   WScript.Echo item(1)
   WScript.Echo item(2)
Next

(in reply to thepip3r)
 
 
Post #: 2
 
 RE: Creating and Referencing Multidimensional arrays - 11/17/2006 9:55:42 AM   
  thepip3r

 

Posts: 21
Score: 0
Joined: 10/21/2006
Status: offline
I actually have Dim aProgList() to call a dynamic array.  That's why in my loop to create the multiple dimensions, I'm ReDimming and Preserving the array to make the array larger...

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Creating and Referencing Multidimensional arrays - 11/20/2006 1:36:00 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
From the WSH documentation:
quote:


If you use the Preserve keyword, you can resize only the last array dimension


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to thepip3r)
 
 
Post #: 4
 
 RE: Creating and Referencing Multidimensional arrays - 11/20/2006 1:47:42 AM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
In my experience dynamic arrays just aren't worth it.  Constantly Redimming an array uses more memory and is less performant than simply declaring an array with more elements than you really need (I am more than willing to be proved wrong on this point though!)

The same goes for multi-dimensional arrays really.  I've never found an over-riding reason to use Dynamic arrays other than the fact that it's "better practice".

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Creating and Referencing Multidimensional arrays - 11/20/2006 1:50:53 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
I will second ginolard's opinion and state that any time I have seen the need for multidimensional arrays, dictionaries have provided a cleaner solution.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ginolard)
 
 
Post #: 6
 
 RE: Creating and Referencing Multidimensional arrays - 11/20/2006 2:52:04 AM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Ah, dictionaries.  I cannot agree with ebgreen's statement strongly enough.

For 1 or 2 dimensional arrays, dictionaries are far far superior to standard multi-dimensional arrays.  For arrays with more than 2 dimensions just Dim them larger than you need (e.g. Dim MultiArray(1000,1000,1000)

sure, OK, there'll be some blank entries in there because you can't redim the whole array (only the last dimension) but it's a small price really.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Creating and Referencing Multidimensional arrays - 11/20/2006 3:16:37 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
I use dictionaries for any and all number of dimensions. Here is an example that creates the dictionary equivalent of a 3d array:


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ginolard)
 
 
Post #: 8
 
 RE: Creating and Referencing Multidimensional arrays - 11/20/2006 6:47:56 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Oh wow.  A dictionary WITHIN a dictionary.  That's very cool

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Creating and Referencing Multidimensional arrays - 11/21/2006 1:22:16 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Perl was my first scripting language. It is not unusual to see a hash of hashes of arrays of hashes or some similar crazy data structure.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ginolard)
 
 
Post #: 10
 
 RE: Creating and Referencing Multidimensional arrays - 11/21/2006 2:36:54 AM   
  TNO


Posts: 1397
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Quoted from the WSH documentation:

quote:


A Dictionary object is the equivalent of a PERL associative array....

...Items can be any form of data, and are stored in the array.


_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Creating and Referencing Multidimensional arrays Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts