How to fill a dynamic array?

How to fill a dynamic array?

mdhutchinson
Advisor Advisor
1,317 Views
25 Replies
Message 1 of 26

How to fill a dynamic array?

mdhutchinson
Advisor
Advisor
I have an application that:

I am still a bit green with VBA… this is only my first application… but so far (slowly) so good!

Put as short as is possible, the application …
Activates currently open documents...
Within each dwg...
... the app builds a select set of closed polygonal block (3 or 4 or so) ...
Then parses through each closed polygonal block...
and gets other block references (10 to 34 or more) that are positioned within
them. The collected multiple blocks are sorted by polygonal block’s OCS. The sorted block's number attribute value is incremented starting from the first dwg to the last open dwg.

After all the dwgs are activated and the objects are processed... I want to fill a ListView control with collected data... where each block is represented as a row in the ListView control. Each row in the ListView control will be filled with (8 columns) as follows:

Cnt#AttribVal1, AttribVal2, AttribVal3, Lgth, Wdth, Dpth, Handle, Document

… So… Obviously, I know how many columns there are, but I don’t know until all is process how many objects there will be … there could be several hundred and for larger projects perhaps a thousand or more…

As I understand it … you can ReDim ONLY the upper bound of the last dimension last dimension of the dynamic array… so, … how might I approach this such to collect all the data where the rows may vary (as many as a thousand worst case perhaps), then fill the ListView control after all the data is collected?

Also, I think I’ve experimented enough with the ListView control, and I now know how to fill it … also, it looks that once filled, the control itself holds the data and the variable doesn’t have to be maintained, instead I can retrieved the data straight from the control itself… therefore perhaps I only need to populate a dynamic array for each drawing processed, then put the data into the control… then process the next drawing and reuse the dynamic array.

So I guess to summarize my questions are two:

1). How can I define a two dimensional dynamic array that can grow to hold variable records/rows and 8 columns?

2). Would it best to collect all the data and fill the ListView afterwards… or input the data into the ListView control after each drawing has been processed?
0 Likes
1,318 Views
25 Replies
Replies (25)
Message 2 of 26

Anonymous
Not applicable
Personally, I would use a class module to define an object that stores the
data for each object, and store those objects in a collection. I would not
use an array.

--
R. Robert Bell


wrote in message news:5441250@discussion.autodesk.com...
I have an application that:

I am still a bit green with VBA. this is only my first application. but so
far (slowly) so good!

Put as short as is possible, the application .
Activates currently open documents...
Within each dwg...
... the app builds a select set of closed polygonal block (3 or 4 or so)
...
Then parses through each closed polygonal block...
and gets other block references (10 to 34 or more) that are positioned
within
them. The collected multiple blocks are sorted by polygonal block's OCS. The
sorted block's number attribute value is incremented starting from the first
dwg to the last open dwg.

After all the dwgs are activated and the objects are processed... I want to
fill a ListView control with collected data... where each block is
represented as a row in the ListView control. Each row in the ListView
control will be filled with (8 columns) as follows:

Cnt#AttribVal1, AttribVal2, AttribVal3, Lgth, Wdth, Dpth, Handle, Document

. So. Obviously, I know how many columns there are, but I don't know until
all is process how many objects there will be . there could be several
hundred and for larger projects perhaps a thousand or more.

As I understand it . you can ReDim ONLY the upper bound of the last
dimension last dimension of the dynamic array. so, . how might I approach
this such to collect all the data where the rows may vary (as many as a
thousand worst case perhaps), then fill the ListView control after all the
data is collected?

Also, I think I've experimented enough with the ListView control, and I now
know how to fill it . also, it looks that once filled, the control itself
holds the data and the variable doesn't have to be maintained, instead I can
retrieved the data straight from the control itself. therefore perhaps I
only need to populate a dynamic array for each drawing processed, then put
the data into the control. then process the next drawing and reuse the
dynamic array.

So I guess to summarize my questions are two:

1). How can I define a two dimensional dynamic array that can grow to hold
variable records/rows and 8 columns?

