[Year 12 SofDev] Arrays of unknown length.

Damien A-B buck.damien.j at edumail.vic.gov.au
Mon Jun 25 11:25:35 EST 2007


Hi Bruce,
    Does this help? 
taken from
http://www.ondotnet.com/pub/a/dotnet/excerpt/vbnetnut_appa/index.html?page=2

Cheers

Damien Atkinson-Buck

IT Department

Keilor Downs College


Arrays and array declarations


VB 6 permitted you to define the lower bound of a specific array, as well as
the default lower bound of arrays whose lower bound was not explicitly
specified. In VB .NET, the lower bound of every array dimension is 0 and
cannot be changed. The following examples show how to declare a
one-dimensional array, with or without an explicit size and with or without
initialization:

' Implicit constructor: No initial size and no initialization

Dim Days(  ) As Integer

 

' Explicit constructor: No initial size and no initialization

Dim Days(  ) As Integer = New Integer(  ) {}

 

' Implicit constructor: Initial size but no initialization

Dim Days(6) As Integer

 

' Explicit constructor: Initial size but no initialization

Dim Days(  ) As Integer = New Integer(6) {}

 

' Implicit constructor: Initial size implied by initialization

Dim Days(  ) As Integer = {1, 2, 3, 4, 5, 6, 7}

 

' Explicit constructor, Initial size and initialization

Dim Days(  ) As Integer = New Integer(6) {1, 2, 3, 4, 5, 6, 7}

Note that in the declaration:

Dim ArrayName(X) As ArrayType

the number X is the upper bound of the array. Thus, the array has size X+1.

Multidimensional arrays are declared similarly. For instance, the following
example declares and initializes a two-dimensional array:

Dim X(,) As Integer = {{1, 2, 3}, {4, 5, 6}}

and the following code displays the contents of the array:

Debug.Write(X(0, 0))

Debug.Write(X(0, 1))

Debug.Writeline(X(0, 2))

Debug.Write(X(1, 0))

Debug.Write(X(1, 1))

Debug.Write(X(1, 2))

 

123

456

In VB .NET, all arrays are dynamic; there is no such thing as a fixed-size
array. The declared size should be thought of simply as the initial size of
the array, which is subject to change using the ReDim statement. Note,
however, that the number of dimensions of an array cannot be changed.

Moreover, unlike VB 6, the ReDim statement cannot be used for array
declaration, but only for array resizing. All arrays must be declared
initially using a Dim (or equivalent) statement.


  _____  

From: sofdev-bounces at edulists.com.au [mailto:sofdev-bounces at edulists.com.au]
On Behalf Of RILEY, Bruce
Sent: Friday, 22 June 2007 10:03 AM
To: Year 12 Software Development Teachers' Mailing List
Subject: [Year 12 SofDev] Arrays of unknown length.



Hi all

I am trying to work out how a example of using a 1-d array of unknown length
to demo to the students. I am using VB .NET

 

Essentially I want to input an unknown number of integers using an inputbox,
enter a piece of dummy data to end the input, then display these back to the
students.

 

I am trying to use eg. Dim Score() as integer and then later use ReDim
Preserve(count) but can't get the code right. 

 

Any help would be gratefully received.

 

----------------------------------------------------------------------------
--------

 

Bruce Riley

ICT Manager

Kew High School

1393 Burke Road

Kew East, VIC. 3102

Australia

 

Phone: 61 3 9859 8652

Fax:     61 3 9819 7880

 

_______________________________________________ 
http://www.edulists.com.au  <http://www.edulists.com.au> IT Software
Development Mailing List kindly supported by 
http://www.vcaa.vic.edu.au  <http://www.vcaa.vic.edu.au> - Victorian
Curriculum and Assessment Authority and 
http://www.vitta.org.au  <http://www.vitta.org.au> - VITTA Victorian
Information Technology Teachers Association Inc 

Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20070625/2ffd72f1/attachment.html


More information about the sofdev mailing list