Micro Focus QTP (UFT) Forums

Full Version: Accessing an array returned from a function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Could someone please tell me what I am doing wrong. I have a function like that return an array. I can print the array elements if I declare the MyCtrl() as a global variable. But when I try to get the array contents in a function I get an error Type Mismatch at this line 'CtrlName = MyFunction' in the calling function.

Code:
Function MyFunction
Dim MyCtrl()

MyFunction = MyCtrl
End Function

'Now access the array from the above function
Function GetCtrl

Dim CtrlName()
CtrlName = MyFunction ' get Type Mismatch at this line
for i=0 To Ubound(CtrlName)
Print CtrlName(i)
End Function

Thanks,
Sqadri
Code:
Function MyFunction
Dim MyCtrl(1)
MyCtrl(0) = "First String"
MyCtrl(1) = "Second String"
MyFunction = MyCtrl
End Function

'Now access the array from the above function
Code:
Dim CtrlName
CtrlName = MyFunction ' get Type Mismatch at this line
for i=0 To Ubound(CtrlName)
MsgBox CtrlName(i)
next
Check the above code it is working. The variable that will receive the resulting array must be declared as dynamic
Hi Swathi,

Thank you,
Sqadri