2). Would it best to collect all the data and fill the ListView afterwards.
or input the data into the ListView control after each drawing has been
processed?
0 Likes
Message 3 of 26

mdhutchinson
Advisor
Advisor
Are you referring to Creating Dynamic Data Structures Using Class Modules such as what is shown in the VBA Developer's Handbook chapter 8?

http://www.developershandbook.com/Downloads/1951c06.pdf
... okay... I am green... and I need some tender care to get this stuff...

how can I get started with this...

let's see... I need to create an Object for each 'row' ... basically

The each object will have Properties as follows:

ControlNum
ProductCode
PceLength
PceWidth
PceDepth
DocumentFoundIn
MarkHandle

... am I on the right track? ... how do I proceed?
Is there some sample I might look at?
0 Likes
Message 4 of 26

Anonymous
Not applicable
wrote in message news:5441332@discussion.autodesk.com...
Are you referring to Creating Dynamic Data Structures Using Class Modules
such as what is shown in the VBA Developer's Handbook chapter 8?

http://www.developershandbook.com/Downloads/1951c06.pdf
... okay... I am green... and I need some tender care to get this stuff...

how can I get started with this...

let's see... I need to create an Object for each 'row' ... basically

The each object will have Properties as follows:

ControlNum
ProductCode
PceLength
PceWidth
PceDepth
DocumentFoundIn
MarkHandle

... am I on the right track? ... how do I proceed?
Is there some sample I might look at?


quick sample to give idea hopefully ... there are tons of examples in the
help files and google on this group and msdn for stuff about classes

briefly in vba create a new class module
Menu --> Insert|Class module
Name it whatever you want to call it eg "cInfo"
give it your properties mentioned above by writing property accessors (Get,
Let, Set)
define private member variables at top of module to hold values for each
property
eg:
Private mlProductCode as long

define propert Let or set(if object) to input value
Property Let ProductCode(Data as Long)
mlProductCode = Data
End Property

define property Get to retrieve value
Property Get ProductCode() as Long
ProductCode = mlProductCode
End Property

In main program Dim a variable for your class
Dim oInfo as cInfo
Dim mcolInfoItems as collection 'to hold all your instances

In programs loop
Do While ...
'create instance for this "row"
Set oInfo = New cInfo
'set all properties
oInfo.ProductCode = lThisProductCode
'etc with other properties
'add object to collection
mcolInfoItems.Add oInfo
Loop

then when all items are collected
For Each oInfo in mcolInfoItems
'do whatever
Next oInfo


hth
Mark
ps, is it possible to post as plain text? that way replies will show your
text as being the "replied to" block of text
0 Likes
Message 5 of 26

mdhutchinson
Advisor
Advisor
MP...

I am writting code in my app now to create and minipulate this collection.

Anyway... is this the right idea for the Class modeule
Option Explicit

Private ContNumItems As Collection 'collection of ContNumItems
Private itmContNum As Integer 'ControlNumber
Private itmProductCode As String 'PCode
Private itmPceMrk As String 'Mark
Private itmPceLength As Double 'Length
Private itmPceWidth As Double 'Width
Private itmPceDepth As Double 'Depth
Private itmMrkBlkDoc As String 'DwgName
Private itmMrkBlkHandle As AcadBlockReference.Handle 'Object.Handle
'|****************************************************************************|
'|**************** Let & Get properties -- Control Number ********************|
Property Let ContNum(data As Integer)
itmContNum = data
End Property
Property Get ContNum() As Integer
ContNum = itmContNum
End Property
'|****************************************************************************|
'|****************** Let & Get properties -- Product Code ********************|
Property Let ProductCode(data As String)
itmProductCode = data
End Property
Property Get ProductCode() As String
ProductCode = itmProductCode
End Property
'|****************************************************************************|
'|****************** Let & Get properties -- Piece Mark **********************|
Property Let PceMrk(data As String)
PceMrk = data
End Property
Property Get PceMrk() As String
PceMrk = itmPceMrk
End Property

