Micro Focus QTP (UFT) Forums
How can we retain values in an array without destorying previous values - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Interview Questions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Interview-Questions)
+--- Thread: How can we retain values in an array without destorying previous values (/Thread-How-can-we-retain-values-in-an-array-without-destorying-previous-values)



How can we retain values in an array without destorying previous values - kotaramamohana - 06-22-2012

Hi Friends,

suppose we have stored 5 values in array. Later we decided to increase array size without destorying previous values. Is it possible to do that. If yes, Can you please share how can we do that?

For your understanding i am giving one Example:
Code:
a=array("a","b","c","d","e")

msgbox a(0)  'It displays a

ReDim a(15)
msgbox a(0)  'it displays empty value (How can I retain a(0) value)



RE: How can we retain values in an array without destorying previous values - Ankesh - 06-22-2012

You need to preserve the array elements using preserve keyword.

Use

Redim Preserve a(15)


Regards,
Ankesh


RE: How can we retain values in an array without destorying previous values - ssvali - 06-22-2012

Use "Preserve" keyword to retain value

Below is the example
Code:
a=array("a","b","c","d","e")

msgbox a(0)  'It displays a

ReDim Preserve a(15)
msgbox a(0)  'it retains value



RE: How can we retain values in an array without destorying previous values - kotaramamohana - 06-22-2012

Thanks Ankesh and SSvali, Its working fine