Author Topic: Got Arrays?  (Read 11988 times)

0 Members and 1 Guest are viewing this topic.

Fatty

  • Guest
Re: Got Arrays?
« Reply #15 on: May 03, 2008, 04:10:24 AM »
Dear Matt,
another way is to use Type
something like (not tested, may some mistakes)
Code: [Select]
Option Explicit

Type FileInfoRecord
a As String
b As String
c As String
End Type


Sub FillArrayWithRecords()
    Dim ListViewRow As FileInfoRecord
    ReDim ListViewRows(5) As FileInfoRecord
Dim i, k
For i = 0 To 5
ListViewRow.a = "T-0" & CStr(i + 1)
ListViewRow.b = "Technology " & CStr(i + 1)
ListViewRow.c = "000400-" & CStr(i + 1) & ".dwg"
ListViewRows(i) = ListViewRow
Next
MsgBox "Last row is: " & vbCr & _
ListViewRows(i).a & vbCr & _
ListViewRows(i).b & vbCr & _
ListViewRows(i).c
i = UBound(ListViewRows)
ReDim Preserve ListViewRows(i + 5)
For k = i + 1 To i + 5
ListViewRow.a = "T-0" & CStr(k)
ListViewRow.b = "Technology " & CStr(k)
ListViewRow.c = "000400-" & CStr(k) & ".dwg"
ListViewRows(i) = ListViewRow
Next
MsgBox "Now Last row is: " & vbCr & _
ListViewRows(k).a & vbCr & _
ListViewRows(k).b & vbCr & _
ListViewRows(k).c

End Sub

Regards,

~'J'~

rogue

  • Guest
Re: Got Arrays?
« Reply #16 on: May 05, 2008, 12:04:07 PM »
ARRRGH!  I was just going to submit some UDT (User-Defined-Type) code, but was beaten to the punch. However, to build on that code, you can nest the TYPES, and have arrays within them  ... (warning - code typed on the fly)

Type Layout
   LayoutName as String
   ParentDoc as AcadDocument
End type

Type DwgInfo
    PathSpec as String
    LayoutCount as Long
    Layouts() as Layout
End Type

Dim DocCount as long
Dim DocArray(DocCount) as DwgInfo


; ... and you can access the properties like such...

  Dim I as Long, J as Long

  For I=0 to Ubound(DocArray)
     Debug.print "Document:";DocCount(I).PathSpec
       For J=0 to LayoutCount
          Debug.print,,"Layout Name:";DocCount(I).Layouts(J).LayoutName
      Next J
  Next I

... of course, you'd have to check for/set empty arrays

 

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #17 on: May 07, 2008, 08:09:00 AM »
Matt: where did you get to on this?  Just curious   :-)

Guest

  • Guest
Re: Got Arrays?
« Reply #18 on: May 07, 2008, 08:09:58 AM »
Matt: where did you get to on this?  Just curious   :-)

Not very far.   :-(

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #19 on: May 07, 2008, 08:15:04 AM »
Matt: where did you get to on this?  Just curious   :-)

