Ubound()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the consensus about using the Ubound function? Should it be avoided
altogether? Is there an arry size where Ubound becomes less efficent?

Also, is there a better way to increase the size of an array (preserving its
current values) besides using Redim Preserve?

Thanks,
Mark
 
What is the consensus about using the Ubound function? Should it be
avoided altogether? Is there an arry size where Ubound becomes less
efficent?

Also, is there a better way to increase the size of an array
(preserving its current values) besides using Redim Preserve?

Have you considered the ArrayList? Depending on your needs, it may have advantages.
It does not require a Redim to change the size of the array for one.

Jim Wooley
http://devauthority.com/blogs/jwooley
 
Mark said:
What is the consensus about using the Ubound function? Should it be avoided
altogether? Is there an arry size where Ubound becomes less efficent?

I really have no objects to the Ubound function, nor do I know of any
limits on it's efficeincy.
Also, is there a better way to increase the size of an array (preserving its
current values) besides using Redim Preserve?

With a regular array object? Not really. My only advice here is to
limit the number of calls to Redim... That means don't call Redim for
every element you add - always allocate in chunks.

If what you are storing in the array are reference types (classes, not
structures) then I would suggest using an arraylist rather then a pure
array. An arraylist will grow dynamically (actually, it will
essentially do what you have to do manually with a regular array -
redim the array that is it's backing store when it needs to grow, but
it does it in chunks so you don't have to worry about it). It will
most likely give you better performance... If you are using VB.NET
2005, then I would say to use one of the generic list class. It will
give you good performance even with value types (structures). If you
using 2003 or earlier, then I would consider using a typed array if you
are storing value types and managing the array resize your self - I
would put it into a class....

I hope my rambling made sense :)
 
Mark said:
What is the consensus about using the Ubound function? Should it be
avoided
altogether? Is there an arry size where Ubound becomes less efficent?

In addition to the other replies, note that using 'UBound' can make code
shorter and prevent bugs from occuring because it really returns the upper
bound opposed to the array object's 'Length' property, which will return the
number of items in the array.
 
Back
Top