Author Topic: Got Arrays?  (Read 6248 times)

0 Members and 1 Guest are viewing this topic.

Guest

  • Guest
Got Arrays?
« on: May 02, 2008, 01:35:20 PM »
I've got a program that I'm working on that I need to create a list of information.  Based on the various searches I've done, I'm probably now more confused than ever before.  I'm not sure what the best way to do this is (scripting dictionary, array, collection, etc...) but I'd like to learn how to do it using an arrray.

So here's the scoop...

The program I'm working on will create a series of drawings and add various layout tabs to them.  And so for starters, I need to gather the drawing information based on file names and what layout tabs are associated with them.

For example:  Drawing 'A' could have layout tabs 'A', 'B', 'C'.  Drawing 'B' could have layout tabs 'A1', 'A2', 'A3', 'A4', 'A5' and so on and so forth.

I'm currently gathering the information from the listview box of my program (see attached DVB).  When you click the "CREATE PROJECT FILES" button, it loops through the entries in the listview.  But what I need to do is gather the information as follows:
Drawing 'A'
Layout tab 'A'
Layout tab 'B'
Layout tab 'C'

Drawing 'B'
Layout tab 'A1'
Layout tab 'A2'
Layout tab 'A3'
Layout tab 'A4'
Layout tab 'A5'

And so on....