'|****************************************************************************|
'|****************** Let & Get properties -- Piece Length ********************|
Property Let PceLength(data As Double)
itmPceLength = data
End Property
Property Get PceLength() As Double
PceLength = itmPceLength
End Property
'|****************************************************************************|
'|****************** Let & Get properties -- Piece Width *********************|
Property Let PceWidth(data As Double)
itmPceWidth = data
End Property
Property Get PceWidth() As Double
PceWidth = itmPceWidth
End Property
'|****************************************************************************|
'|****************** Let & Get properties -- Piece Depth *********************|
Property Let PceDepth(data As Double)
itmPceDepth = data
End Property
Property Get PceDepth() As Double
PceDepth = itmPceDepth
End Property
'|****************************************************************************|
'|**************** Let & Get properties -- BlockRef Handle *******************|
Property Let MrkBlkHandle(data As String)
itmMrkBlkHandle = data
End Property
Property Get MrkBlkHandle() As String
MrkBlkHandle = itmMrkBlkHandle
End Property
'|****************************************************************************|
'|************ Let & Get properties -- BlockReference Handle *****************|
Property Let MrkBlkDoc(data As String)
itmMrkBlkDoc = data
End Property
Property Get MrkBlkDoc() As String
MrkBlkDoc = itmMrkBlkDoc
End Property
0 Likes
Message 6 of 26

mdhutchinson
Advisor
Advisor
Revised Class Module is Below....

The class module seems to work so far... the locals window shows properties getting set correctly... but when I go to add the data to the collection it fails.
see the noted line indicated by..." <<<<<< IT FAILS HERE "

… but per your instructions ... if (of course), I am interpreting it correctly 8-):
‘ your instruction ******************
’In programs loop
Do While ...
'create instance for this "row"
Set oInfo = New cInfo
'set all properties
oInfo.ProductCode = lThisProductCode
'etc with other properties
'add object to collection
mcolInfoItems.Add oInfo ‘ my code fails here? What am I missing?
Loop
’ end of your instruction

My line to add the info to the collection fails... (see below)
If I comment out this line my code runs to completion:

For incMrk = 0 To ssMrkSorted.Count - 1 ' loop thru sorted Mark Block Selection Set
Set blkMrk = ssMrkSorted.item(incMrk) ' for each Mark Block

Set CntNumItm = New ContNumItem
CntNumItm.ContNum = incCntlNum ' actual data
CntNumItm.ProductCode = "WP1" ' test data
CntNumItm.PceMrk = "W10A" ' test data
CntNumItm.PceLength = 300.86 ' test data
CntNumItm.PceWidth = 144.5 ' test data
CntNumItm.PceDepth = 12.75 ' test data
CntNumItm.MrkBlkDoc = blkMrk.Document.Name ' actual data
CntNumItm.MrkBlkHandle = blkMrk.Handle ' actula data

ContNumItems.Add CntNumItm '<<<<<< IT FAILS HERE --- If I comment this line out it runs fine to completion?

Debug.Print blkMrk.Handle ' get the handle
Debug.Print TypeName(blkMrk.Handle) ' check the data type
Debug.Print blkMrk.Document.Name ' get the owning document
Debug.Print TypeName(blkMrk.Document.Name) ' check the data type

Call SetCntlNumAtt(blkMrk, incCntlNum) ' set the control number
incCntlNum = incCntlNum + 1 ' increment the Control Number
Next incMrk


‘******* the class module (this seems to work as it should)
'************************************************************
'************************************************************
Option Explicit

Private itmContNum As Integer 'ControlNumber
Private itmProductCode As String 'PCode
Private itmPceMrk As String 'Mark
Private itmPceLength As Double 'Length
Private itmPceWidth As Double 'Width
Private itmPceDepth As Double 'Depth
Private itmMrkBlkDoc As String 'DwgName
Private itmMrkBlkHandle As String 'Object.Handle
'|*********************************************************** *****************|
'|**************** Let & Get properties -- Control Number ********************|
Property Let ContNum(data As Integer)
itmContNum = data
End Property
Property Get ContNum() As Integer
ContNum = itmContNum
End Property
'|***************************************************************** ***********|
'|****************** Let & Get properties -- Product Code ********************|
Property Let ProductCode(data As String)
itmProductCode = data
End Property
Property Get ProductCode() As String
ProductCode = itmProductCode
End Property
'|***************************************************************** ***********|
'|****************** Let & Get properties -- Piece Mark **********************|
Property Let PceMrk(data As String)
itmPceMrk = data
End Property
Property Get PceMrk() As String
PceMrk = itmPceMrk
End Property

