<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to fill a dynamic array? in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854590#M28669</link>
    <description>The other attachment which shows the unique value I want to add...</description>
    <pubDate>Fri, 05 Jan 2007 14:47:36 GMT</pubDate>
    <dc:creator>mdhutchinson</dc:creator>
    <dc:date>2007-01-05T14:47:36Z</dc:date>
    <item>
      <title>How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854580#M28659</link>
      <description>I have an application that:&lt;BR /&gt;
&lt;BR /&gt;
I am still a bit green with VBA… this is only my first application… but so far (slowly) so good!&lt;BR /&gt;
&lt;BR /&gt;
Put as short as is possible, the application …&lt;BR /&gt;
Activates currently open documents...&lt;BR /&gt;
Within each dwg...&lt;BR /&gt;
   ... the app builds a select set of closed polygonal block (3 or 4 or so) ...&lt;BR /&gt;
      Then parses through each closed polygonal block...&lt;BR /&gt;
    and gets other block references (10 to 34 or more) that are positioned within &lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
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:&lt;BR /&gt;
&lt;BR /&gt;
Cnt#AttribVal1, AttribVal2, AttribVal3, Lgth, Wdth, Dpth, Handle, Document&lt;BR /&gt;
&lt;BR /&gt;
… 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…&lt;BR /&gt;
&lt;BR /&gt;
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?&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
So I guess to summarize my questions are two:&lt;BR /&gt;
&lt;BR /&gt;
1).  How can I define a two dimensional dynamic array that can grow to hold variable records/rows and 8 columns?&lt;BR /&gt;
&lt;BR /&gt;
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?</description>
      <pubDate>Thu, 04 Jan 2007 17:53:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854580#M28659</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-04T17:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854581#M28660</link>
      <description>Personally, I would use a class module to define an object that stores the &lt;BR /&gt;
data for each object, and store those objects in a collection. I would not &lt;BR /&gt;
use an array.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5441250@discussion.autodesk.com...&lt;BR /&gt;
I have an application that:&lt;BR /&gt;
&lt;BR /&gt;
I am still a bit green with VBA. this is only my first application. but so &lt;BR /&gt;
far (slowly) so good!&lt;BR /&gt;
&lt;BR /&gt;
Put as short as is possible, the application .&lt;BR /&gt;
Activates currently open documents...&lt;BR /&gt;
Within each dwg...&lt;BR /&gt;
   ... the app builds a select set of closed polygonal block (3 or 4 or so) &lt;BR /&gt;
...&lt;BR /&gt;
      Then parses through each closed polygonal block...&lt;BR /&gt;
    and gets other block references (10 to 34 or more) that are positioned &lt;BR /&gt;
within&lt;BR /&gt;
them. The collected multiple blocks are sorted by polygonal block's OCS. The &lt;BR /&gt;
sorted block's number attribute value is incremented starting from the first &lt;BR /&gt;
dwg to the last open dwg.&lt;BR /&gt;
&lt;BR /&gt;
After all the dwgs are activated and the objects are processed... I want to &lt;BR /&gt;
fill a ListView control with collected data... where each block is &lt;BR /&gt;
represented as a row in the ListView control.  Each row in the ListView &lt;BR /&gt;
control will be filled with (8 columns) as follows:&lt;BR /&gt;
&lt;BR /&gt;
Cnt#AttribVal1, AttribVal2, AttribVal3, Lgth, Wdth, Dpth, Handle, Document&lt;BR /&gt;
&lt;BR /&gt;
. So. Obviously, I know how many columns there are, but I don't know until &lt;BR /&gt;
all is process how many objects there will be . there could be several &lt;BR /&gt;
hundred and for larger projects perhaps a thousand or more.&lt;BR /&gt;
&lt;BR /&gt;
As I understand it . you can ReDim ONLY the upper bound of the last &lt;BR /&gt;
dimension last dimension of the dynamic array. so, . how might I approach &lt;BR /&gt;
this such to collect all the data where the rows may vary (as many as a &lt;BR /&gt;
thousand worst case perhaps), then fill the ListView control after all the &lt;BR /&gt;
data is collected?&lt;BR /&gt;
&lt;BR /&gt;
Also, I think I've experimented enough with the ListView control, and I now &lt;BR /&gt;
know how to fill it . also, it looks that once filled, the control itself &lt;BR /&gt;
holds the data and the variable doesn't have to be maintained, instead I can &lt;BR /&gt;
retrieved the data straight from the control itself. therefore perhaps I &lt;BR /&gt;
only need to populate a dynamic array for each drawing processed, then put &lt;BR /&gt;
the data into the control. then process the next drawing and reuse the &lt;BR /&gt;
dynamic array.&lt;BR /&gt;
&lt;BR /&gt;
So I guess to summarize my questions are two:&lt;BR /&gt;
&lt;BR /&gt;
1).  How can I define a two dimensional dynamic array that can grow to hold &lt;BR /&gt;
variable records/rows and 8 columns?&lt;BR /&gt;
&lt;BR /&gt;
2). Would it best to collect all the data and fill the ListView afterwards. &lt;BR /&gt;
or input the data into the ListView control after each drawing has been &lt;BR /&gt;
processed?&lt;/HUTCH&gt;</description>
      <pubDate>Thu, 04 Jan 2007 18:04:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854581#M28660</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-04T18:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854582#M28661</link>
      <description>Are you referring to Creating Dynamic Data Structures Using Class Modules such as what is shown in the VBA Developer's Handbook chapter 8?&lt;BR /&gt;