So do I need to do an array of arrays (as if a simple array isn't giving me enough grief)??  I hope this makes sense.

SomeCallMeDave

  • Guest
Re: Got Arrays?
« Reply #1 on: May 02, 2008, 02:17:07 PM »
One way to do it would be with a collection.  You could create a DwgInfo object that has a Name (Drawing A)  and has a collection where you could store the layout names.

Something like this:

In a class module called DwgInfo
Code: [Select]
Option Explicit
Private colLayouts As Collection
Private mName As String

Private Sub Class_Initialize()
    Set colLayouts = New Collection
   
End Sub

Public Sub add(LayoutName As String)
    colLayouts.add LayoutName
End Sub
Public Sub remove(LayoutName As String)
    colLayouts.remove (LayoutName)
End Sub
Public Property Get Count() As Integer
 Count = colLayouts.Count
End Property

Public Property Let Name(dwgName As String)
    mName = dwgName
End Property

Public Property Get Name() As String
    Name = mName
End Property

Public Function Item(index As Integer) As String
    Item = colLayouts.Item(index)
End Function



Then in a code module:

Code: [Select]
Public Sub Test()
    Dim dwg1 As DwgInfo
    Dim dwg2 As DwgInfo
    Dim colDwg As Collection
   
    Dim i As Integer
   
    Set colDwg = New Collection
   
    Set dwg1 = New DwgInfo
    Set dwg2 = New DwgInfo
   
    dwg1.Name = "Drawing A"
    dwg1.add ("A")
    dwg1.add ("B")
    dwg1.add ("C")
   
    dwg2.Name = "Drawing B"
    dwg2.add ("A1")
    dwg2.add ("A2")
    dwg2.add ("A3")
   
    For i = 1 To dwg1.Count
      'do your stuff here
        Debug.Print dwg1.Item(i)
    Next i
   
    For i = 1 To dwg2.Count
     'do your stuff here
        Debug.Print dwg2.Item(i)
    Next i
   
   

End Sub


Also, in your code module, you could have another collection to hold the dwgInfo objects and then iterate that collection to do your magic.

If you use arrays, you will have to resize them to add elements where collections might be slower, but they are easier to use for dynamically sized data.

Just my 2 cents.

Guest

  • Guest
Re: Got Arrays?
« Reply #2 on: May 02, 2008, 02:25:47 PM »
I'm not sure collections would be the way to go because 1) the number of drawings/layout tabs will vary based and 2) how do you determine if an item is already in a collection?  There is no EXISTS function.  Would that be a separate function altogether?

I'd really like to figure out this array stuff.  It's driving me crazy.

Thanks for your input.

Guest

  • Guest
Re: Got Arrays?
« Reply #3 on: May 02, 2008, 03:41:40 PM »
Tuoni:

Here's the code behind the CREATE PROJECT FILES button.

Code: [Select]
Private Sub cmdSetup_Click()
    Dim i As Integer
    Dim intFileNumber As Integer
    Dim strLayout As String, strFileName As String

    For i = 1 To lvTech.ListItems.Count
        intFileNumber = lvTech.ListItems(i)
        strLayout = lvTech.ListItems(i).ListSubItems(1)
        strFileName = lvTech.ListItems(i).ListSubItems(3)
        Debug.Print strFileName
        Debug.Print strLayout
    Next i
End Sub

And this is what it spits out at the immediate window.

Quote
0004000-T-NOT.dwg
T-000
0004000-T-COMM-1.dwg
TC-101
0004000-T-COMM-1.dwg
TC-102
0004000-T-COMM-2.dwg
TC-201
0004000-T-COMM-2.dwg
TC-202
0004000-T-SECY-1.dwg
TS-101
0004000-T-SECY-1.dwg
TS-102
0004000-T-SECY-2.dwg
TS-201
0004000-T-SECY-2.dwg
TS-202
0004000-T-SITE.dwg
TS-000
0004000-T-PART.dwg
TC-301
0004000-T-PART.dwg
TC-302
0004000-T-RISR.dwg
TC-401
0004000-T-RISR.dwg
TC-402
0004000-T-DETL.dwg
TC-501
0004000-T-DETL.dwg
TC-502
0004000-T-DETL.dwg
TC-503
0004000-T-DETL.dwg
TC-504

This is based on what you see in the image in my first post.

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #4 on: May 02, 2008, 04:11:06 PM »
If I'm understanding what you're aiming for correctly (which I'm possibly not...) the code posted by David Blackmon would appear to do exactly what you want - for each drawing, create a new DwgInfo object and add the layouts to it and then add it to a collection.  You could write an exists property which loops through the collection if needs be?

Guest

  • Guest
Re: Got Arrays?
« Reply #5 on: May 02, 2008, 04:13:23 PM »
If I'm understanding what you're aiming for correctly (which I'm possibly not...) the code posted by David Blackmon would appear to do exactly what you want - for each drawing, create a new DwgInfo object and add the layouts to it and then add it to a collection.  You could write an exists property which loops through the collection if needs be?

Would a collection be the best way to go about doing this?  Or would an array be better?  Just curious.

Guest

  • Guest
Re: Got Arrays?
« Reply #6 on: May 02, 2008, 04:22:15 PM »
And another question...

Code: [Select]
    Dim dwg1 As DwgInfo
    Dim dwg2 As DwgInfo

The code provided has 2 dimmed.  How can I, I guess, "dim" more on the fly as I encounter more drawings?



It's been a long and I've been staring at this code for hours and it's all becoming a blur, so forgive me if I'm asking "stupid" questions.   :oops:

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #7 on: May 02, 2008, 04:24:03 PM »
If I'm understanding what you're aiming for correctly (which I'm possibly not...) the code posted by David Blackmon would appear to do exactly what you want - for each drawing, create a new DwgInfo object and add the layouts to it and then add it to a collection.  You could write an exists property which loops through the collection if needs be?

Would a collection be the best way to go about doing this?  Or would an array be better?  Just curious.
Depends what you want to do with them, really.  Collections have a couple of advantages over arrays - adding to them is easy enough and unlike arrays you don't have to worry about how full it is, whether you have space, whereabouts that space is;  secondly you can refer to items in a collection by index or by key, arrays you can only use index...  Collections are theoretically slower than arrays, however I doubt you'd notice.  One thing to keep in mind, though, is that collections' indexing starts at 1, not 0

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #8 on: May 02, 2008, 04:38:00 PM »
And another question...

Code: [Select]
    Dim dwg1 As DwgInfo
    Dim dwg2 As DwgInfo

The code provided has 2 dimmed.  How can I, I guess, "dim" more on the fly as I encounter more drawings?



It's been a long and I've been staring at this code for hours and it's all becoming a blur, so forgive me if I'm asking "stupid" questions.   :oops:
You should be able to create the object within the loop, like so: (note, untested)

Code: [Select]
Public Sub Test()
    Dim dwg As DwgInfo
    Dim colDwg As Collection
   
    Dim i As Integer
    Dim j As Integer

    Set colDwg = New Collection
   
    For i = 1 To lvTech.ListItems.Count
        Set dwg = new DwgInfo
        dwg.Name = lvTech.ListItems(i).ListSubItems(3)
        For j = 1 To dwg.Count
            dwg.add( -insert the code for the layout in here- )
        Next j
        colDwg.add(dwg)
    Next i
   
End Sub
Something like that, anyways.  You'll need to do some sanity checking on that - again, untested

SomeCallMeDave

  • Guest
Re: Got Arrays?
« Reply #9 on: May 02, 2008, 04:38:33 PM »
You can dim one variable and use it over and over

Code: [Select]
Public Sub Test()
    Dim dwg1 As DwgInfo
    Dim dwg2 As DwgInfo
    Dim colDwg As Collection
   
    Dim i As Integer
    Dim j As Integer
   
   
    Set colDwg = New Collection
   
    Set dwg1 = New DwgInfo
    Set dwg2 = New DwgInfo
   

    'loop thru the possible drawing names here and add them to the colDwg
    For i = 1 To 5
        Set dwg1 = New DwgInfo

       'add another loop here to add each layout to the dwg1 object
        dwg1.Name = "Drawing A" + Str(i)
        dwg1.add ("A" + Str(i))
        dwg1.add ("B" + Str(i))
        dwg1.add ("C" + Str(i))
        colDwg.add dwg1
        Set dwg1 = Nothing
    Next i
   
    For i = 1 To 5
        Set dwg2 = colDwg.Item(i)
        For j = 1 To dwg2.Count
            Debug.Print dwg2.Item(j)
        Next j
   
    Next i
   
 

End Sub



SomeCallMeDave

  • Guest
Re: Got Arrays?
« Reply #10 on: May 02, 2008, 04:39:38 PM »
Oops.  Tuoni beat me to it

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #11 on: May 02, 2008, 04:41:01 PM »
Oops.  Tuoni beat me to it
Good to see I wasn't imagining that process :-D  Been a while since I've played with this here language!

SomeCallMeDave

  • Guest
Re: Got Arrays?
« Reply #12 on: May 02, 2008, 06:39:39 PM »
.....  Been a while since I've played with this here language!

Me too.  I tried to put semi-colon at the end of every line  :-D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Got Arrays?
« Reply #13 on: May 02, 2008, 06:44:10 PM »
.....  Been a while since I've played with this here language!

Me too.  I tried to put semi-colon at the end of every line  :-D

 :-)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: Got Arrays?
« Reply #14 on: May 02, 2008, 06:45:39 PM »
.....  Been a while since I've played with this here language!

Me too.  I tried to put semi-colon at the end of every line  :-D
I deleted mine just before I posted :lol: