Micro Focus QTP (UFT) Forums

Full Version: Global Array re dimension inside an action
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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.