'|************************************************************* ***************|
'|****************** Let & Get properties -- Piece Length ********************|
Property Let PceLength(data As Double)
itmPceLength = data
End Property
Property Get PceLength() As Double
PceLength = itmPceLength
End Property
'|***************************************************************** ***********|
'|****************** Let & Get properties -- Piece Width *********************|
Property Let PceWidth(data As Double)
itmPceWidth = data
End Property
Property Get PceWidth() As Double
PceWidth = itmPceWidth
End Property
'|***************************************************************** ***********|
'|****************** Let & Get properties -- Piece Depth *********************|
Property Let PceDepth(data As Double)
itmPceDepth = data
End Property
Property Get PceDepth() As Double
PceDepth = itmPceDepth
End Property
'|***************************************************************** ***********|
'|**************** Let & Get properties -- BlockRef Handle *******************|
Property Let MrkBlkHandle(data As String)
itmMrkBlkHandle = data
End Property
Property Get MrkBlkHandle() As String
MrkBlkHandle = itmMrkBlkHandle
End Property
'|***************************************************************** ***********|
'|************ Let & Get properties -- BlockReference Handle *****************|
Property Let MrkBlkDoc(data As String)
itmMrkBlkDoc = data
End Property
Property Get MrkBlkDoc() As String
MrkBlkDoc = itmMrkBlkDoc
End Property
0 Likes
Message 7 of 26

Anonymous
Not applicable
Give a unique index value for each item as you add it.

Sub Test()
Dim myItems As Collection
Set myItems = New Collection

Dim i As Long
For i = 0 To 9
Dim aItem As Test
Set aItem = New Test
aItem.Name = "Item" & CStr(i)
myItems.Add aItem, CStr(i)
Next i
End Sub


--
R. Robert Bell


wrote in message news:5441811@discussion.autodesk.com...
Revised Class Module is Below....

The class module seems to work so far... the locals window shows properties
getting set correctly... but when I go to add the data to the collection it
fails.
see the noted line indicated by..." <<<<<< IT FAILS HERE "

. but per your instructions ... if (of course), I am interpreting it
correctly 8-):
' your instruction ******************
'In programs loop
Do While ...
'create instance for this "row"
Set oInfo = New cInfo
'set all properties
oInfo.ProductCode = lThisProductCode
'etc with other properties
'add object to collection
mcolInfoItems.Add oInfo ' my code fails here? What am I missing?
Loop
' end of your instruction

My line to add the info to the collection fails... (see below)
If I comment out this line my code runs to completion:

For incMrk = 0 To ssMrkSorted.Count - 1 ' loop thru sorted Mark Block
Selection Set
Set blkMrk = ssMrkSorted.item(incMrk) ' for each Mark Block

Set CntNumItm = New ContNumItem
CntNumItm.ContNum = incCntlNum ' actual data
CntNumItm.ProductCode = "WP1" ' test data
CntNumItm.PceMrk = "W10A" ' test data
CntNumItm.PceLength = 300.86 ' test data
CntNumItm.PceWidth = 144.5 ' test data
CntNumItm.PceDepth = 12.75 ' test data
CntNumItm.MrkBlkDoc = blkMrk.Document.Name ' actual data
CntNumItm.MrkBlkHandle = blkMrk.Handle ' actula data

ContNumItems.Add CntNumItm '<<<<<< IT FAILS HERE --- If I comment this line
out it runs fine to completion?