&lt;BR /&gt;
http://www.developershandbook.com/Downloads/1951c06.pdf&lt;BR /&gt;
... okay... I am green... and I need some tender care to get this stuff...&lt;BR /&gt;
&lt;BR /&gt;
how can I get started with this...&lt;BR /&gt;
&lt;BR /&gt;
let's see... I need to create an Object for each 'row' ... basically&lt;BR /&gt;
&lt;BR /&gt;
The each object will have Properties as follows:&lt;BR /&gt;
&lt;BR /&gt;
ControlNum&lt;BR /&gt;
ProductCode&lt;BR /&gt;
PceLength&lt;BR /&gt;
PceWidth&lt;BR /&gt;
PceDepth&lt;BR /&gt;
DocumentFoundIn&lt;BR /&gt;
MarkHandle&lt;BR /&gt;
&lt;BR /&gt;
... am I on the right track? ... how do I proceed?&lt;BR /&gt;
Is there some sample I might look at?</description>
      <pubDate>Thu, 04 Jan 2007 18:38:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854582#M28661</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-04T18:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854583#M28662</link>
      <description>&lt;HUTCH&gt; wrote in message news:5441332@discussion.autodesk.com...&lt;BR /&gt;
Are you referring to Creating Dynamic Data Structures Using Class Modules&lt;BR /&gt;
such as what is shown in the VBA Developer's Handbook chapter 8?&lt;BR /&gt;
&lt;BR /&gt;
http://www.developershandbook.com/Downloads/1951c06.pdf&lt;BR /&gt;
... okay... I am green... and I need some tender care to get this stuff...&lt;BR /&gt;
&lt;BR /&gt;
how can I get started with this...&lt;BR /&gt;
&lt;BR /&gt;
let's see... I need to create an Object for each 'row' ... basically&lt;BR /&gt;
&lt;BR /&gt;
The each object will have Properties as follows:&lt;BR /&gt;
&lt;BR /&gt;
ControlNum&lt;BR /&gt;
ProductCode&lt;BR /&gt;
PceLength&lt;BR /&gt;
PceWidth&lt;BR /&gt;
PceDepth&lt;BR /&gt;
DocumentFoundIn&lt;BR /&gt;
MarkHandle&lt;BR /&gt;
&lt;BR /&gt;
... am I on the right track? ... how do I proceed?&lt;BR /&gt;
Is there some sample I might look at?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
quick sample to give idea hopefully ... there are tons of examples in the&lt;BR /&gt;
help files and google on this group and msdn for stuff about classes&lt;BR /&gt;
&lt;BR /&gt;
briefly in vba create a new class module&lt;BR /&gt;
Menu --&amp;gt; Insert|Class module&lt;BR /&gt;
Name it whatever you want to call it eg "cInfo"&lt;BR /&gt;
give it your properties mentioned above by writing property accessors (Get,&lt;BR /&gt;
Let, Set)&lt;BR /&gt;
define private member variables at top of module to hold values for each&lt;BR /&gt;
property&lt;BR /&gt;
eg:&lt;BR /&gt;
Private mlProductCode as long&lt;BR /&gt;
&lt;BR /&gt;
define propert Let or set(if object) to input value&lt;BR /&gt;
Property Let ProductCode(Data as Long)&lt;BR /&gt;
    mlProductCode = Data&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
define property Get to retrieve value&lt;BR /&gt;
Property Get ProductCode() as Long&lt;BR /&gt;
   ProductCode = mlProductCode&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
In main program Dim a variable for your class&lt;BR /&gt;
Dim oInfo as cInfo&lt;BR /&gt;
Dim mcolInfoItems as collection 'to hold all your instances&lt;BR /&gt;
&lt;BR /&gt;
In programs loop&lt;BR /&gt;
Do While ...&lt;BR /&gt;
    'create instance for this "row"&lt;BR /&gt;
    Set oInfo = New cInfo&lt;BR /&gt;
    'set all properties&lt;BR /&gt;
    oInfo.ProductCode = lThisProductCode&lt;BR /&gt;
    'etc with other properties&lt;BR /&gt;
    'add object to collection&lt;BR /&gt;
    mcolInfoItems.Add oInfo&lt;BR /&gt;
Loop&lt;BR /&gt;
&lt;BR /&gt;
then when all items are collected&lt;BR /&gt;
For Each oInfo in mcolInfoItems&lt;BR /&gt;
'do whatever&lt;BR /&gt;
Next oInfo&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
hth&lt;BR /&gt;
Mark&lt;BR /&gt;
ps, is it possible to post as plain text? that way replies will show your&lt;BR /&gt;
text as being the "replied to" block of text&lt;/HUTCH&gt;</description>
      <pubDate>Thu, 04 Jan 2007 19:08:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854583#M28662</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-04T19:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854584#M28663</link>
      <description>MP...&lt;BR /&gt;
&lt;BR /&gt;
I am writting code in my app now to create and minipulate this collection.&lt;BR /&gt;
&lt;BR /&gt;
Anyway... is this the right idea for the Class modeule&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Private ContNumItems As Collection                      'collection of ContNumItems&lt;BR /&gt;
Private itmContNum As Integer                           'ControlNumber&lt;BR /&gt;
Private itmProductCode As String                        'PCode&lt;BR /&gt;
Private itmPceMrk As String                             'Mark&lt;BR /&gt;
Private itmPceLength As Double                          'Length&lt;BR /&gt;
Private itmPceWidth As Double                           'Width&lt;BR /&gt;
Private itmPceDepth As Double                           'Depth&lt;BR /&gt;
Private itmMrkBlkDoc As String                          'DwgName&lt;BR /&gt;
Private itmMrkBlkHandle As AcadBlockReference.Handle    'Object.Handle&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|**************** Let &amp;amp; Get properties -- Control Number ********************|&lt;BR /&gt;
Property Let ContNum(data As Integer)&lt;BR /&gt;
 itmContNum = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get ContNum() As Integer&lt;BR /&gt;
    ContNum = itmContNum&lt;BR /&gt;
End Property&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Product Code ********************|&lt;BR /&gt;
Property Let ProductCode(data As String)&lt;BR /&gt;
    itmProductCode = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get ProductCode() As String&lt;BR /&gt;
    ProductCode = itmProductCode&lt;BR /&gt;
End Property&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Mark **********************|&lt;BR /&gt;
Property Let PceMrk(data As String)&lt;BR /&gt;
    PceMrk = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceMrk() As String&lt;BR /&gt;
    PceMrk = itmPceMrk&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Length ********************|&lt;BR /&gt;
Property Let PceLength(data As Double)&lt;BR /&gt;
    itmPceLength = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceLength() As Double&lt;BR /&gt;
    PceLength = itmPceLength&lt;BR /&gt;
End Property&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Width *********************|&lt;BR /&gt;
Property Let PceWidth(data As Double)&lt;BR /&gt;
    itmPceWidth = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceWidth() As Double&lt;BR /&gt;
    PceWidth = itmPceWidth&lt;BR /&gt;
End Property&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Depth *********************|&lt;BR /&gt;
Property Let PceDepth(data As Double)&lt;BR /&gt;
    itmPceDepth = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceDepth() As Double&lt;BR /&gt;
    PceDepth = itmPceDepth&lt;BR /&gt;
End Property&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|**************** Let &amp;amp; Get properties -- BlockRef Handle *******************|&lt;BR /&gt;
Property Let MrkBlkHandle(data As String)&lt;BR /&gt;
    itmMrkBlkHandle = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get MrkBlkHandle() As String&lt;BR /&gt;
    MrkBlkHandle = itmMrkBlkHandle&lt;BR /&gt;
End Property&lt;BR /&gt;
'|****************************************************************************|&lt;BR /&gt;
'|************ Let &amp;amp; Get properties -- BlockReference Handle *****************|&lt;BR /&gt;
Property Let MrkBlkDoc(data As String)&lt;BR /&gt;
    itmMrkBlkDoc = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get MrkBlkDoc() As String&lt;BR /&gt;
    MrkBlkDoc = itmMrkBlkDoc&lt;BR /&gt;
End Property</description>
      <pubDate>Thu, 04 Jan 2007 22:17:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854584#M28663</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-04T22:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854585#M28664</link>
      <description>Revised Class Module is Below....&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
see the noted line indicated by..." &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE "&lt;BR /&gt;
&lt;BR /&gt;
… but per your instructions ... if (of course), I am interpreting it correctly 8-):&lt;BR /&gt;
‘ your instruction ******************&lt;BR /&gt;
’In programs loop&lt;BR /&gt;
Do While ...&lt;BR /&gt;
'create instance for this "row"&lt;BR /&gt;
Set oInfo = New cInfo&lt;BR /&gt;
'set all properties&lt;BR /&gt;
oInfo.ProductCode = lThisProductCode&lt;BR /&gt;
'etc with other properties&lt;BR /&gt;
'add object to collection&lt;BR /&gt;
mcolInfoItems.Add oInfo  ‘ my code fails here?  What am I missing?&lt;BR /&gt;
Loop&lt;BR /&gt;
’ end of your instruction&lt;BR /&gt;
&lt;BR /&gt;
My line to add the info to the collection fails... (see below)&lt;BR /&gt;
If I comment out this line my code runs to completion:&lt;BR /&gt;
&lt;BR /&gt;
For incMrk = 0 To ssMrkSorted.Count - 1 ' loop thru sorted Mark Block Selection Set&lt;BR /&gt;
Set blkMrk = ssMrkSorted.item(incMrk) ' for each Mark Block&lt;BR /&gt;
&lt;BR /&gt;
Set CntNumItm = New ContNumItem&lt;BR /&gt;
CntNumItm.ContNum = incCntlNum ' actual data&lt;BR /&gt;
CntNumItm.ProductCode = "WP1" ' test data&lt;BR /&gt;
CntNumItm.PceMrk = "W10A" ' test data&lt;BR /&gt;
CntNumItm.PceLength = 300.86 ' test data&lt;BR /&gt;
CntNumItm.PceWidth = 144.5 ' test data&lt;BR /&gt;
CntNumItm.PceDepth = 12.75 ' test data&lt;BR /&gt;
CntNumItm.MrkBlkDoc = blkMrk.Document.Name ' actual data&lt;BR /&gt;
CntNumItm.MrkBlkHandle = blkMrk.Handle ' actula data&lt;BR /&gt;
&lt;BR /&gt;
ContNumItems.Add CntNumItm  '&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE --- If I comment this line out it runs fine to completion?&lt;BR /&gt;
&lt;BR /&gt;
Debug.Print blkMrk.Handle ' get the handle&lt;BR /&gt;
Debug.Print TypeName(blkMrk.Handle) ' check the data type&lt;BR /&gt;
Debug.Print blkMrk.Document.Name ' get the owning document&lt;BR /&gt;
Debug.Print TypeName(blkMrk.Document.Name) ' check the data type&lt;BR /&gt;
&lt;BR /&gt;
Call SetCntlNumAtt(blkMrk, incCntlNum) ' set the control number&lt;BR /&gt;
incCntlNum = incCntlNum + 1 ' increment the Control Number&lt;BR /&gt;
Next incMrk&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
‘******* the class module (this seems to work as it should)&lt;BR /&gt;
'************************************************************&lt;BR /&gt;
'************************************************************&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Private itmContNum As Integer 'ControlNumber&lt;BR /&gt;
Private itmProductCode As String 'PCode&lt;BR /&gt;
Private itmPceMrk As String 'Mark&lt;BR /&gt;
Private itmPceLength As Double 'Length&lt;BR /&gt;
Private itmPceWidth As Double 'Width&lt;BR /&gt;
Private itmPceDepth As Double 'Depth&lt;BR /&gt;
Private itmMrkBlkDoc As String 'DwgName&lt;BR /&gt;
Private itmMrkBlkHandle As String 'Object.Handle&lt;BR /&gt;
'|*********************************************************** *****************|&lt;BR /&gt;
'|**************** Let &amp;amp; Get properties -- Control Number ********************|&lt;BR /&gt;
Property Let ContNum(data As Integer)&lt;BR /&gt;
itmContNum = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get ContNum() As Integer&lt;BR /&gt;
ContNum = itmContNum&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** ***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Product Code ********************|&lt;BR /&gt;
Property Let ProductCode(data As String)&lt;BR /&gt;
itmProductCode = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get ProductCode() As String&lt;BR /&gt;
ProductCode = itmProductCode&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** ***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Mark **********************|&lt;BR /&gt;
Property Let PceMrk(data As String)&lt;BR /&gt;
itmPceMrk = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceMrk() As String&lt;BR /&gt;
PceMrk = itmPceMrk&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
'|************************************************************* ***************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Length ********************|&lt;BR /&gt;
Property Let PceLength(data As Double)&lt;BR /&gt;
itmPceLength = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceLength() As Double&lt;BR /&gt;
PceLength = itmPceLength&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** ***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Width *********************|&lt;BR /&gt;
Property Let PceWidth(data As Double)&lt;BR /&gt;
itmPceWidth = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceWidth() As Double&lt;BR /&gt;
PceWidth = itmPceWidth&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** ***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Depth *********************|&lt;BR /&gt;
Property Let PceDepth(data As Double)&lt;BR /&gt;
itmPceDepth = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceDepth() As Double&lt;BR /&gt;
PceDepth = itmPceDepth&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** ***********|&lt;BR /&gt;
'|**************** Let &amp;amp; Get properties -- BlockRef Handle *******************|&lt;BR /&gt;
Property Let MrkBlkHandle(data As String)&lt;BR /&gt;
itmMrkBlkHandle = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get MrkBlkHandle() As String&lt;BR /&gt;
MrkBlkHandle = itmMrkBlkHandle&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** ***********|&lt;BR /&gt;
'|************ Let &amp;amp; Get properties -- BlockReference Handle *****************|&lt;BR /&gt;
Property Let MrkBlkDoc(data As String)&lt;BR /&gt;
itmMrkBlkDoc = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get MrkBlkDoc() As String&lt;BR /&gt;
MrkBlkDoc = itmMrkBlkDoc&lt;BR /&gt;
End Property</description>
      <pubDate>Thu, 04 Jan 2007 23:40:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854585#M28664</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-04T23:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854586#M28665</link>
      <description>Give a unique index value for each item as you add it.&lt;BR /&gt;
&lt;BR /&gt;
Sub Test()&lt;BR /&gt;
  Dim myItems As Collection&lt;BR /&gt;
  Set myItems = New Collection&lt;BR /&gt;
&lt;BR /&gt;
  Dim i As Long&lt;BR /&gt;
  For i = 0 To 9&lt;BR /&gt;
    Dim aItem As Test&lt;BR /&gt;
    Set aItem = New Test&lt;BR /&gt;
    aItem.Name = "Item" &amp;amp; CStr(i)&lt;BR /&gt;
    myItems.Add aItem, CStr(i)&lt;BR /&gt;
  Next i&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5441811@discussion.autodesk.com...&lt;BR /&gt;
Revised Class Module is Below....&lt;BR /&gt;
&lt;BR /&gt;
The class module seems to work so far... the locals window shows properties &lt;BR /&gt;
getting set correctly... but when I go to add the data to the collection it &lt;BR /&gt;
fails.&lt;BR /&gt;
see the noted line indicated by..." &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE "&lt;BR /&gt;
&lt;BR /&gt;
. but per your instructions ... if (of course), I am interpreting it &lt;BR /&gt;
correctly 8-):&lt;BR /&gt;
' your instruction ******************&lt;BR /&gt;
'In programs loop&lt;BR /&gt;
Do While ...&lt;BR /&gt;
'create instance for this "row"&lt;BR /&gt;
Set oInfo = New cInfo&lt;BR /&gt;
'set all properties&lt;BR /&gt;
oInfo.ProductCode = lThisProductCode&lt;BR /&gt;
'etc with other properties&lt;BR /&gt;
'add object to collection&lt;BR /&gt;
mcolInfoItems.Add oInfo  ' my code fails here?  What am I missing?&lt;BR /&gt;
Loop&lt;BR /&gt;
' end of your instruction&lt;BR /&gt;
&lt;BR /&gt;
My line to add the info to the collection fails... (see below)&lt;BR /&gt;
If I comment out this line my code runs to completion:&lt;BR /&gt;
&lt;BR /&gt;
For incMrk = 0 To ssMrkSorted.Count - 1 ' loop thru sorted Mark Block &lt;BR /&gt;
Selection Set&lt;BR /&gt;
Set blkMrk = ssMrkSorted.item(incMrk) ' for each Mark Block&lt;BR /&gt;
&lt;BR /&gt;
Set CntNumItm = New ContNumItem&lt;BR /&gt;
CntNumItm.ContNum = incCntlNum ' actual data&lt;BR /&gt;
CntNumItm.ProductCode = "WP1" ' test data&lt;BR /&gt;
CntNumItm.PceMrk = "W10A" ' test data&lt;BR /&gt;
CntNumItm.PceLength = 300.86 ' test data&lt;BR /&gt;
CntNumItm.PceWidth = 144.5 ' test data&lt;BR /&gt;
CntNumItm.PceDepth = 12.75 ' test data&lt;BR /&gt;
CntNumItm.MrkBlkDoc = blkMrk.Document.Name ' actual data&lt;BR /&gt;
CntNumItm.MrkBlkHandle = blkMrk.Handle ' actula data&lt;BR /&gt;
&lt;BR /&gt;
ContNumItems.Add CntNumItm  '&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE --- If I comment this line &lt;BR /&gt;
out it runs fine to completion?&lt;BR /&gt;
&lt;BR /&gt;
Debug.Print blkMrk.Handle ' get the handle&lt;BR /&gt;
Debug.Print TypeName(blkMrk.Handle) ' check the data type&lt;BR /&gt;
Debug.Print blkMrk.Document.Name ' get the owning document&lt;BR /&gt;
Debug.Print TypeName(blkMrk.Document.Name) ' check the data type&lt;BR /&gt;
&lt;BR /&gt;
Call SetCntlNumAtt(blkMrk, incCntlNum) ' set the control number&lt;BR /&gt;
incCntlNum = incCntlNum + 1 ' increment the Control Number&lt;BR /&gt;
Next incMrk&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'******* the class module (this seems to work as it should)&lt;BR /&gt;
'************************************************************&lt;BR /&gt;
'************************************************************&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Private itmContNum As Integer 'ControlNumber&lt;BR /&gt;
Private itmProductCode As String 'PCode&lt;BR /&gt;
Private itmPceMrk As String 'Mark&lt;BR /&gt;
Private itmPceLength As Double 'Length&lt;BR /&gt;
Private itmPceWidth As Double 'Width&lt;BR /&gt;
Private itmPceDepth As Double 'Depth&lt;BR /&gt;
Private itmMrkBlkDoc As String 'DwgName&lt;BR /&gt;
Private itmMrkBlkHandle As String 'Object.Handle&lt;BR /&gt;
'|*********************************************************** &lt;BR /&gt;
*****************|&lt;BR /&gt;
'|**************** Let &amp;amp; Get properties -- Control Number &lt;BR /&gt;
********************|&lt;BR /&gt;
Property Let ContNum(data As Integer)&lt;BR /&gt;
itmContNum = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get ContNum() As Integer&lt;BR /&gt;
ContNum = itmContNum&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** &lt;BR /&gt;
***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Product Code &lt;BR /&gt;
********************|&lt;BR /&gt;
Property Let ProductCode(data As String)&lt;BR /&gt;
itmProductCode = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get ProductCode() As String&lt;BR /&gt;
ProductCode = itmProductCode&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** &lt;BR /&gt;
***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Mark &lt;BR /&gt;
**********************|&lt;BR /&gt;
Property Let PceMrk(data As String)&lt;BR /&gt;
itmPceMrk = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceMrk() As String&lt;BR /&gt;
PceMrk = itmPceMrk&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
'|************************************************************* &lt;BR /&gt;
***************|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Length &lt;BR /&gt;
********************|&lt;BR /&gt;
Property Let PceLength(data As Double)&lt;BR /&gt;
itmPceLength = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceLength() As Double&lt;BR /&gt;
PceLength = itmPceLength&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** &lt;BR /&gt;
***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Width &lt;BR /&gt;
*********************|&lt;BR /&gt;
Property Let PceWidth(data As Double)&lt;BR /&gt;
itmPceWidth = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceWidth() As Double&lt;BR /&gt;
PceWidth = itmPceWidth&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** &lt;BR /&gt;
***********|&lt;BR /&gt;
'|****************** Let &amp;amp; Get properties -- Piece Depth &lt;BR /&gt;
*********************|&lt;BR /&gt;
Property Let PceDepth(data As Double)&lt;BR /&gt;
itmPceDepth = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get PceDepth() As Double&lt;BR /&gt;
PceDepth = itmPceDepth&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** &lt;BR /&gt;
***********|&lt;BR /&gt;
'|**************** Let &amp;amp; Get properties -- BlockRef Handle &lt;BR /&gt;
*******************|&lt;BR /&gt;
Property Let MrkBlkHandle(data As String)&lt;BR /&gt;
itmMrkBlkHandle = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get MrkBlkHandle() As String&lt;BR /&gt;
MrkBlkHandle = itmMrkBlkHandle&lt;BR /&gt;
End Property&lt;BR /&gt;
'|***************************************************************** &lt;BR /&gt;
***********|&lt;BR /&gt;
'|************ Let &amp;amp; Get properties -- BlockReference Handle &lt;BR /&gt;
*****************|&lt;BR /&gt;
Property Let MrkBlkDoc(data As String)&lt;BR /&gt;
itmMrkBlkDoc = data&lt;BR /&gt;
End Property&lt;BR /&gt;
Property Get MrkBlkDoc() As String&lt;BR /&gt;
MrkBlkDoc = itmMrkBlkDoc&lt;BR /&gt;
End Property&lt;/HUTCH&gt;</description>
      <pubDate>Fri, 05 Jan 2007 00:21:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854586#M28665</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T00:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854587#M28666</link>
      <description>. Robert Bell" &lt;NOT.ROBERTB&gt; wrote in message&lt;BR /&gt;
