What is the use of 'Preserve' keyword in VB Script? - TestingQ.com

-->Exclusive Portal for Testing Jobs

What is the use of 'Preserve' keyword in VB Script?

The Preserve keyword is very important when using ReDim. 
For example, that you create a dynamic array, specifying its storage space by using ReDim, fill it with data, and then later decide to make it larger so you can fill it with more information without losing your original data. In the following example, ReDim sets the initial size of the dynamic array to 25. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place.


   ReDim MyArray(25)
       . . .
   ReDim Preserve MyArray(30)

There is no limit to the number of times you can resize a dynamic array.


    Dim car()
    Redim car(1)    
    Redim preserve car(2)
    msgbox car(1)
    msgbox car(2)


To receive daily posted JOBS & Interview Questions
Just enter your email address below and click 'Submit'
Enter your email address:

Make sure to activate your subscription by clicking on the activation link sent to your email