Solved

Arrays in VB.net 2005

Posted on 2009-05-06
10
523 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
Comment Utility
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
Comment Utility
Do you mean there is no indefinite  array in vb.net?
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 60 total points
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
how'd you go?
0
 
LVL 39

Expert Comment

by:abel
Comment Utility
> 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

15 Experts available now in Live!

Get 1:1 Help Now