Not very far.   :-(
:(  Time constraints or still struggling with the code?

Guest

  • Guest
Re: Got Arrays?
« Reply #20 on: May 07, 2008, 08:21:08 AM »
Matt: where did you get to on this?  Just curious   :-)

Not very far.   :-(
:(  Time constraints or still struggling with the code?

Yes.   :-)

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #21 on: May 07, 2008, 08:27:41 AM »
Matt: where did you get to on this?  Just curious   :-)

Not very far.   :-(
:(  Time constraints or still struggling with the code?

Yes.   :-)
Good answer ;)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Got Arrays?
« Reply #22 on: May 07, 2008, 08:30:21 AM »
Matt, I generally use arrays to hold my arrays rather than collections (speed issues as previously noted) but it is because I generally don't have to handle specific items.

If you create a master array, you can call it that if you like, to keep them straight, then each of your subordinate arrays can be added dynamically and the array can grow as needed.

Although I have to admit I like the dwgInfo class ...

I guess my confusion is why you would want to store the drawing information when you could just as easily get the info from the drawing.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Guest

  • Guest
Re: Got Arrays?
« Reply #23 on: May 07, 2008, 08:40:38 AM »
Matt, I generally use arrays to hold my arrays rather than collections (speed issues as previously noted) but it is because I generally don't have to handle specific items.

If you create a master array, you can call it that if you like, to keep them straight, then each of your subordinate arrays can be added dynamically and the array can grow as needed.

Although I have to admit I like the dwgInfo class ...

I guess my confusion is why you would want to store the drawing information when you could just as easily get the info from the drawing.

I can't get the info from the drawings because the drawings don't exist yet.  Basically what the program will do is create each of the drawings listed in the File Name column and create the layout tab(s) listed in the Sheet No column.  So for the details sheet (0004000-T-DETL.dwg) there would be four layout tabs within that drawing (TC-501 to TC-504).  So what I'm envisioning is an array (or array of arrays) that will hold (1) the values in the File Name column - no duplicates and (2) the values in the Sheet No column that are associated with the values in the File Name column.  Make sense?  I'm thinking this will speed things up since I would be able to loop through the arrays and (1) open the newly created file (the value in the File Name column) and then (2) create the layout tabs associated with that file from the array.

I could simply loop through the values of the listview but that would mean opening the details drawing four times and adding a layout tab each time.

Do you understand what I'm getting at now?  I hope I explained that clearly - of course, I know what I'm talking about (in my head).  Sometimes I have problems conveying the information in a clear manner.   :oops:

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Got Arrays?
« Reply #24 on: May 07, 2008, 09:31:02 AM »
Ah .. very clear now .. You could use a treeview to organize each layout in under each drawing.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Guest

  • Guest
Re: Got Arrays?
« Reply #25 on: May 07, 2008, 09:43:02 AM »
Ah .. very clear now .. You could use a treeview to organize each layout in under each drawing.

Hmmm.....  might not be a bad idea.  Although... I'm already THIS far along - I don't really feel like re-writing a whole bunch of stuff.  Still... it's a good idea.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Got Arrays?
« Reply #26 on: May 07, 2008, 10:01:26 AM »
been there done that ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #27 on: May 07, 2008, 10:41:37 AM »
This any good?

Guest

  • Guest
Re: Got Arrays?
« Reply #28 on: May 07, 2008, 11:11:42 AM »
This any good?
I'm trying to piece this together (bear with me)...   :-)

So you've got this code (which I think I'm starting to understand now).

Code: [Select]
    Dim dwg As DwgInfo
    Dim i As Integer
    Dim j As Integer

    Set colDwg = New Collection
   
    For i = 1 To lvTech.ListItems.Count
        'Check if the filename has already been made
        If dwgInfoExists(lvTech.ListItems(i).ListSubItems(3)) = True Then
            'Add this layout to the DwgInfo
            colDwg.Item(dwgInfoIndex(lvTech.ListItems(i).ListSubItems(3))).add (lvTech.ListItems(i).ListSubItems(1))
        Else
            'Make a new one
            Set dwg = New DwgInfo
            dwg.Title = lvTech.ListItems(i).ListSubItems(2)
            dwg.fileName = lvTech.ListItems(i).ListSubItems(3)
           
            dwg.add (lvTech.ListItems(i).ListSubItems(1))
                   
            colDwg.add dwg
        End If
    Next i

The part that's throwing me for a loop (no pun intended - hehehe) is iterating through the info to show what belongs where.

I've got this (so far)...

Code: [Select]
    Dim x As Integer
    Dim y As Integer
   
    For x = 1 To colDwg.Count
        For y = 1 To dwg.Count
            Debug.Print dwg.Item(y)
        Next y
    Next x

If I understand this correctly, I need to loop through 'colDwg' and then within that loop, loop through the 'dwg' info to determine the layout names that are associated with the file names, right?

And so when I run this I get a bunch of the same thing printed at the immediate window.  What am I missing (besides the obvious probably)?  :ugly:

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #29 on: May 07, 2008, 11:30:24 AM »
<snip>

The part that's throwing me for a loop (no pun intended - hehehe) is iterating through the info to show what belongs where.

I've got this (so far)...

Code: [Select]
    Dim x As Integer
    Dim y As Integer
   
    For x = 1 To colDwg.Count
        For y = 1 To dwg.Count
            Debug.Print dwg.Item(y)
        Next y
    Next x

If I understand this correctly, I need to loop through 'colDwg' and then within that loop, loop through the 'dwg' info to determine the layout names that are associated with the file names, right?

And so when I run this I get a bunch of the same thing printed at the immediate window.  What am I missing (besides the obvious probably)?  :ugly:
You're not reassigning "dwg" at any point in the loop - therefore dwg still refers to the last object you pushed into the collection (assuming, of course, you're running it in the button's sub)