Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing an array returned from a function
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
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
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi Swathi,

Thank you,
Sqadri
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a function in a Test Script from a function library anupam4j 3 6,127 06-26-2015, 12:31 AM
Last Post: babu123
  How to convert a single dimension array to two dimensional array venkatesh9032 3 5,538 02-10-2014, 03:07 PM
Last Post: pranikgarg
  Accessing Environment variable value in Library file vishruth143 1 2,570 09-07-2013, 05:11 AM
Last Post: jacosta
  Adding array to another Global array in VB Script test911 1 3,174 12-02-2012, 12:40 PM
Last Post: parminderdhiman84
  ACCESSING OBJECR REPOSITORY SHARED ONE babukaturi 1 2,540 04-03-2012, 12:03 PM
Last Post: sshukla12

Forum Jump:


Users browsing this thread: 2 Guest(s)