Debug.Print blkMrk.Handle ' get the handle
Debug.Print TypeName(blkMrk.Handle) ' check the data type
Debug.Print blkMrk.Document.Name ' get the owning document
Debug.Print TypeName(blkMrk.Document.Name) ' check the data type

Call SetCntlNumAtt(blkMrk, incCntlNum) ' set the control number
incCntlNum = incCntlNum + 1 ' increment the Control Number
Next incMrk


'******* the class module (this seems to work as it should)
'************************************************************
'************************************************************
Option Explicit

Private itmContNum As Integer 'ControlNumber
Private itmProductCode As String 'PCode
Private itmPceMrk As String 'Mark
Private itmPceLength As Double 'Length
Private itmPceWidth As Double 'Width
Private itmPceDepth As Double 'Depth
Private itmMrkBlkDoc As String 'DwgName
Private itmMrkBlkHandle As String 'Object.Handle
'|***********************************************************
*****************|
'|**************** Let & Get properties -- Control Number
********************|
Property Let ContNum(data As Integer)
itmContNum = data
End Property
Property Get ContNum() As Integer
ContNum = itmContNum
End Property
'|*****************************************************************
***********|
'|****************** Let & Get properties -- Product Code
********************|
Property Let ProductCode(data As String)
itmProductCode = data
End Property
Property Get ProductCode() As String
ProductCode = itmProductCode
End Property
'|*****************************************************************
***********|
'|****************** Let & Get properties -- Piece Mark
**********************|
Property Let PceMrk(data As String)
itmPceMrk = data
End Property
Property Get PceMrk() As String
PceMrk = itmPceMrk
End Property

'|*************************************************************
***************|
'|****************** Let & Get properties -- Piece Length
********************|
Property Let PceLength(data As Double)
itmPceLength = data
End Property
Property Get PceLength() As Double
PceLength = itmPceLength
End Property
'|*****************************************************************
***********|
'|****************** Let & Get properties -- Piece Width
*********************|
Property Let PceWidth(data As Double)
itmPceWidth = data
End Property
Property Get PceWidth() As Double
PceWidth = itmPceWidth
End Property
'|*****************************************************************
***********|
'|****************** Let & Get properties -- Piece Depth
*********************|
Property Let PceDepth(data As Double)
itmPceDepth = data
End Property
Property Get PceDepth() As Double
PceDepth = itmPceDepth
End Property
'|*****************************************************************
***********|
'|**************** Let & Get properties -- BlockRef Handle
*******************|
Property Let MrkBlkHandle(data As String)
itmMrkBlkHandle = data
End Property
Property Get MrkBlkHandle() As String
MrkBlkHandle = itmMrkBlkHandle
End Property
'|*****************************************************************
***********|
'|************ Let & Get properties -- BlockReference Handle
*****************|
Property Let MrkBlkDoc(data As String)
itmMrkBlkDoc = data
End Property
Property Get MrkBlkDoc() As String
MrkBlkDoc = itmMrkBlkDoc
End Property
0 Likes
Message 8 of 26

Anonymous
Not applicable
. Robert Bell" wrote in message
news:5441818@discussion.autodesk.com...
Give a unique index value for each item as you add it.

Sub Test()
Dim myItems As Collection
Set myItems = New Collection

Dim i As Long
For i = 0 To 9
Dim aItem As Test
Set aItem = New Test
aItem.Name = "Item" & CStr(i)
myItems.Add aItem, CStr(i)
Next i
End Sub


--
R. Robert Bell


Hi Robert,
I must be missing something here...
I'm not seeing something you are seeing...
how does that address his question about an error adding a class instance to
a collection?
You don't *have* to use a key to add items to a collection, unless you want
to retrieve them by key rather than by index, do you?

ContNumItems.Add CntNumItm '<<<<<< IT FAILS HERE ---

I would wonder what he means by "It fails Here"... what error is he getting?
I would think if ContNumItems is dimmed as a collection(which isn't shown in
his post) and if it's not Nothing, then his line should work with or without
a named key...or what am i missing?
I wonder if he has Option Explicit set?

Mark
0 Likes
Message 9 of 26

