Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Use a listbox as a dynamic array?

My VBA program will require multiple dynamic arrays of
strings. These will be "parallel arrays", meaning the arrays
will be the same size, and the indexes of each array will
be related to the corresponding indexes of the other arrays.

So....I decided that I do NOT want to bother using dynamic
arrays for my program, simply because dynamic arrays are
a pain to manage, and other reasons related to the design of
my program.

Instead, I was thinking about creating a few hidden Listbox
controls on a Userform (i.e Visible = False). Then, I could
simply use Listbox.AddItem() to continually add new strings
to the various hidden Listbox's, and possibly remove or
search for strings if necessary.

I'm just curious, but has anybody ever implemented something
like this in their VBA program? How did it work for you?
Were there any problems that I should know about?

What does everybody else think about this idea?

I'd appreciate any comments. Thank you.

Robert


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Use a listbox as a dynamic array?

Robert Crandal wrote:
My VBA program will require multiple dynamic arrays of
strings. These will be "parallel arrays", meaning the arrays
will be the same size, and the indexes of each array will
be related to the corresponding indexes of the other arrays.

So....I decided that I do NOT want to bother using dynamic
arrays for my program, simply because dynamic arrays are
a pain to manage, and other reasons related to the design of
my program.

Instead, I was thinking about creating a few hidden Listbox
controls on a Userform (i.e Visible = False). Then, I could
simply use Listbox.AddItem() to continually add new strings
to the various hidden Listbox's, and possibly remove or
search for strings if necessary.

I'm just curious, but has anybody ever implemented something
like this in their VBA program? How did it work for you?
Were there any problems that I should know about?

What does everybody else think about this idea?

I'd appreciate any comments. Thank you.

Robert


I did.
it works well, however I can't tell anything about performance because
it was used for very small arrays.

By the way that is the only way to get empty two-dimensional array. (no
elements)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Use a listbox as a dynamic array?

Robert Crandal expressed precisely :
My VBA program will require multiple dynamic arrays of
strings. These will be "parallel arrays", meaning the arrays
will be the same size, and the indexes of each array will
be related to the corresponding indexes of the other arrays.

So....I decided that I do NOT want to bother using dynamic
arrays for my program, simply because dynamic arrays are
a pain to manage, and other reasons related to the design of
my program.

Instead, I was thinking about creating a few hidden Listbox
controls on a Userform (i.e Visible = False). Then, I could
simply use Listbox.AddItem() to continually add new strings
to the various hidden Listbox's, and possibly remove or
search for strings if necessary.

I'm just curious, but has anybody ever implemented something
like this in their VBA program? How did it work for you?
Were there any problems that I should know about?

What does everybody else think about this idea?

I'd appreciate any comments. Thank you.

Robert


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.

If you have a good naming convention in place then working with arrays
is trivial (so long as you understand array structures)!

--
Garry

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Use a listbox as a dynamic array?

witek used his keyboard to write :
By the way that is the only way to get empty two-dimensional array.
(no elements)


Not true! You can make any element 'empty' in any array, regardless of
its number of dims.

--
Garry

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Use a listbox as a dynamic array?

GS wrote:
witek used his keyboard to write :
By the way that is the only way to get empty two-dimensional array.
(no elements)


Not true! You can make any element 'empty' in any array, regardless of
its number of dims.



can you show me a code which creates array with 5 columns and zero rows?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Use a listbox as a dynamic array?

witek expressed precisely :
GS wrote:
witek used his keyboard to write :
By the way that is the only way to get empty two-dimensional
array.
(no elements)


Not true! You can make any element 'empty' in any array, regardless
of
its number of dims.



can you show me a code which creates array with 5 columns and zero
rows?


That's not an array! Show me otherwise...

Can you show a listbox that has 5 columns and zero rows? Yes.., when
it's empty. Can you load this into an array with zero rows? No!

--
Garry

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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Use a listbox as a dynamic array?

GS wrote:
witek expressed precisely :
GS wrote:
witek used his keyboard to write :
By the way that is the only way to get empty two-dimensional array.
(no elements)

Not true! You can make any element 'empty' in any array, regardless of
its number of dims.



can you show me a code which creates array with 5 columns and zero rows?


That's not an array! Show me otherwise...


so what is that?
What is the name of structure returned by listbox.list if listbox is empty?


Can you show a listbox that has 5 columns and zero rows? Yes.., when
it's empty. Can you load this into an array with zero rows? No!

as above . What does listbox.list returns?

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Use a listbox as a dynamic array?

"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.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Use a listbox as a dynamic array?

witek used his keyboard to write :
GS wrote:
witek expressed precisely :
GS wrote:
witek used his keyboard to write :
By the way that is the only way to get empty two-dimensional
array.
(no elements)

Not true! You can make any element 'empty' in any array,
regardless of
its number of dims.



can you show me a code which creates array with 5 columns and zero
rows?


That's not an array! Show me otherwise...


so what is that?
What is the name of structure returned by listbox.list if listbox is
empty?


Can you show a listbox that has 5 columns and zero rows? Yes..,
when
it's empty. Can you load this into an array with zero rows? No!

as above . What does listbox.list returns?


Whatever are you on about? Your response to my statement of being able
to make any element of any array empty has nothing to do with that
statement! Please explain what your point is!

--
Garry

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


  #10   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DYNAMIC LISTBOX daphoenix Excel Programming 2 April 2nd 09 10:46 AM
Speed of fixed array versus dynamic array Sing Excel Programming 8 November 18th 07 10:19 AM
Dynamic Array Lbound not working when only one value in array [email protected] Excel Programming 3 May 25th 07 04:08 AM
dynamic fill of listbox - need help gonger Excel Programming 6 May 25th 06 07:16 PM
Dynamic Multi Column ListBox Ronbo Excel Programming 3 January 11th 05 07:59 PM


All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"