Solved

Arrays in VB.net 2005

Posted on 2009-05-06
10
524 Views
Last Modified: 2013-11-26
I have 2 questions in vb:
I am trying to declare an array of an indifinte size but i can't find this explained anywhere.

1. Can you declare an array of indefinite size but without initializing it?
 

Dim myArray() As Integer --> this does not work

Dim myArray() As Integer = {1,2,3} -> this works but this is not an indefinite? the array has ta size of 3

2. What is the "0" inside the following functions?

MsgBox(myArray.GetLowerBound(0))

MsgBox(myArray.GetUpperBound(0))

Thanks
0
Comment
Question by:jean11
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 39

Accepted Solution

by:
abel earned 65 total points
ID: 24319537
an array has by default a fixed size. If you want to change that, you have to redim it, which is a costly operation. Instead, it is better to use the datatypes List or ArrayList which provide a flexible size.
0
 

Author Comment

by:jean11
ID: 24319632
Do you mean there is no indefinite  array in vb.net?
0
 
LVL 39

Expert Comment

by:abel
ID: 24319670
I mean that there is no language where-ever that has an indefinite array (only on a turing machine, but that has indefinite memory), as long as you mean with indefinite infinitely growable or shrinkable.

Languages that do support growing / shrinkable array type (perl, ruby other scripting languages) do not really support the array type, but support the flexible array type.

The equivalent to that in VB.NET (and any .NET language) is to use the ArrayList. But since an arraylist is limited, you will quickly want to move on to the more versatile and very quick generic List interface, which does all you want and more.
0
 

Author Comment

by:jean11
ID: 24319764
Thanks for the replies.

Yes I meant a growable array. An array that you do not specify size at the time of writing the program and  at run time the array will grow.

Do you know the answer to the second question?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 60 total points
ID: 24319799
As abel said, use a generic List...

Simplified:

    Dim myArray As New List(Of Integer)
    myArray.Add(4)
    myArray.Add(1)
    myArray.Add(1) ' <-- it "grows" automatically to accommodate new entries...
0
 
LVL 39

Expert Comment

by:abel
ID: 24319818
> 2. What is the "0" inside the following functions?
> MsgBox(myArray.GetLowerBound(0))

that is the dimension of the array. A classic array can have multiple dimensions. You can ask for each dimension what the upper bound is. It is something I very rarely encounter in normal encoding practices, but anyway, that's what it means ;)
0
 
LVL 23

Expert Comment

by:debuggerau
ID: 24322813
Sounds like the question was well answered except for the lowerbound(0) specific.

The (0) returns the lower bound for the indexes of the first dimension of the Array...
http://msdn.microsoft.com/en-us/library/system.array.getlowerbound(VS.71).aspx

0
 
LVL 23

Expert Comment

by:debuggerau
ID: 25193586
how'd you go?
0
 
LVL 39

Expert Comment

by:abel
ID: 25193911
> Sounds like the question was well answered except for the lowerbound(0) specific.
really? Think my last comment covered that. But good to put the pointer to the reference here.

Doin't expect this user to check back... If you don't ping the thread, you have a chance that it will be cleaned up by the clean up volunteers at some point (3 weeks minimum).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now