Anonymous
Not applicable
wrote in message news:5441811@discussion.autodesk.com...
Revised Class Module is Below....

The class module seems to work so far... the locals window shows properties
getting set correctly... but when I go to add the data to the collection it
fails.
see the noted line indicated by..." <<<<<< IT FAILS HERE "

. but per your instructions ... if (of course), I am interpreting it
correctly 8-):
' your instruction ******************
'In programs loop
Do While ...
'create instance for this "row"
Set oInfo = New cInfo
'set all properties
oInfo.ProductCode = lThisProductCode
'etc with other properties
'add object to collection
mcolInfoItems.Add oInfo ' my code fails here? What am I missing?
Loop
' end of your instruction

My line to add the info to the collection fails... (see below)
If I comment out this line my code runs to completion:
ContNumItems.Add CntNumItm '<<<<<< IT FAILS HERE --- If I comment this line
out it runs fine to completion?

where is ContNumItems declared and set?
what error are you getting when you say "It fails Here"
(It's always important to post the error rather than saying something
"doesnt' work")
do you have Option Explicit at top of module?
what are your break on error settings ?
do you have an error trap in your routine that tells you the error code ?
0 Likes
Message 10 of 26

mdhutchinson
Advisor
Advisor
thanks so much for the help...

To: MP
At the top Option Explicit within the module where the flawed code resides I have:

Option Explicit
Dim objss As AcadSelectionSet
Dim strName As String
Dim CntNumItm As ContNumItem
‘ ContNumItem is the name of my class module…
‘ where let and get properties are defined.
‘ ContNumItems is defined at the option explicit section.
Dim ContNumItems As Collection

As you can see, I do have an Option Explicit at the top of the module.
Assuming you mean General tab of options dialog… My break on error settings are set to the third selection: ‘Break on Unhandled Errors’

The error that happens is:
Run-time error 91: Object variable or With block variable not set. (see the attached)

To Robert Bell… ‘a unique index value for each item I want to add?... what do you mean?... see the attached as I do have a unique value for the item I want to add…
… is the ‘index’ another required parameter that happens to be an integer?... the unique value in your example only exist in the string which you are adding “Item” & Cstr(i).

I want to add to the collection my ‘ContNumItems’… each being a ‘CntNumItm’ object populated with properties (via my class module) … each one of these objects will be unique via the itmContNum property which increments for each object that I want to add… isn’t this unique enough?...
what am I missing?
0 Likes
Message 11 of 26

mdhutchinson
Advisor
Advisor
The other attachment which shows the unique value I want to add...
0 Likes
Message 12 of 26

Anonymous
Not applicable
wrote in message news:5442240@discussion.autodesk.com...
thanks so much for the help...

To: MP
At the top Option Explicit within the module where the flawed code resides I
have:

Option Explicit
Dim objss As AcadSelectionSet
Dim strName As String
Dim CntNumItm As ContNumItem
' ContNumItem is the name of my class module.
' where let and get properties are defined.
' ContNumItems is defined at the option explicit section.
Dim ContNumItems As Collection

As you can see, I do have an Option Explicit at the top
of the module.

That's a good thing


Assuming you mean General tab of options dialog. My break on error settings
are set to the third selection: 'Break on Unhandled Errors'

That's also good.


The error that happens is:
Run-time error 91: Object variable or With block variable not set. (see the
attached)

So there's your answer, an object variable was not set!!!
Which one?
The one at the line that threw the error.
ContNumItems.Add xxx
What is ContNumItems ?
at this point its' Nothing because you haven't set it yet....
above where you have
Dim ContNumItems As Collection
you need
Set ContNumItems = New Collection
now it's Something 🙂 and the error goes away...I hope

a general note...if you really have those variables at the top of your
module then they're available to all functions in that module which may not
be what you want
it is generally recommended to give variables the most local scope possible
so if they're just used in the function you're working on now, move them
into that function.
as it is now it's possible you set ContNumItems = New Collection in one
function, then somewhere else Set ContNumItems = Nothing, then later, try to
add something to it....
You probably *arent'* doing that...but it's possible which is why it's
recommended to keep them as local as possible to avoid inadvertant bugs...
:-)
hth
Mark
0 Likes
Message 13 of 26

