Micro Focus QTP (UFT) Forums
Global Array re dimension inside an action - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Global Array re dimension inside an action (/Thread-Global-Array-re-dimension-inside-an-action)



Global Array re dimension inside an action - martinbedouret - 09-24-2009

Hi,
I'm trying to re-dimension a global array declared in a library file associated to my test. I'm using the ReDim sentence inside an action but I get "Illegal assignment" error.
This is what I have:

in a library file (library.qlf):

Code:
Dim dinamicArray()  'define a global dinamic array

in an action of a qtp test case:
Code:
...
ReDim dinamicArray(2)
....

I link the library file to the test and the global array is recognized in the action but I get "Illegal assignment" error at run time.

Would appreciate any kind of help
Martin


RE: Global Array re dimension inside an action - Saket - 09-24-2009

You can not ReDim an array in an action which is declared in a library file,
You should have both Dim and ReDim either in the library file or in the Action itself.

what you can do here is declare the variable as Public(if you need) in the action only and then ReDim as per your need in that action.


RE: Global Array re dimension inside an action - martinbedouret - 09-24-2009

Ok, thanks for the comment. I implemented a workaround to solve it:

in the library file (library.qlf):

Code:
Public dinamicArray()  'define a global dinamic array

Public Function ReDimArray(ArrayName, num)
    Execute "ReDim "&ArrayName&"("&num&")"
End Function

in an action of a qtp test case:
Code:
Call ReDimArray("dinamicArray",0)
Call ReDimArray("dinamicArray",1)
Call ReDimArray("dinamicArray",2)

It is a workaround just to solve the library limitation. Thanks Saket.