Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Working with Redim Statement in VB.Net and its Advantages

Author: DevASP

It is use to declare dynamic-array variables and allocate or reallocate storage space. This is a very use full statement of VB.Net and we can declare dynamic arrays with this.

The ReDim statement is used to size or resize a dynamic array that has already been formally declared using a Private, Public, or Dim statement with empty parentheses (without dimension subscripts). You can use the ReDim statement repeatedly to change the number of elements and dimensions in an array.

If you use the Preserve keyword, you can resize only the last array dimension, and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.



ReDim [Preserve] varname(subscripts) [, varname(subscripts)] . . .



Preserves the data in an existing array when you change the size of the last dimension



            Name of the variable; follows standard variable naming conventions.




Dimensions of an array variable; up to 60 multiple dimensions may be declared. The subscripts argument uses the following syntax:

upper [,upper] . . .

The lower bound of an array is always zero. 

Dim X As Array(,,)

ReDim X(10, 10, 10)

These two statements just declare an array know you can store any value in this array but there is requirement of the program that that you have to increase size of third dimension of the array without lose the previous data one way is that you declare another array store X array data in that array then increase X size and again store precious data. But provide us a very use full Statement we can do this

ReDim Preserve X(10, 10, 15)

Now it preserves its previous records and size of array also increased.

Note: If you make an array smaller than it was originally, data in the eliminated elements is lost.

Article Comments
i want make code like this
structure dtsiswa
public nis as string
public nama as string
end structure
dim siswa() as dtsiswa
dim posisi as integer
sub save(pos as integer)
end sub
when in button why that's error

sub button_click(................
redim preserve siswa(posisi)
end sub

can you help me

Posted on 7/4/2007 1:23:28 AM by yusuf


Posted on 12/28/2007 10:40:55 AM by David Mungoshi

Add Article Comment:
Name :
Email Address :
Comments :
<< How to make System Try Animated Icons and Text of your Application Form in VB.Net

Disclaimer - Privacy
© 2002-2017