I inserted the code into another project of mine, and it worked there as well... so I'm sure that the code works without issue.
I'm using VB 2008 Express
Main Topics
Browse All TopicsHello,
Let's say that I want a length of size 2, and then I want to put some strings in it
Dim Ar(2) as string
Ar(0) = "A"
Ar(1) = "B"
Why is it that I'm able to play around with the 3rd slot (2nd index)?
Ar(2) = "C"
So, I just made an array of size 2, but I can put THREE things in it?
So, when I want an array with Two slots and ONLY two slots in it, how can I make this happen?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Its pretty standard with VB.Net, seems that the value in the declaration is the upper index
http://www.startvbdotnet.c
From MSDN
"The index of each dimension is 0-based, which means it ranges from 0 through its upper bound. Therefore, the length of a given dimension is greater by 1 than the declared upper bound for that dimension."
Although it may look odd, it is consistent.
In VB.NET if you want an array of LENGTH 3, you would (because of the zero-based indexing) declare an UPPERBOUND of 2.
The confusion arises because you say you want an array of LENGTH 2, and yet you use an UPPERBOUND of 2. What you put in the array's declaration signature is the upper bound, not the length. Try this code
Dim a(2) As String
Debug.WriteLine(a.Length)
Debug.WriteLine(UBound(a))
So the thing to remember is simply that, in VB.NET, LENGTH and UPPERBOUND are different.
Roger
Business Accounts
Answer for Membership
by: jaime_olivaresPosted on 2008-05-31 at 11:27:11ID: 21684591
strange result, it should generate an array bound exception