Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Hi,
I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? Thank you, Robert Stober |
#2
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Perhaps you could clarify what "enumerate the whole thing" means?
Alan Beban Robert Stober wrote: Hi, I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? Thank you, Robert Stober |
#3
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Alan,
I want to print out every defined value in the array. For instance if this were a standard (one-deminsional) array, I could write: Sub PrintArray() Dim fruits As Variant Dim i As Integer fruits = Array("grapes", "pineapples", "kiwi") For i = LBound(fruits) To UBound(fruits) Debug.Print fruits(i) Next i End Sub But my array isn't one deminsional, and I don't quite understand how my data is being put into the array. There's a second argument to LBound and UBound that I don't quite understand yet, so I want to print the contents of my array so I can see how my data is organized. Does that clear it up? Thank you, Robert "Alan Beban" wrote in message ... Perhaps you could clarify what "enumerate the whole thing" means? Alan Beban Robert Stober wrote: Hi, I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? Thank you, Robert Stober |
#4
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Well, sorta'. You say it's multi-dimensional and not one-dimensional; is
it two-dimensional? Three-dimensional? Is it a secret? If it's two-dimensional, For i = LBound(fruits,1) to UBound(fruits,1) For j=LBound(fruits,2) to UBound(fruits,2) Debug.Print i,j,fruits(i,j) Next j Next i If it's three-dimensional, For i = LBound(fruits,1) to UBound(fruits,1) For j=LBound(fruits,2) to UBound(fruits,2) For k=LBound(fruits,3) to UBound(fruits,3) Debug.Print i,j,k,fruits(i,j,k) Next k Next j Next i etc. Alan Beban Robert Stober wrote: Alan, I want to print out every defined value in the array. For instance if this were a standard (one-deminsional) array, I could write: Sub PrintArray() Dim fruits As Variant Dim i As Integer fruits = Array("grapes", "pineapples", "kiwi") For i = LBound(fruits) To UBound(fruits) Debug.Print fruits(i) Next i End Sub But my array isn't one deminsional, and I don't quite understand how my data is being put into the array. There's a second argument to LBound and UBound that I don't quite understand yet, so I want to print the contents of my array so I can see how my data is organized. Does that clear it up? Thank you, Robert "Alan Beban" wrote in message ... Perhaps you could clarify what "enumerate the whole thing" means? Alan Beban Robert Stober wrote: Hi, I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? Thank you, Robert Stober |
#5
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Alan,
Thank you. I also figured it out. Here's what I came up with (sorry about the double spaces): Dim j As Integer Dim k As Integer For j = LBound(locationNames, 1) To UBound(locationNames, 1) For k = LBound(locationNames, 2) To UBound(locationNames, 2) Sheets("Contents").Range("F3").Cells(j, k).Value = locationNames(j, k) Next k Next j Thank you for answering my question. Robert "Alan Beban" wrote in message ... Well, sorta'. You say it's multi-dimensional and not one-dimensional; is it two-dimensional? Three-dimensional? Is it a secret? If it's two-dimensional, For i = LBound(fruits,1) to UBound(fruits,1) For j=LBound(fruits,2) to UBound(fruits,2) Debug.Print i,j,fruits(i,j) Next j Next i If it's three-dimensional, For i = LBound(fruits,1) to UBound(fruits,1) For j=LBound(fruits,2) to UBound(fruits,2) For k=LBound(fruits,3) to UBound(fruits,3) Debug.Print i,j,k,fruits(i,j,k) Next k Next j Next i etc. Alan Beban Robert Stober wrote: Alan, I want to print out every defined value in the array. For instance if this were a standard (one-deminsional) array, I could write: Sub PrintArray() Dim fruits As Variant Dim i As Integer fruits = Array("grapes", "pineapples", "kiwi") For i = LBound(fruits) To UBound(fruits) Debug.Print fruits(i) Next i End Sub But my array isn't one deminsional, and I don't quite understand how my data is being put into the array. There's a second argument to LBound and UBound that I don't quite understand yet, so I want to print the contents of my array so I can see how my data is organized. Does that clear it up? Thank you, Robert "Alan Beban" wrote in message ... Perhaps you could clarify what "enumerate the whole thing" means? Alan Beban Robert Stober wrote: Hi, I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? Thank you, Robert Stober |
#6
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Rather than looping, consider
Sheets("Contents").Range("F3").Resize(UBound(locat ionNames,1),_ UBound(locationNames,2)).Value = locationNames Alan Beban Robert Stober wrote: Alan, Thank you. I also figured it out. Here's what I came up with (sorry about the double spaces): Dim j As Integer Dim k As Integer For j = LBound(locationNames, 1) To UBound(locationNames, 1) For k = LBound(locationNames, 2) To UBound(locationNames, 2) Sheets("Contents").Range("F3").Cells(j, k).Value = locationNames(j, k) Next k Next j Thank you for answering my question. Robert "Alan Beban" wrote in message ... Well, sorta'. You say it's multi-dimensional and not one-dimensional; is it two-dimensional? Three-dimensional? Is it a secret? If it's two-dimensional, For i = LBound(fruits,1) to UBound(fruits,1) For j=LBound(fruits,2) to UBound(fruits,2) Debug.Print i,j,fruits(i,j) Next j Next i If it's three-dimensional, For i = LBound(fruits,1) to UBound(fruits,1) For j=LBound(fruits,2) to UBound(fruits,2) For k=LBound(fruits,3) to UBound(fruits,3) Debug.Print i,j,k,fruits(i,j,k) Next k Next j Next i etc. Alan Beban Robert Stober wrote: Alan, I want to print out every defined value in the array. For instance if this were a standard (one-deminsional) array, I could write: Sub PrintArray() Dim fruits As Variant Dim i As Integer fruits = Array("grapes", "pineapples", "kiwi") For i = LBound(fruits) To UBound(fruits) Debug.Print fruits(i) Next i End Sub But my array isn't one deminsional, and I don't quite understand how my data is being put into the array. There's a second argument to LBound and UBound that I don't quite understand yet, so I want to print the contents of my array so I can see how my data is organized. Does that clear it up? Thank you, Robert "Alan Beban" wrote in message ... Perhaps you could clarify what "enumerate the whole thing" means? Alan Beban Robert Stober wrote: Hi, I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? Thank you, Robert Stober |
#7
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Robert Stober wrote:
Hi, I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? where arr is a 2-D array... for j = 0 to ubound(arr,2) for i = 0 to ubound(arr,1) wscript.echo arr(i,j) next next where arr is a 3-D array... for k = 0 to ubound(arr,3) for j = 0 to ubound(arr,2) for i = 0 to ubound(arr,1) wscript.echo arr(i,j,k) next next next -- Michael Harris Microsoft.MVP.Scripting Windows 2000 Scripting Guide Microsoft® Windows®2000 Scripting Guide http://www.microsoft.com/technet/scr...s_overview.asp System Administration Scripting Guide - samples scripts http://www.microsoft.com/downloads/r...eleaseID=38942 WSH 5.6 documentation download http://www.microsoft.com/downloads/d...displaylang=en |
#8
![]()
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
|
|||
|
|||
![]()
Robert Stober wrote:
I've built a multi-dimensional array from a table and would like to enumerate the whole thing, but I'm confused. Can anyone help me out? For Each elm In ary WScript.echo elm Next Apparently, VBScript stores arrays in column-major order, so this will produce: ary(0, 0, 0, ...) ary(1, 0, 0, ...) ary(2, 0, 0, ...) ... ary(n, 1, 0, ...) ary(n, 2, 0, ...) ... etc. But it's the simplest, most general way. -- Steve The believer is happy; the doubter is wise. -Hungarian proverb |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
newbie question on multi-dimensional array | New Users to Excel | |||
Problem with Multi-Dimensional Array | Excel Programming | |||
How to declare Multi-dimensional dynamic array? | Excel Programming | |||
Declaring Dynamic Multi-dimensional Array | Excel Programming | |||
sort multi-dimensional array on numeric data? | Excel Programming |