Student Mode Code Display

Welcome to the Fraternity!

Commenting has been enabled. You can comment on all the Code Items now.

Static and Dynamic Array Preserve Keyword


Add This Code to My Favourite List
Enter Email

Contributed By admin
Date 2015-01-27 04:40:23

'######################################################
'Static and Dynamic Array, Use of Preserve Keyword
'#######################################################

'ReDim is used to Redimensioning the existing 
'"Dynamic Array".
'Case 1: ReSizing Static Array is not Possible
Dim Arr(1)
Arr(0)= "My"
Arr(1) = "Name"

ReDim Arr(2) 'Will give Error
'Above Statement Will give error as Arr is not aDynamic 
'array since its size has already been decided during its 
'declaration

'Case 2: ReSizing Dynamic Array
Dim Arr()’ Dynamic Array
ReDim Arr(1)
Arr(0)= "My"
Arr(1)= "Name"

'Again Resizing
ReDim Arr(2)

'This time array will resize but it will not 
'retain the previous information
'So Preserve Keyword is to be used

'Case 3: ReSizing Dynamic Array using Preserve Keyword
Dim Arr() 'Dynamic Array
ReDim Arr(1)
Arr(0)= "My"
Arr(1) = "Name"

'Again Resizing
ReDim Preserve Arr(2)
Arr(2)="Akash"

'Preserve keyword will retain previous information

Download Above Code

Comments:


Updated by AKT at 2015-04-15 10:52:51
na

Add your comments...
Name : *      
Email : *      
The content of this field will be kept private and will not be shown publicly

Your Comment/Answer *

Enter the text present in this box : *