Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


4 Dimensional Array

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> 4 Dimensional Array
  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 >>
 4 Dimensional Array - 7/20/2007 12:01:33 AM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
Its dumb but Its not working.
SO I declare my 4D array
Dim arr(13,13,13,13)
set values
arr(1,1,1,1)=("ST05V01","E:","N:","0:")
or
arr(2,2,2,2)=("ST05V02", "F:","K:","")

Dosent Work.. :(

Anyone can help....

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net
 
 
Post #: 1
 
 RE: 4 Dimensional Array - 7/20/2007 12:19:03 AM   
  ehvbs

 

Posts: 2199
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi 4scriptmoni,

arr(1,1,1,1) references a single cell in your Array, so you must assign
a single value:

  arr(1,1,1,1) = "ST05V01"
  arr(1,1,1,2) = "E:"

(in reply to 4scriptmoni)
 
 
Post #: 2
 
 RE: 4 Dimensional Array - 7/20/2007 5:52:10 AM   
  Skie

 

Posts: 58
Score: 0
Joined: 3/2/2006
Status: offline
Do you really need a 4D array (over 28,000 items)?  I realize you only provided a short example, but it looks like a 2D arary would work.
Dim Arr(13,4)
Arr(1,1) = "ST05V01"
Arr(1,2) = "E:"
Arr(1,3) = "N:"
Arr(1.4) = "0:"
Arr(2,1) = "ST05V02"
Arr(2,2) = "F:"
Arr(2,3) = "K:"
Arr(3,1) = ...

(in reply to 4scriptmoni)
 
 
Post #: 3
 
 RE: 4 Dimensional Array - 7/20/2007 6:18:50 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
Or better yet in my opinion, a dictionary:

Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
oDic.Add "ST05V01", Split("E:-N-O:", "-")
oDic.Add "ST05V02", Split("F:-K:-", "-")

_____________________________

"... 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 Skie)
 
 
Post #: 4
 
 RE: 4 Dimensional Array - 7/20/2007 7:07:39 AM   
  Skie

 

Posts: 58
Score: 0
Joined: 3/2/2006
Status: offline
Yeah, dictionary also works if it doesn't actually need a 4D array.  I know split works or using an actual array, but can you use Array when adding a dictionary item?
Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
oDic.Add "ST05V01", Array("E:","N:","O:")
oDic.Add "ST05V02", Array("F:","K:")

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: 4 Dimensional Array - 7/20/2007 7:16:27 AM   
  ehvbs

 

Posts: 2199
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi ebgreen,

why use a dictionary in this case? The lack of features of VBScript Arrays may justify
the use of a dictionary given special circumstances. But as a rule of thumb: Use a
dictionary if and only if

(a) you want to access elements by alphabetical key instead of numerical index

(b) you are willing to pay the price:

       (1) keys must be unique (no second "ST05V01" possible)

       (2) arrays as values in a dictionary are accessed ByVal/Copy; you
             can't change their elements directly

That's why I'd advise 4scriptmoni to stick to his array.

Regards

ehvbs

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: 4 Dimensional Array - 7/20/2007 7:22:35 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
You are correct about the limitations of using dictionaries. Although I'm not sure about (b)-(2). I'll need to do some testing.

_____________________________

"... 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 ehvbs)
 
 
Post #: 7
 
 RE: 4 Dimensional Array - 7/20/2007 7:28:12 AM   
  ehvbs

 

Posts: 2199
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
code


      

output


      

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: 4 Dimensional Array - 7/20/2007 7:36:42 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
The workaround is to change the entire array. Granted not very efficient for a large array, but not terrible for a small one:


      

Output:

      

_____________________________

"... 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 ehvbs)
 
 
Post #: 9
 
 RE: 4 Dimensional Array - 7/20/2007 8:33:05 AM   
  ehvbs

 

Posts: 2199
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi ebgreen,

while

  " The workaround is to change the entire array. Granted not very efficient for a large
    array, but not terrible for a small one"

is technically correct, it should be added that the necessity for the workaround isn't
obvious (ragged arrays/arrays of arrays don't cause the problem) and it's easy to
forget to apply it. Most important - in my opinion - is the fact that you don't gain
anything by using dictionaries in this context (ok - as I understand the context).

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: 4 Dimensional Array - 7/22/2007 7:10:44 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
Hi guys, thanks so much for all the answers.
I like the idea about the dictonary, although I have to confess I never have used it before..
Basicly what I need are pair or more of value ex:
ST05V01, E,N,O
ST05V02,F,K
So my function would run in that server but only in those disks.
At the moment I do have a 2D array but the for loop is ugly.
Anyways, can I do such with this code:

      
How can I do a for loop to go once in that server with disk e, and again disk N, O... ?
Now I have:


      







_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: 4 Dimensional Array - 7/23/2007 5:07:20 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
Ehvbs, to be honest with you, the requirement for using a dictionary is all in my brain. I just think better in those terms and was simply presenting it as an alternative for people who have the misfortune to think like I do.  

_____________________________

"... 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 4scriptmoni)
 
 
Post #: 12
 
 RE: 4 Dimensional Array - 7/23/2007 5:56:51 AM   
  Skie

 

Posts: 58
Score: 0
Joined: 3/2/2006
Status: offline
You're treating it as two arrays rather than two-dimensional array.

      

If you want to check every drive on every server, you'd be better off with two one-dimensional arrays.

      

If you want to check select drives on each server, then you should use a two-dimensional array.

      

(in reply to 4scriptmoni)
 
 
Post #: 13
 
 RE: 4 Dimensional Array - 7/23/2007 6:30:36 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
The answer was given in one of the examples previously. I added it using your script supplied to give you the following:


      


I woud not have done it this way though. I think that it would be simpler to have the list in a file and read it. The values would be seperated by a comma and each server on a seperate line. This would be an example:


      


The text file would be similar to the following:

server1,e:,f:
server2,c:
server3,e:,m:,g:,u:,c:
server4,c:,y:



< Message edited by CondoPC -- 7/25/2007 12:20:07 AM >

(in reply to ebgreen)
 
 
Post #: 14
 
 RE: 4 Dimensional Array - 7/23/2007 7:24:39 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
Thanks CondoPC and everyone else.
Before my script was taking about 290 seconds now it only takes about 30 seconds.
I should have thought about a text file.
I am posting the complete script here http://www.visualbasicscript.com/m_49860/tm.htm
cheers,

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to CondoPC)
 
 
Post #: 15
 
 RE: 4 Dimensional Array - 7/24/2007 4:01:35 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
combining a dictionary with an array as elements also works well

ive used that on quite a few scripts where i need to store complex data but want it fast and without a lot of fuss

ar(0,0,0,1) = "fugly"

aint no way im going there...

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to 4scriptmoni)
 
 
Post #: 16
 
 
 
  

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 >> 4 Dimensional Array 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