473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Ubound()

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
Apr 17 '06 #1
4 4299
> 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
Apr 17 '06 #2

Mark wrote:
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 :)

--
Tom Shelton [MVP]

Apr 17 '06 #3
Good stuff! Thanks a bunch.

Mark

"Mark" wrote:
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

Apr 17 '06 #4
"Mark" <Ma**@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason | last post by:
I have a number of arrays that are populated with database values. I need to determine which array has the highest ubound out of all the arrays. The array size will always change based on the...
2
by: Rick Brown | last post by:
I get a "subscript out of range" error when I run this code. "Rcount = rsSupplierCode.RecordCount" Returns 49 BUT "numReturned = UBound(varRecords, 2) + 1" Returns only 3 I'm I wrong to...
3
by: Andi Twine | last post by:
Hi all, I really hope someone here can help ! I have designed and built an ASP.NET web service with Visual Studio .NET. The web service outputs some dummy XML data when its called with some...
4
by: Cindy Meister -WordMVP- | last post by:
Hi all Generally, it seems Option Strict ON is recommended practice? How, then, does one reconcile -- Option Strict On Public MyArray(6) Single 'Some Code here
2
by: Starbuck | last post by:
Hi All In one of my converted (VB6 to VB.Net) apps I have managed to remove all instances of - Imports Microsoft.VisualBasic - except for one form which raises errors in regard to LBound and...
4
by: JR | last post by:
I may have posted a blank post accidentally. Sorry I am coming over to VB.NET from C++/C# and am confused about the UBound function. Example code: Dim i As Integer Dim myarray(6) As...
3
by: Eugene Anthony | last post by:
<% if UBOUND(Arr) > 0 then%> <% end if %> I am getting the following error: Error Type: Microsoft VBScript runtime (0x800A000D) Type mismatch: 'UBOUND'
2
by: sunshine | last post by:
I'm having trouble converting this FOR loop from VB.NET to C#: Here's the VB.NET code: Dim localCart As Object localCart = Session("cart") For i = 0 To UBound(localCart, 2) If...
2
by: Adam Honek | last post by:
I have the following code below. The thing is, even if txtCCEmailAddress.Text is empty (no text), CCRecipeant will return a Ubound() higher than 0 and still go in the loop. If there's nothing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.