news:5441818@discussion.autodesk.com...&lt;BR /&gt;
Give a unique index value for each item as you add it.&lt;BR /&gt;
&lt;BR /&gt;
Sub Test()&lt;BR /&gt;
  Dim myItems As Collection&lt;BR /&gt;
  Set myItems = New Collection&lt;BR /&gt;
&lt;BR /&gt;
  Dim i As Long&lt;BR /&gt;
  For i = 0 To 9&lt;BR /&gt;
    Dim aItem As Test&lt;BR /&gt;
    Set aItem = New Test&lt;BR /&gt;
    aItem.Name = "Item" &amp;amp; CStr(i)&lt;BR /&gt;
    myItems.Add aItem, CStr(i)&lt;BR /&gt;
  Next i&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Hi Robert,&lt;BR /&gt;
I must be missing something here...&lt;BR /&gt;
I'm not seeing something you are seeing...&lt;BR /&gt;
how does that address his question about an error adding a class instance to&lt;BR /&gt;
a collection?&lt;BR /&gt;
You don't *have* to use a key to add items to a collection, unless you want&lt;BR /&gt;
to retrieve them by key rather than by index, do you?&lt;BR /&gt;
&lt;BR /&gt;
ContNumItems.Add CntNumItm  '&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE ---&lt;BR /&gt;
&lt;BR /&gt;
I would wonder what he means by "It fails Here"... what error is he getting?&lt;BR /&gt;
I would think if ContNumItems is dimmed as a collection(which isn't shown in&lt;BR /&gt;
his post) and if it's not Nothing, then his line should work with or without&lt;BR /&gt;
a named key...or what am i missing?&lt;BR /&gt;
I wonder if he has Option Explicit set?&lt;BR /&gt;
&lt;BR /&gt;
Mark&lt;/NOT.ROBERTB&gt;</description>
      <pubDate>Fri, 05 Jan 2007 02:38:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854587#M28666</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T02:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854588#M28667</link>
      <description>&lt;HUTCH&gt; wrote in message news:5441811@discussion.autodesk.com...&lt;BR /&gt;
