Array of Arrays

Array of Arrays

Anonymous
Not applicable
300 Views
9 Replies
Message 1 of 10

Array of Arrays

Anonymous
Not applicable
Group,

I've created a one-dimensional array of two-dimensional arrays. I can see
the 2D arrays within the outer array, but I can't seem to dig out the second
dimension information. The 2D array looks like this:

DetailArray(0,0) = "Object name:"
DetailArray(0,1) = strObjName
DetailArray(1,0) = "Object ID:"
DetailArray(1,1) = intObjID

Then I assign this 2D array to the first element of a one-dimensional array
like this:

DetailsArray(0) = DetailArray

While watching the two arrays, I can see the information in the 2D array. I
can also see it in the one-dimensional array. It looks like this:

DetailsArray(0)(0)

Under that, I see the 2D array, but I cannot dig out the second dimension
for display. I assign the array to a list box with this:

lstDetails = DetailsArray(0)

but I only get the hard-coded strings, not the information contained in the
variables. I tried:

lstDetails = DetailsArray(0)(0)

because that is what the watch window shows, but that produces an out of
subscript range error. Does anyone know how to get the second dimension out
of the embedded array? Thanks.

--
Eugene N. Kilmer
Owner/Mag Drafting
0 Likes
301 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Eugene,

The statement
lstDetails = DetailsArray(0)(0)

should be
lstdetails = DetailsArray(0) (X, X)

X being the appropriate index you want.

Joe Sutphin
Author of "AutoCAD 2000 VBA Programmers Reference"
ISBN #1861002564 Order it at
http://www.amazon.com/exec/obidos/ASIN/1861002564/o/qid%3D942504788/sr%3D8-1
/002-7788324-2908264

Checkout Sources - the only magazine dedicated to AutoCAD customization
http://vbdesign.hypermart.net/sources/

Eugene N. Kilmer wrote in message
news:858l5q$mt616@adesknews2.autodesk.com...
> Group,
>
> I've created a one-dimensional array of two-dimensional arrays. I can see
> the 2D arrays within the outer array, but I can't seem to dig out the
second
> dimension information. The 2D array looks like this:
>
> DetailArray(0,0) = "Object name:"
> DetailArray(0,1) = strObjName
> DetailArray(1,0) = "Object ID:"
> DetailArray(1,1) = intObjID
>
> Then I assign this 2D array to the first element of a one-dimensional
array
> like this:
>
> DetailsArray(0) = DetailArray
>
> While watching the two arrays, I can see the information in the 2D array.
I
> can also see it in the one-dimensional array. It looks like this:
>
> DetailsArray(0)(0)
>
> Under that, I see the 2D array, but I cannot dig out the second dimension
> for display. I assign the array to a list box with this:
>
> lstDetails = DetailsArray(0)
>
> but I only get the hard-coded strings, not the information contained in
the
> variables. I tried:
>
> lstDetails = DetailsArray(0)(0)
>
> because that is what the watch window shows, but that produces an out of
> subscript range error. Does anyone know how to get the second dimension
out
> of the embedded array? Thanks.
>
> --
> Eugene N. Kilmer
> Owner/Mag Drafting
>
0 Likes
Message 3 of 10

Anonymous
Not applicable
Mr. Sutphin,

That will get me the one element of the 2D array, but what I wanted to do
was load a list box with the whole array. If I were trying to do that with
DetailArray, I would do it like this:

lstDetails.list = DetailArray

correct? If DetailArray is a 2D array that is the first element of the
one-dimensional array DetailsArray, I can't dump its entire contents into a
list box? Do I have to pull out each element separately and perhaps make
yet another array I can load into the list box?

--
Eugene N. Kilmer
Owner/Mag Drafting
0 Likes
Message 4 of 10

Anonymous
Not applicable
It appears you are attempting to place object names and their corresponding
ObjectIDs into a listbox. If so, skip the one-dimensional array part. If so,
here's a snippet to help you out. First, make sure you som objects to
select. Then, add a listbox to a new UserForm and add this code:

Private Sub UserForm_Click()

Dim ss As AcadSelectionSet, i As Long
Dim tmp(), x As Long

On Error Resume Next
Set ss = ThisDrawing.SelectionSets("ss")
If err Then Set ss = ThisDrwing.SelectionSets.Add("ss")
ss.Clear
Me.Hide
ss.SelectOnScreen
x = ss.Count - 1

ReDim tmp(0 To x, 0 To x)
For i = 0 To ss.Count - 1
tmp(i, 0) = ss.Item(i).ObjectName
tmp(i, 1) = ss.Item(i).ObjectID
Next

ListBox1.List = tmp
Me.Show

End Sub
0 Likes
Message 5 of 10

Anonymous
Not applicable
Boy, talk about typos! "Make sure you have some objects to select" is what I
meant to say. Also, I forgot to mention you need to set the ColumnCount
property to 2 on your listbox. If you don't want one or the other column to
show, set its width to zero, For example, to hide the ObjectIDs, set
ColumnWidths to ;0.

The trick to filling a VBA listbox with an array is to set the ColumnCount
property equal to the number of dimensions in your array.
0 Likes
Message 6 of 10

Anonymous
Not applicable
Frank,

Yes, I do have a two column list box and I can get the information I want
from my 2D array without the one-dimensional array, but what I'm trying to
do is have the information available for several objects in a drawing ready
for display sequentially. For example, let's say there are a circle, a
line, and a piece of text in a drawing. I wanted a 2D array of information
for each of them ready beforehand, and each 2D array included in another
one-dimensional array. I thought I could set up "Next" and "Previous"
buttons to show the information about each object as either of those buttons
was pressed. Initially, the 2D array would dump information about the
circle into the list box and, when the "Next" button gets clicked, the 2D
information about the line would load up, and so on.

I was trying to get the one-dimensional array to control what 2D array gets
loaded. The first element of the flat array would be the 2D array about the
circle, the next element, the 2D array about the line, etc.

--
Eugene N. Kilmer
Owner/Mag Drafting
0 Likes
Message 7 of 10

Anonymous
Not applicable
Use the 2D array you already have. Use your previous and next buttons to
change the value of a form level variable. The form level variable
corrsponds to the index of your 2D array's first dimension. At this point,
it's easy enough to just manually assign the contents of the current index
to your listbox manually.
0 Likes
Message 8 of 10

Anonymous
Not applicable
Attached is a simple UserForm demonstrating what I was saying. Let me know
if it's what you're looking for.

Frank Oquendo wrote in message
news:85bccl$rqk5@adesknews2.autodesk.com...
> Use the 2D array you already have. Use your previous and next buttons to
> change the value of a form level variable. The form level variable
> corrsponds to the index of your 2D array's first dimension. At this point,
> it's easy enough to just manually assign the contents of the current index
> to your listbox manually.
>
>
>
>
0 Likes
Message 9 of 10

Anonymous
Not applicable
This is to the VB programers:
I have this user-defined public Type:

Public Type MyCircle
X as Single
Y as Single
Dia as Long
End Type

now I declare public array of this type
Public Circles() As MyCircle

in the next step I need to create an array: "GroupCircles ",
which is an array of arrays "Circles" of type "MyCircle"...
What is the correct declaration for this purpose?
0 Likes
Message 10 of 10

Anonymous
Not applicable
If I' following you correctly, your second array should be of type Variant.

--
Attitudes are contagious. Is yours worth catching?
http://www.acadx.com

"Rafi" wrote in message
news:eebfae8.7@WebX.SaUCah8kaAW...
> This is to the VB programers:
> I have this user-defined public Type:
>
> Public Type MyCircle
> X as Single
> Y as Single
> Dia as Long
> End Type
>
> now I declare public array of this type
> Public Circles() As MyCircle
>
> in the next step I need to create an array: "GroupCircles ",
> which is an array of arrays "Circles" of type "MyCircle"...
> What is the correct declaration for this purpose?
>
0 Likes