Login | |
|
 |
RE: multidimensional arrays - 1/11/2006 10:53:27 AM
|
|
 |
|
| |
ziminski
Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
|
I have used it like this, not sure if it is what you're after tho, Sub outputArray() WScript.Echo "************ detailed output **************" WScript.echo "machine,src file and date,missing,extra,different(Date)" ' For j = 0 To UBound(outArray) ' WScript.echo outArray(0,j) & "," & outArray(1,j)& "," & outArray(2,j) _ ' & "," & outArray(3,j)& "," & outArray(4,j) ' Next ' For I = LBound(outArray,1) To UBound(outArray,1) For J = LBound(outArray,2) To UBound(outArray,2) ' Peroform action with data in outArray(I,J) 'outArray(I,J) = I * J WScript.echo I & vbcrlf & J & vbcrlf & outArray(I,J) Next Next End Sub 'outputArray
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/11/2006 12:00:50 PM
|
|
 |
|
| |
ziminski
Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
|
or maybe this is closer to what you want Sub outputArray() WScript.Echo "************ detailed output **************" WScript.echo "machine,src file and date,missing,extra,different(Date)" WScript.Echo UBound(outArray,1) WScript.Echo LBound(outArray,1) ' For j = 0 To UBound(outArray) ' WScript.echo outArray(0,j) & "," & outArray(1,j)& "," & outArray(2,j) _ ' & "," & outArray(3,j)& "," & outArray(4,j) ' Next ' For j = 0 To UBound(outArray,1) For k = 0 To UBound(outArray, 2) WScript.echo j & " - " & k Next Next End Sub 'outputArray
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/11/2006 12:54:01 PM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
Regarding your first example, I comented out the output section and just tried to echo different layers of the array with no luck. I input this into the array: add2Array "user0","success0","failure0","logdate0","ipaddy0" add2Array "user1","success1","failure1","logdate1","ipaddy1" add2Array "user2","success2","failure2","logdate2","ipaddy2" add2Array "user3","success3","failure3","logdate3","ipaddy3" add2Array "user4","success4","failure4","logdate4","ipaddy4" add2Array "user5","success5","failure5","logdate5","ipaddy5" add2Array "user6","success6","failure6","logdate6","ipaddy6" The output for this: WScript.echo outArray(0,0) & "," & outArray(1,0)& "," & outArray(2,0) & "," & outArray(3,0)& "," & outArray(4,0) Was this: user6,success6,failure6,logdate6,ipaddy6 Looks like you only have one multidemensional element in the array. The output for this: WScript.echo outArray(0,1) & "," & outArray(1,1)& "," & outArray(2,1) & "," & outArray(3,1)& "," & outArray(4,1) was this: ,,,, Not enough time to really look into but I thonk you have issues in your add2array sub. Sorry I couldn't be more of a help. I think you were asking about this; UBound(outArray,2) will return the size of the second dimension. Test this: arraySize = UBound(outArray, 2) WScript.Echo arraySize Good luck. Cybex
< Message edited by Cybex -- 1/11/2006 1:42:33 PM >
_____________________________
Common sense is not so common.
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 1:47:05 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
perhaps im missing the whole point of multidimensional arrays. here is what im trying to do, i need to store some data (about 1000 lines) then output them all at the end of the script the data is basically like the data i'm inputting in my script when you create the array its basically Array(r,c) where r = row and c = column, is this correct?
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:02:37 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
i am unable to get it to work by incrementing the first number of the array eg, Array(i,5) rather than Array(5,i) i keep getting subscript out of range. code: ReDim Preserve outArray(0, 5) Dim arrcount add2Array "user0","success0","failure0","logdate0","ipaddy0" add2Array "user1","success1","failure1","logdate1","ipaddy1" add2Array "user2","success2","failure2","logdate2","ipaddy2" add2Array "user3","success3","failure3","logdate3","ipaddy3" add2Array "user4","success4","failure4","logdate4","ipaddy4" add2Array "user5","success5","failure5","logdate5","ipaddy5" add2Array "user6","success6","failure6","logdate6","ipaddy6" outputArray() Sub add2Array(user,success,failure,logdate,ipaddy) WScript.Echo "adding user with arrcount " & arrcount ReDim Preserve outArray(arrcount, 5) For i = 0 To 4 WScript.Echo i outArray(arrcount,i) = user outArray(arrcount,i) = success outArray(arrcount,i) = failure outArray(arrcount,i) = logdate outArray(arrcount,i) = ipaddy Next arrcount = arrcount + 1 End Sub 'add2Array sub outputArray() WScript.Echo "starting output" For j = 0 To arrcount - 1 For i = 0 To 5 WScript.Echo "outarray("& j & "," & i &")" WScript.Echo outarray(j,i) Next Next End Sub
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:06:58 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
more simple test of that idea, ReDim Preserve outArray(0, 5) ReDim Preserve outArray(1, 5) ReDim Preserve outArray(2, 5) dynamic_array.vbs(71, 1) Microsoft VBScript runtime error: Subscript out of range when i do this, ReDim Preserve outArray(5, 0) ReDim Preserve outArray(5, 1) ReDim Preserve outArray(5, 2) it works fine. i think that is how i figured it out last time but it seems to me that you are incrementing the columns rather than the rows like a spreadsheet or database
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:18:55 AM
|
|
 |