mdhutchinson
Advisor
Advisor
That was it! ...

In the Option Explicit section I edited:
Dim ContNumItems As Collection
' instead to...
Dim ContNumItems As New Collection

…and it worked without error, but only the first time ... when I ran it a second time I got: “Run-time error '457': This key is already associated with an element of this collection” – Are collections persistent within the instance of the AutoCAD editor?

Some other questions… and finally a COUPLE THOUGHTS about my app (which you can read if this would help you understand where I am heading with this) …

I think I want to have the collection so that I can call its members by the key... for all practical purposes, the 'key' could be equal to the ControlNumber... which increments across multiple erection dwg files (within a given job) with no duplicates… but, in the final version for production I may want to be able to have an ‘empty’ control number ‘key’ that doesn’t exist in the collection … can the Item keys have breaks in the sequence.. (i.e. 1, 2, 3, 5, 6, 7, 8, 10, etc).
What is the data type of the ‘key’? … string or integer?

In my application I probably want to have the ContNumItems collection available throughout the VBA project… So where should I put its Dim as New statement so that I can modify, reference, or possiby ‘delete’ an item (if this can be done?).

Question: Should I have both of these lines with the first in the option explicit section and the second in the in the procedure?

Dim ContNumItems As Collection
Set ContNumItems = New Collection

… A COUPLE THOUGHTS about my approach to this project …

1) Each Item in the Collection ‘ContNumItems’ is a reference to a single shipping unit or piece.

2) ContNum references a unique Production Control Number for a specific piece.

3) There will be only one Collection for a Contract/Job. The Collection and its data needs to able to span multiple drawing files.

4) The collection and the data within it needs to be re-created (except when a ‘locking feature/mechanism’ is toggled ‘On’) every time a command button is clicked in my VBA application by the user. When it is ‘locked’ the command button can be disabled.

5) The data stored in the Collection once created will get shown to the user in a ListView control… (I have much of the ListView Control working with ‘test’ data.)
I need to pad the Control Number for display purposes only with leading ‘000’ so the ListView column header first column ‘when clicked’ will sort the data as I want. (e.g. 0001, 0002, 0003 … 9997, 9998, 9999)

6) Once the ‘locking mechanism’ is toggle ‘On’ the data will be exported to a comma delimited .CSV file (via a command button pick by the user)

7) If the ‘Lock’ is on and the .CSV file has been created, subsequent runs of my application will initialize the Collection ‘ContNumItems’ and fill the data from what is in the .CSV file which should be consistent with what is in the drawing files.
0 Likes
Message 14 of 26

Anonymous
Not applicable
FWIW,

It is a bad idea to use the "shortcut" Dim As New .

This means that you can inadvertently create a new object when you don't
really want one, due to code mistakes.

Far better to:
Dim myCollect as Collection
Set myCollect = New Collection

This explicitly creates the new collection to variable. As you can see from
my posted code, that is what I did. As far as the key value goes, I assumed
that you had explicitly created the new instance of the collection somewhere
else, and just failed to post that part of the code. My bad.

--
R. Robert Bell


wrote in message news:5442368@discussion.autodesk.com...
That was it! ...

In the Option Explicit section I edited:
Dim ContNumItems As Collection
' instead to...
Dim ContNumItems As New Collection

.and it worked without error, but only the first time ... when I ran it a
second time I got: "Run-time error '457': This key is already associated
with an element of this collection" - Are collections persistent within the
instance of the AutoCAD editor?
0 Likes
Message 15 of 26

mdhutchinson
Advisor
Advisor
Thanks for the suggestion... I will explicitly create the new collection to a variable...

one question though... I want this collection to be accessible thoughout my application's feature set ... so where should I dim the collection in my application's modules (only one of these thoughout a given project)...
...see my other post in answer to MP.

