[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

Arrays in VB.net 2005

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
jean11
Asked:
jean11
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
abelCommented:
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
 
jean11Author Commented:
Do you mean there is no indefinite  array in vb.net?
0
 
abelCommented:
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
jean11Author Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
abelCommented:
> 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
 
debuggerauCommented:
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
 
debuggerauCommented:
how'd you go?
0
 
abelCommented:
> 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now