Defining the range of an array

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

Guest

If we declar a varible as:

Dim series(10) as Double

then series can contain 11 items in maximum ( 0 - 11 ).
How do you declar this varible, making the first item as

series(1)

instead of

series(0)

? Thanks.
 
Hi.

Sorry you cant. The first element in an array is zero in vb.net

Ken
-----------------
If we declar a varible as:

Dim series(10) as Double

then series can contain 11 items in maximum ( 0 - 11 ).
How do you declar this varible, making the first item as

series(1)

instead of

series(0)

? Thanks.
 
You are saying that the first item in the array is series(0)
and the tenth item (i.e. the last item) in the array is series(10)

This statement Dim series(10) as Double actually can
accommodate 10 items only.

Am I correct?

Xero
 
Xero,

No, when dimensioning an array, you specifiy the upper bound of the array,
with the lower bound always being zero.

So,

Dim series (10) As Double

will produce an array with 11 elements, numbered 0 through 10.

Kerry Moorman
 
Jeff,

It is a strange way of keeping compatibility that is taken, and maybe it
could have been avoided, however all methods or whatever in the VB namespace
is using for indexing the start index First where First is 1.

The rest of dotnet methods or whatever are using for First the zero.

Although I am used to the zero start indexer, is in my opinion the way VB
does it better. However, you cannot turn history back so most of us with not
only VB background are using the zero indexer.

Dim i(10) as integer are 11 integers in an array.
Usable from 0 to 10 what are eleven or 1 to 10 what are ten integers

And therefore I use
dim i(9) as integer when I want 10 integer is an array.

It looks strange, however I hope this helps anyway something.

Cor
 
I see ...
Thanks, guys!

Xero
Cor Ligthert said:
Jeff,

It is a strange way of keeping compatibility that is taken, and maybe it
could have been avoided, however all methods or whatever in the VB namespace
is using for indexing the start index First where First is 1.

The rest of dotnet methods or whatever are using for First the zero.

Although I am used to the zero start indexer, is in my opinion the way VB
does it better. However, you cannot turn history back so most of us with not
only VB background are using the zero indexer.

Dim i(10) as integer are 11 integers in an array.
Usable from 0 to 10 what are eleven or 1 to 10 what are ten integers

And therefore I use
dim i(9) as integer when I want 10 integer is an array.

It looks strange, however I hope this helps anyway something.

Cor
 
Back
Top