returning an array

zagnutts
zagnutts used Ask the Experts™
on
I am trying to create a function that returns an array and I seem to be having a slight problem

'simplified function

Function TestFunc()
  dim temparry(1)

  tempArry(0)=0
  tempArry(1)=1
  TestFunc=tempArry
end Function


I then call this function in my page as follows
.....
dim arryA(1)

'initialize array
arryA(0)=0
arryA(1)=0

arryA=TestFunc()  'This is where I get an error "Type mismatch "


both arrays are the same size, so I don't see why there is a type mismatch.
Any help appreciated.









Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
Call it as

dim arrA

arrA = TestFunc()
Commented:
amit_g is correct, however if you don't remove the follwoing statements you will have again type mismatch error

'initialize array
arryA(0)=0
arryA(1)=0

Commented:
try this

function makeArray()
       Dim tempArray(1)
      
       tempArray(0)="Melanie"
       tempArray(1)="Johanna"

       makeArray=tempArray
end function

dim myArray

myArray = makeArray()

for i=0 to UBound(myArray)
      Response.Write myArray(i)
next      

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial