View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Use a listbox as a dynamic array?

Robert Crandal wrote on 07/03/2013 :
"GS" wrote

I've ALWAYS found using dynamic arrays much easier to manage, AND
get way better performance than read/write to a control or
worksheet. IOW, your logic (IMO) for using hidden listboxes is
flawed because that's way more complex than just managing the
arrays you populate them with. You need to keep track of which
listbox contains what data same as you'd have to keep track of
which array contains what data. Listbox indexes start at zero;
dynamic 2D arrays of ranges start at 1. This adds to management
complexity.


I thought I read somewhere that it was not possible to resize an
array that
already contains data. I could be wrong about this.

I was initially thinking about creating two or three separate arrays,
each
containing sized at 6000 elements, and then add or delete data as
necessary.
I was thinking this might be a slightly inefficient approach, so I
considered
the idea of using a Listbox as an array that can grow when necessary.

My program already requires one Listbox that will be visible. I
thought
about creating one or two separate hidden Listbox controls that will
be parallel to the visible Listbox (meaning the Listboxes are the
same size
and each index corresponds to each other according to my program).
It seemed like an easy to manage method to me, because all I need to
do
is call AddItem() for each Listbox, one at a time, and it eliminated
the use
of global arrays that require dynamic resizing and whatever.


A 1D array can be resized using ReDim. It can also be downsized using
Filter to remove empty elements.

A 2D array can be parsed of empty elements by putting it into another
array.

Either approach isn't really any different that what you're doing with
listboxes as far as the physical process goes. What is different,
though, is that you have the extra overhead of the controls PLUS the
code to manage them. As far as accessing items by row/col goes, an
array is a lot easier than a multi-column listbox. An array also
doesn't have the extra read/write overhead related to working with the
individual listbox items.

I'm not saying there's anything wrong with what you're doing. It's just
not the approach I would take!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion