How to fill a dynamic array?

How to fill a dynamic array?

mdhutchinson
Advisor Advisor
2,029 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
2,030 Views
25 Replies
Replies (25)
Message 21 of 26

mdhutchinson
Advisor
Advisor
yes... for a complete and sound app...

I suppose I will eventually write a persistent reactor that get created of some sort... I've done a few of these before in Vlisp... (they get create as part of an mnl file) ... but not many.. these are currently in use and seem to be working fairly well.
Are these any easier to write in VBA then in Vlisp in your estimation?
0 Likes
Message 22 of 26

Anonymous
Not applicable
I prefer VBA events, but there are no persistent object events in VBA.
However, that is not a bad thing, IMHO. That being said, I have not poured
much energy into object-level events either.

--
R. Robert Bell


wrote in message news:[email protected]...
yes... for a complete and sound app...

I suppose I will eventually write a persistent reactor that get created of
some sort... I've done a few of these before in Vlisp... (they get create as
part of an mnl file) ... but not many.. these are currently in use and seem
to be working fairly well.
Are these any easier to write in VBA then in Vlisp in your estimation?
0 Likes
Message 23 of 26

mdhutchinson
Advisor
Advisor
I guess I would then have to load the nessesary reactors from som auto loading file, like mnl or acad.lsp or some such file. Does VBA have an autoloading mechanism or do I just place a call to my reactors in the mnl or acad.lsp file?
0 Likes
Message 24 of 26

Anonymous
Not applicable
wrote in message news:[email protected]...
I guess I would then have to load the nessesary reactors from som auto
loading file, like mnl or acad.lsp or some such file. Does VBA have an
autoloading mechanism or do I just place a call to my reactors in the mnl or
acad.lsp file?

you could expend much energy getting reactors and such set up and maybe it
would work flawlessly
or you could just re-read the dwgs at the time you need the report.
So you always know you have the current data

In my opinion the simplest approach is usually the best.
0 Likes
Message 25 of 26

Anonymous
Not applicable
Personally, I would check each drawing opened to see if it had a dictionary
that relates to this application, and if found, create the object events at
that point.

Checking the drawing for the dictionary and running the appropriate macro
could be in the .mnl or AcadDoc.lsp (not Acad.lsp).

--
R. Robert Bell


wrote in message news:[email protected]...
I guess I would then have to load the nessesary reactors from som auto
loading file, like mnl or acad.lsp or some such file. Does VBA have an
autoloading mechanism or do I just place a call to my reactors in the mnl or
acad.lsp file?
0 Likes
Message 26 of 26

Anonymous
Not applicable
Let me offer this bit of advice.

Don't waste your time trying to build event-
driven solutions in VBA.

The exact reasons why any attempt to do this
will always lead to failure are many and not
easily understood by folks like Robert, which
is probably why he's eager to advise you to
head down that dead end.

I don't really have time to write a book about
my own experiences with this, so I'll just cite
a few of the most obvious issues, but these
are not the only ones.

For starters, the modified event does not fire
when an object modification is undone.

Additionally, copying objects (both within the
same DWG and across DWGs) that are being
watched will pose additional complications that
VBA simply cannot deal with.

My advice is to take a different approach to your
design. While a drawing is open, access the data
directly when it is needed. When a drawing is
saved, extract any data you want available while
the drawing is offline, and store it in a database.

Do not try to replicate or store a mirror copy of
data stored in a drawing file, and expect to use
events or reactors to keep it synchonized, because
it is simply not possible with VBA alone.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:[email protected]...
I guess I would then have to load the nessesary reactors from som auto loading file, like mnl or acad.lsp or some such file. Does VBA have an autoloading mechanism or do I just place a call to my reactors in the mnl or acad.lsp file?
0 Likes