Revised Class Module is Below....&lt;BR /&gt;
&lt;BR /&gt;
The class module seems to work so far... the locals window shows properties&lt;BR /&gt;
getting set correctly... but when I go to add the data to the collection it&lt;BR /&gt;
fails.&lt;BR /&gt;
see the noted line indicated by..." &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE "&lt;BR /&gt;
&lt;BR /&gt;
. but per your instructions ... if (of course), I am interpreting it&lt;BR /&gt;
correctly 8-):&lt;BR /&gt;
' your instruction ******************&lt;BR /&gt;
'In programs loop&lt;BR /&gt;
Do While ...&lt;BR /&gt;
'create instance for this "row"&lt;BR /&gt;
Set oInfo = New cInfo&lt;BR /&gt;
'set all properties&lt;BR /&gt;
oInfo.ProductCode = lThisProductCode&lt;BR /&gt;
'etc with other properties&lt;BR /&gt;
'add object to collection&lt;BR /&gt;
mcolInfoItems.Add oInfo  ' my code fails here?  What am I missing?&lt;BR /&gt;
Loop&lt;BR /&gt;
' end of your instruction&lt;BR /&gt;
&lt;BR /&gt;
My line to add the info to the collection fails... (see below)&lt;BR /&gt;
If I comment out this line my code runs to completion:&lt;BR /&gt;
ContNumItems.Add CntNumItm  '&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; IT FAILS HERE --- If I comment this line&lt;BR /&gt;
out it runs fine to completion?&lt;BR /&gt;
&lt;BR /&gt;
where is ContNumItems declared and set?&lt;BR /&gt;
what error are you getting when you say "It fails Here"&lt;BR /&gt;
(It's always important to post the error rather than saying something&lt;BR /&gt;
"doesnt' work")&lt;BR /&gt;
do you have Option Explicit at top of module?&lt;BR /&gt;
what are your break on error settings ?&lt;BR /&gt;
do you have an error trap in your routine that tells you the error code ?&lt;/HUTCH&gt;</description>
      <pubDate>Fri, 05 Jan 2007 02:42:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854588#M28667</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T02:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854589#M28668</link>
      <description>thanks so much for the help... &lt;BR /&gt;
&lt;BR /&gt;
To: MP&lt;BR /&gt;
At the top Option Explicit within the module where the flawed code resides I have:&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Dim objss As AcadSelectionSet&lt;BR /&gt;
Dim strName As String&lt;BR /&gt;
Dim CntNumItm As ContNumItem &lt;BR /&gt;
‘ ContNumItem is the name of my class module…&lt;BR /&gt;
‘ where let and get properties are defined.&lt;BR /&gt;
‘ ContNumItems is defined at the option explicit section.&lt;BR /&gt;
Dim ContNumItems As Collection&lt;BR /&gt;
&lt;BR /&gt;
As you can see, I do have an Option Explicit at the top of the module.&lt;BR /&gt;
Assuming you mean General tab of options dialog… My break on error settings are set to the third selection: ‘Break on Unhandled Errors’&lt;BR /&gt;
&lt;BR /&gt;
The error that happens is:&lt;BR /&gt;
Run-time error 91: Object variable or With block variable not set. (see the attached)&lt;BR /&gt;
&lt;BR /&gt;
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… &lt;BR /&gt;
… 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” &amp;amp; Cstr(i).&lt;BR /&gt;
&lt;BR /&gt;
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?...&lt;BR /&gt;
what am I missing?</description>
      <pubDate>Fri, 05 Jan 2007 14:41:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854589#M28668</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-05T14:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854590#M28669</link>
      <description>The other attachment which shows the unique value I want to add...</description>
      <pubDate>Fri, 05 Jan 2007 14:47:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854590#M28669</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-05T14:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854591#M28670</link>
      <description>&lt;HUTCH&gt; wrote in message news:5442240@discussion.autodesk.com...&lt;BR /&gt;
