Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Saturday 5 January 2019

Uses of Redim Preserve Keyword


In order to save the data in the array,  Preserve keyword is to be used.

Example
-----------------------
'Initialize Dynamic array
Dim arr()

'In the brackets 2 is mentioned, this indicates the last index  of the array. 
'So  number of cells will be 3 as index starts from 0.

Redim arr(2

arr(0) = "Akash"
arr(1) = "Padam"
arr(2) = "Prashant"


'Re-dimension array as there is a need to delete last element from the array
'In the bracket 1 is mentioned indicating that the last cell index should be 1
'So there will be two elements in the array, at arr(0) and at arr(1)

ReDim arr(1Msgbox arr(0' Return Empty
Msgbox arr(1' Return Empty


' If Preserve is not used array will be Re-Dimensioned, but existing values will be deleted
'In order to save the data, Preserve is to be used
'So the correct code will be:

ReDim Preserve arr(1Msgbox arr(0' Return Akash 
Msgbox arr(1' Return Padam


No comments:

Post a Comment

Note: only a member of this blog may post a comment.