473,396 Members | 1,771 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,396 software developers and data experts.

array declarations

Jay
Why is it that array declarations are different than expected (other
languages)

for example:

dim strArray(5) as String

really means that there are 6 elements and their names are 0, 1,2,3,4,5

I would expect the following:

dim strArray(5) as String

There are 5 elements and their names are 0, 1,2,3,4

Nov 21 '05 #1
4 1034
Jay,

This is because VBNet can work with the "one" indexer and the "zero"
indexer. In my opininion are there as well other solutions for that, however
they did it like this consequently keeping the indexer 1 and not internally
set in those VBNet methods the one by -1 by instance.

I hope this gives an idea?

Cor

"Jay" <
...
Why is it that array declarations are different than expected (other
languages)

for example:

dim strArray(5) as String

really means that there are 6 elements and their names are 0, 1,2,3,4,5

I would expect the following:

dim strArray(5) as String

There are 5 elements and their names are 0, 1,2,3,4

Nov 21 '05 #2

"Jay" <j@h.com> wrote
Why is it that array declarations are different than expected (other
languages)

for example:

dim strArray(5) as String

really means that there are 6 elements and their names are 0, 1,2,3,4,5

Probably because VB used to allow declaring the lower bound:

Dim strA(10 To 20) As String

(You'll note that there are 11 elements there) VB also used to have an
Option Base such that either 0 or 1 could be used as the default:

Option Base 1
Dim strB(5) As String

In that case there were 5 elements : 1, 2, 3, 4, 5

Option Base 0
Dim strB(5) As String ' 6 elements there

Now because .Net's arrays are by default 0 based, then it should
follow that they mimic the old Option Base 0 functionality....

LFS
Nov 21 '05 #3
"Jay" <j@h.com> schrieb:
Why is it that array declarations are different than expected
(other languages)

for example:

dim strArray(5) as String

really means that there are 6 elements and their names are 0, 1,2,3,4,5

I would expect the following:

dim strArray(5) as String

There are 5 elements and their names are 0, 1,2,3,4


In Addition to the other replies: VB 2005 will support the 'Bla(0 To 100)'
syntax again, but only with zero bounds. I'll update my code to this syntax
when VB 2005 comes out to avoid ambiguity for the reader.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4
If you look at the documentation for VB.NET array declarations they state
that the number is the upper bound, not the length. The array is 0-based and
the Length property will return 6 in your example. The GetUpperBound method
will return 5.

ArraySizeInitializationModifier ::=
( UpperBoundList ) [ ArrayTypeModifiers ]
UpperBoundList::=
Expression |
UpperBoundList , Expression

"Jay" <j@h.com> wrote in message news:VFIad.2921$EZ.579@okepread07...
Why is it that array declarations are different than expected (other
languages)

for example:

dim strArray(5) as String

really means that there are 6 elements and their names are 0, 1,2,3,4,5

I would expect the following:

dim strArray(5) as String

There are 5 elements and their names are 0, 1,2,3,4

Nov 21 '05 #5

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

Similar topics

10
by: BadOmen | last post by:
I have made an array in a function in a Class now I need to get to that Array from an other function in an other Class, How do I do that? The Array has no fixed size as it is dependent on how...
5
by: pandapower | last post by:
Hi, I know about the equivalence of pointer and arrays.But my doubt comes when its for multidimentional arrays.I have read the C faq but still have some doubts. Suppose I have a declaration as...
6
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
7
by: arnuld | last post by:
this programme gives unusual output. i am not able to find out where the semantic bug lies: /* C++ Primer - 4/e * * an example from section section 7.2.4, page 241 * STATEMENT * write a...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
10
by: Ahmad Humayun | last post by:
Whats the difference between: char str1 = "wxyz"; char* str2 = "abcd"; I can do this: str2 = str1 but I can't do this: str1 = str2
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.