thanks so much for the help...&lt;BR /&gt;
&lt;BR /&gt;
To: MP&lt;BR /&gt;
At the top Option Explicit within the module where the flawed code resides I&lt;BR /&gt;
have:&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Dim objss As AcadSelectionSet&lt;BR /&gt;
Dim strName As String&lt;BR /&gt;
Dim CntNumItm As ContNumItem&lt;BR /&gt;
' ContNumItem is the name of my class module.&lt;BR /&gt;
' where let and get properties are defined.&lt;BR /&gt;
' ContNumItems is defined at the option explicit section.&lt;BR /&gt;
Dim ContNumItems As Collection&lt;BR /&gt;
&lt;BR /&gt;
As you can see, I do have an Option Explicit at the top&lt;BR /&gt;
of the module.&lt;BR /&gt;
&lt;BR /&gt;
That's a good thing &lt;G&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Assuming you mean General tab of options dialog. My break on error settings&lt;BR /&gt;
are set to the third selection: 'Break on Unhandled Errors'&lt;BR /&gt;
&lt;BR /&gt;
That's also good.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The error that happens is:&lt;BR /&gt;
Run-time error 91: Object variable or With block variable not set. (see the&lt;BR /&gt;
attached)&lt;BR /&gt;
&lt;BR /&gt;
So there's your answer, an object variable was not set!!!&lt;BR /&gt;
Which one?&lt;BR /&gt;
The one at the line that threw the error.&lt;BR /&gt;
ContNumItems.Add xxx&lt;BR /&gt;
What is ContNumItems ?&lt;BR /&gt;
at this point its' Nothing because you haven't set it yet....&lt;BR /&gt;
above where you have&lt;BR /&gt;
Dim ContNumItems As Collection&lt;BR /&gt;
you need&lt;BR /&gt;
Set ContNumItems = New Collection&lt;BR /&gt;
now it's Something &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; and the error goes away...I hope &lt;VBG&gt;&lt;BR /&gt;
&lt;BR /&gt;
a general note...if you really have those variables at the top of your&lt;BR /&gt;
module then they're available to all functions in that module which may not&lt;BR /&gt;
be what you want&lt;BR /&gt;
it is generally recommended to give variables the most local scope possible&lt;BR /&gt;
so if they're just used in the function you're working on now, move them&lt;BR /&gt;
into that function.&lt;BR /&gt;
as it is now it's possible you set ContNumItems = New Collection in one&lt;BR /&gt;
function, then somewhere else Set ContNumItems = Nothing, then later, try to&lt;BR /&gt;
add something to it....&lt;BR /&gt;
You probably *arent'* doing that...but it's possible which is why it's&lt;BR /&gt;
recommended to keep them as local as possible to avoid inadvertant bugs...&lt;BR /&gt;
:-)&lt;BR /&gt;
hth&lt;BR /&gt;
Mark&lt;/VBG&gt;&lt;/G&gt;&lt;/HUTCH&gt;</description>
      <pubDate>Fri, 05 Jan 2007 15:26:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854591#M28670</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T15:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854592#M28671</link>
      <description>That was it! ...&lt;BR /&gt;
&lt;BR /&gt;
In the Option Explicit section I edited:&lt;BR /&gt;
Dim ContNumItems As Collection&lt;BR /&gt;
' instead to... &lt;BR /&gt;
Dim ContNumItems As New Collection&lt;BR /&gt;
&lt;BR /&gt;
…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? &lt;BR /&gt;
&lt;BR /&gt;
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) … &lt;BR /&gt;
&lt;BR /&gt;
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). &lt;BR /&gt;
What is the data type of the ‘key’?  … string or integer?&lt;BR /&gt;
&lt;BR /&gt;
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?).&lt;BR /&gt;
&lt;BR /&gt;
Question:  Should I have both of these lines with the first in the option explicit section and the second in the in the procedure?&lt;BR /&gt;
&lt;BR /&gt;
Dim ContNumItems As Collection&lt;BR /&gt;
Set ContNumItems = New Collection&lt;BR /&gt;
&lt;BR /&gt;
… A COUPLE THOUGHTS about my approach to this project …&lt;BR /&gt;
&lt;BR /&gt;
1) Each Item in the Collection ‘ContNumItems’ is a reference to a single shipping unit or piece.&lt;BR /&gt;
&lt;BR /&gt;
2) ContNum references a unique Production Control Number for a specific piece.&lt;BR /&gt;
&lt;BR /&gt;
3) There will be only one Collection for a Contract/Job. The Collection and its data needs to able to span multiple drawing files. &lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
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.)&lt;BR /&gt;
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) &lt;BR /&gt;
&lt;BR /&gt;
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)&lt;BR /&gt;
&lt;BR /&gt;
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.</description>
      <pubDate>Fri, 05 Jan 2007 16:29:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854592#M28671</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-05T16:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854593#M28672</link>
      <description>FWIW,&lt;BR /&gt;
&lt;BR /&gt;
It is a bad idea to use the "shortcut" Dim &lt;WHATEVER&gt; As New &lt;WHATEVER&gt;.&lt;BR /&gt;
&lt;BR /&gt;
This means that you can inadvertently create a new object when you don't &lt;BR /&gt;
really want one, due to code mistakes.&lt;BR /&gt;
&lt;BR /&gt;
Far better to:&lt;BR /&gt;
Dim myCollect as Collection&lt;BR /&gt;
Set myCollect = New Collection&lt;BR /&gt;
&lt;BR /&gt;
This explicitly creates the new collection to variable. As you can see from &lt;BR /&gt;
my posted code, that is what I did. As far as the key value goes, I assumed &lt;BR /&gt;
that you had explicitly created the new instance of the collection somewhere &lt;BR /&gt;
else, and just failed to post that part of the code. My bad.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5442368@discussion.autodesk.com...&lt;BR /&gt;
That was it! ...&lt;BR /&gt;
&lt;BR /&gt;
In the Option Explicit section I edited:&lt;BR /&gt;
Dim ContNumItems As Collection&lt;BR /&gt;
' instead to...&lt;BR /&gt;
Dim ContNumItems As New Collection&lt;BR /&gt;
&lt;BR /&gt;
.and it worked without error, but only the first time ... when I ran it a &lt;BR /&gt;
second time I got: "Run-time error '457': This key is already associated &lt;BR /&gt;
with an element of this collection" - Are collections persistent within the &lt;BR /&gt;
instance of the AutoCAD editor?&lt;/HUTCH&gt;&lt;/WHATEVER&gt;&lt;/WHATEVER&gt;</description>
      <pubDate>Fri, 05 Jan 2007 16:38:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854593#M28672</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T16:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854594#M28673</link>
      <description>Thanks for the suggestion... I will explicitly create the new collection to a variable...&lt;BR /&gt;
&lt;BR /&gt;
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)...&lt;BR /&gt;
...see my other post in answer to MP.&lt;BR /&gt;
&lt;BR /&gt;
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.</description>
      <pubDate>Fri, 05 Jan 2007 16:47:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854594#M28673</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-05T16:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854595#M28674</link>
      <description>Without seeing the project explorer structure, I can only guess, but I would &lt;BR /&gt;
