Micro Focus QTP (UFT) Forums
Accessing an array returned from a function - 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 Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Accessing an array returned from a function (/Thread-Accessing-an-array-returned-from-a-function)



Accessing an array returned from a function - sqadri - 03-27-2012

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


RE: Accessing an array returned from a function - swathi - 03-28-2012

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


RE: Accessing an array returned from a function - sqadri - 03-28-2012

Hi Swathi,

Thank you,
Sqadri