The collection needs to be initialy filled from data in the drawing. But once 'locked' and exported to a CSV file... will be filled from data in the CSV file... ( I could create XDATA in each dwg)... but in any case I want the CSV file and the data in the Dwg files to be strictly identical.
0 Likes
Message 16 of 26

Anonymous
Not applicable
Without seeing the project explorer structure, I can only guess, but I would
say you need to declare a public module-level variable, in the module that
you use to start the application.

Why are you using a .csv rather than a true database?

--
R. Robert Bell


wrote in message news:5442460@discussion.autodesk.com...
Thanks for the suggestion... I will explicitly create the new collection to
a variable...

one question though... I want this collection to be accessible thoughout my
application's feature set ... so where should I dim the collection in my
application's modules (only one of these thoughout a given project)...
...see my other post in answer to MP.

The collection needs to be initialy filled from data in the drawing. But
once 'locked' and exported to a CSV file... will be filled from data in the
CSV file... ( I could create XDATA in each dwg)... but in any case I want
the CSV file and the data in the Dwg files to be strictly identical.
0 Likes
Message 17 of 26

mdhutchinson
Advisor
Advisor
... good question!

I am handing off the data in CSV file format for another in-house app... written by an outside consultant ... the app is an Access application that has enterprise wide impact...

I could I suppose link into this application's data structure and write it directly... except for two things:
1) I don't have the expertise to do this. although I suppose I could learn it, indeed want to... but...
2) the company for which I work or the outside consultant may not want me messin' with this data.

The CSV file is the mechanism that was mutually agreed to by me and the consultant.

... this app I am writing is my first in VBA (with a long history in Lisp and VisualLisp)... I am learning a ton of new stuff -- greatly due to this discussion group...
0 Likes
Message 18 of 26

Anonymous
Not applicable
As long as you have a good reason... ;^)

It would be easy to search for the .csv, and if not found, only populate
from the current drawing.

--
R. Robert Bell


wrote in message news:5442479@discussion.autodesk.com...
... good question!

I am handing off the data in CSV file format for another in-house app...
written by an outside consultant ... the app is an Access application that
has enterprise wide impact...

I could I suppose link into this application's data structure and write it
directly... except for two things:
1) I don't have the expertise to do this. although I suppose I could learn
it, indeed want to... but...
2) the company for which I work or the outside consultant may not want me
messin' with this data.

The CSV file is the mechanism that was mutually agreed to by me and the
consultant.

... this app I am writing is my first in VBA (with a long history in Lisp
and VisualLisp)... I am learning a ton of new stuff -- greatly due to this
discussion group...
0 Likes
Message 19 of 26

mdhutchinson
Advisor
Advisor
yes... that is what I am heading towards...
only... other thing is that the data initially will be populated from 1 or more dwg files ... the data in the CSV file needs to be identical to what is in the drawing files, attributed blocks, and dwg geometry (length and width of region objects).

... do you think it would be well to also build my own dictionary to hold the data also within the individual dwgs?
another challenge is some of the regions will be inline with the WCS and some will not... so I have to devise a way to get the length and width from the geometry rotated away from the WCS...
... as you know the 'boundingbox' method doesn't work well with rotated geometry.

I think I have some logic worked out to write the algorithm but I am not ready to write it yet.
0 Likes
Message 20 of 26

Anonymous
Not applicable
That question deserves careful consideration. You need to account for normal
CAD operations such as copy and erase with whatever approach you take.

--
R. Robert Bell


wrote in message news:5442525@discussion.autodesk.com...
yes... that is what I am heading towards...
only... other thing is that the data initially will be populated from 1 or
more dwg files ... the data in the CSV file needs to be identical to what is
in the drawing files, attributed blocks, and dwg geometry (length and width
of region objects).

... do you think it would be well to also build my own dictionary to hold
the data also within the individual dwgs?
another challenge is some of the regions will be inline with the WCS and
some will not... so I have to devise a way to get the length and width from
the geometry rotated away from the WCS...
... as you know the 'boundingbox' method doesn't work well with rotated
geometry.

I think I have some logic worked out to write the algorithm but I am not
ready to write it yet.
0 Likes