say you need to declare a public module-level variable, in the module that &lt;BR /&gt;
you use to start the application.&lt;BR /&gt;
&lt;BR /&gt;
Why are you using a .csv rather than a true database?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5442460@discussion.autodesk.com...&lt;BR /&gt;
Thanks for the suggestion... I will explicitly create the new collection to &lt;BR /&gt;
a variable...&lt;BR /&gt;
&lt;BR /&gt;
one question though... I want this collection to be accessible thoughout my &lt;BR /&gt;
application's feature set ... so where should I dim the collection in my &lt;BR /&gt;
application's modules (only one of these thoughout a given project)...&lt;BR /&gt;
...see my other post in answer to MP.&lt;BR /&gt;
&lt;BR /&gt;
The collection needs to be initialy filled from data in the drawing. But &lt;BR /&gt;
once 'locked' and exported to a CSV file... will be filled from data in the &lt;BR /&gt;
CSV file... ( I could create XDATA in each dwg)... but in any case I want &lt;BR /&gt;
the CSV file and the data in the Dwg files to be strictly identical.&lt;/HUTCH&gt;</description>
      <pubDate>Fri, 05 Jan 2007 16:54:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854595#M28674</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T16:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854596#M28675</link>
      <description>... good question!&lt;BR /&gt;
&lt;BR /&gt;
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... &lt;BR /&gt;
&lt;BR /&gt;
I could I suppose link into this application's data structure and write it directly... except for two things:&lt;BR /&gt;
1) I don't have the expertise to do this. although I suppose I could learn it, indeed want to... but...&lt;BR /&gt;
2) the company for which I work or the outside consultant may not want me messin' with this data.&lt;BR /&gt;
&lt;BR /&gt;
The CSV file is the mechanism that was mutually agreed to by me and the consultant.&lt;BR /&gt;
&lt;BR /&gt;
... 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...</description>
      <pubDate>Fri, 05 Jan 2007 17:01:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854596#M28675</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-05T17:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854597#M28676</link>
      <description>As long as you have a good reason... ;^)&lt;BR /&gt;
&lt;BR /&gt;
It would be easy to search for the .csv, and if not found, only populate &lt;BR /&gt;
from the current drawing.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5442479@discussion.autodesk.com...&lt;BR /&gt;
... good question!&lt;BR /&gt;
&lt;BR /&gt;
I am handing off the data in CSV file format for another in-house app... &lt;BR /&gt;
written by an outside consultant ... the app is an Access application that &lt;BR /&gt;
has enterprise wide impact...&lt;BR /&gt;
&lt;BR /&gt;
I could I suppose link into this application's data structure and write it &lt;BR /&gt;
directly... except for two things:&lt;BR /&gt;
1) I don't have the expertise to do this. although I suppose I could learn &lt;BR /&gt;
it, indeed want to... but...&lt;BR /&gt;
2) the company for which I work or the outside consultant may not want me &lt;BR /&gt;
messin' with this data.&lt;BR /&gt;
&lt;BR /&gt;
The CSV file is the mechanism that was mutually agreed to by me and the &lt;BR /&gt;
consultant.&lt;BR /&gt;
&lt;BR /&gt;
... this app I am writing is my first in VBA (with a long history in Lisp &lt;BR /&gt;
and VisualLisp)... I am learning a ton of new stuff -- greatly due to this &lt;BR /&gt;
discussion group...&lt;/HUTCH&gt;</description>
      <pubDate>Fri, 05 Jan 2007 17:17:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854597#M28676</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T17:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854598#M28677</link>
      <description>yes... that is what I am heading towards...&lt;BR /&gt;
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).&lt;BR /&gt;
&lt;BR /&gt;
... do you think it would be well to also build my own dictionary to hold the data also within the individual dwgs?&lt;BR /&gt;
 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...&lt;BR /&gt;
... as you know the 'boundingbox' method doesn't work well with rotated geometry.&lt;BR /&gt;
&lt;BR /&gt;
I think I have some logic worked out to write the algorithm but I am not ready to write it yet.</description>
      <pubDate>Fri, 05 Jan 2007 17:24:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854598#M28677</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-05T17:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to fill a dynamic array?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854599#M28678</link>
      <description>That question deserves careful consideration. You need to account for normal &lt;BR /&gt;
CAD operations such as copy and erase with whatever approach you take.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
R. Robert Bell&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5442525@discussion.autodesk.com...&lt;BR /&gt;
yes... that is what I am heading towards...&lt;BR /&gt;
only... other thing is that the data initially will be populated from 1 or &lt;BR /&gt;
more dwg files ... the data in the CSV file needs to be identical to what is &lt;BR /&gt;
in the drawing files, attributed blocks, and dwg geometry (length and width &lt;BR /&gt;
of region objects).&lt;BR /&gt;
&lt;BR /&gt;
... do you think it would be well to also build my own dictionary to hold &lt;BR /&gt;
the data also within the individual dwgs?&lt;BR /&gt;
 another challenge is some of the regions will be inline with the WCS and &lt;BR /&gt;
some will not... so I have to devise a way to get the length and width from &lt;BR /&gt;
the geometry rotated away from the WCS...&lt;BR /&gt;
... as you know the 'boundingbox' method doesn't work well with rotated &lt;BR /&gt;
geometry.&lt;BR /&gt;
&lt;BR /&gt;
I think I have some logic worked out to write the algorithm but I am not &lt;BR /&gt;
ready to write it yet.&lt;/HUTCH&gt;</description>
      <pubDate>Fri, 05 Jan 2007 17:30:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-fill-a-dynamic-array/m-p/1854599#M28678</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-05T17:30:32Z</dc:date>
    </item>
  </channel>
</rss>

