Getting the upper bound index of an integer array

J

Jerry West

I'd like to get the upper bound index of an integer array. I've tried the
following:

Dim i as Integer
Dim arrayIng() as Integer

i = arrayIng.GetUpperBound

This doesn't work. It seems GetUpperBound behaves more like a function in
that it wants a passed parameter. Is there not a property similar to VB6
like: i = UBound(arrayIng)

I realize that's still possible in VB .NET but isn't there a newer way of
doing it in VB .NET?

JW
 
L

Lloyd Sheen

Jerry West said:
I'd like to get the upper bound index of an integer array. I've tried the
following:

Dim i as Integer
Dim arrayIng() as Integer

i = arrayIng.GetUpperBound

This doesn't work. It seems GetUpperBound behaves more like a function in
that it wants a passed parameter. Is there not a property similar to VB6
like: i = UBound(arrayIng)

I realize that's still possible in VB .NET but isn't there a newer way of
doing it in VB .NET?

JW

It wants to know which part of an array you want the upper bound. Gets the
upper bound of the specified dimension in the System.Array. In your case
pass 0.

Hope this helps
Lloyd Sheen
 
C

Cor Ligthert[MVP]

Jerry,

I never use the upper bound or whatever.

Array.length - 1 = the latest, Array(0) is the first.

It is a pitty that in the first VB.Net beta time there is decided to keep
for real arrays a kind of compatibility with VB6 with the result now that it
keeps real arrays in VB.Net a troublefull situation.

An array in VB.Net is created with one extra in a way that you can use the
length and the count, however as well the bounds. To keep projects with
interchangeble languages, I will always avoid in this the starting index 1.
Be aware that this 1 extra is only for true arrays and the old not
Icollection implementing VB.Net collection. For the rest all lists and
collections and the generic versions of that behave as in all languages in
dotNet from zero to the length of the array.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top