|
| |
ginolard
Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
|
Is it only a 2-dimensional array? If so, use the Dictionary object, it's MUCH better.
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:29:17 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
i tried that, i cant use a dictionary because the key isnt always unique. i just had a thought tho, what if i generate my own key like incremented numbers, and just insert the whole string as the item i think that might work, and be much easier to use! ill give it a go and see if it will fill my needs, thanks!
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:39:00 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
i shoulda done that a LONG time ago! much cleaner and faster... Set objDictionary = CreateObject("Scripting.Dictionary") dim dictcount dimcount = 1 add2dict "user0,success0,failure0,logdate0,ipaddy0" add2dict "user1,success1,failure1,logdate1,ipaddy1" add2dict "user2,success2,failure2,logdate2,ipaddy2" add2dict "user3,success3,failure3,logdate3,ipaddy3" add2dict "user4,success4,failure4,logdate4,ipaddy4" add2dict "user5,success5,failure5,logdate5,ipaddy5" add2dict "user6,success6,failure6,logdate6,ipaddy6" Sub add2dict(item) objDictionary.Add dictcount, item dictcount = dictcount + 1 End Sub For Each obj In objDictionary WScript.Echo "The key is: " & obj & " and the associated data is: " & objDictionary(obj) Next
< Message edited by kirrilian -- 1/12/2006 2:44:09 AM >
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:43:02 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
i agree but that array problem still bothers me...
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:49:15 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
If I understand your problem then it is a known issue. From the WSH docs: quote:
If you use the Preserve keyword, you can resize only the last array dimension, and you can't change the number of dimensions at all.
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 2:54:38 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
AH HA! so thats why its all weirded out then. figgers. so was i correct in my assumption about what the numbers [array(0,0)] mean? when you create the array its basically Array(r,c) where r = row and c = column, is this correct?
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 3:01:03 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
You can think of it that way, but that analogy will fall apart if you go over 4 dimensions. It also doesn't work for jagged arrays (i.e. multi-dimensional arrays where the size of the second dimension varies)
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 3:07:27 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
If you really want to do it, there is a way to get around the prohibition of Redim Preserving the first dimension of the array. It is very clunky and I would never do it in production code, but I can post it if you would like.
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/12/2006 3:27:20 PM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
that analogy falls apart if you go over 2 dimensions lol i agree on the jaggedness, thats where i was getting hung up when i couldve just used a dictionary the whole time, sheesh! 3d gives (x, y, z), im not even sure how to represent a 4d array! nah if i need it someday (which i doubt i would in vbs) ill let you know
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/13/2006 3:08:51 AM
|
|
 |
|
| |
ginolard
Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
|
Oh yes, I should've told you that ;) I had a similar problem a while ago and resorted to using a Dictionary in the end. It's a big limitation of VBscript IMHO. I think Javascript can do it.
|
|
| |
|
|
|
 |
RE: multidimensional arrays - 1/13/2006 5:56:44 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
ebgreen: so technically the 4th dimension is the integral of the 3rd, mathmatically speaking that is interesting, i never looked at it that way but it makes sense. thanks ginolard: that woulda helped lol i dont even remember why i was trying to use a dynamic multidimensional array to begin with!
_____________________________
Have you searched here ? VBScript Fundamentals My Site
|
|
| |
|
|
|
|
|