Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return array from function

Status
Not open for further replies.

magmo

Programmer
May 26, 2004
291
SE
Hi


Is it possible to return an array from a function? I tryed this but that didn't work.

Code:
<%
Function MakeArray()
    Dim arrMyArray(3,1)
    arrMyArray(0,0) = "Car no 1"
    arrMyArray(0,1) = 10
    arrMyArray(1,0) = "Car no 2"
    arrMyArray(1,1) = 5
    arrMyArray(2,0) = "Car no 3"
    arrMyArray(2,1) = 8
    arrMyArray(3,0) = "Car no 4"
    arrMyArray(3,1) = 2
    
    MakeArray = arrMyArray()
End Function

Dim MyArray()
MyArray = MakeArray()

For i = LBound(MyArray) to UBound(MyArray)
  Response.Write ("Model: " & MyArray(i, 0) & " , Qty ")
  Response.Write MyArray(i, 1) & "<BR>"
Next
%>



Regards
 
Hello magmo,

Simply avoid declaring it dynamic.
Code:
<%
Function MakeArray()
    Dim arrMyArray(3,1)
    arrMyArray(0,0) = "Car no 1"
    arrMyArray(0,1) = 10
    arrMyArray(1,0) = "Car no 2"
    arrMyArray(1,1) = 5
    arrMyArray(2,0) = "Car no 3"
    arrMyArray(2,1) = 8
    arrMyArray(3,0) = "Car no 4"
    arrMyArray(3,1) = 2
    
    'MakeArray = arrMyArray[s][red]()[/red][/s]
    MakeArray = arrMyArray
End Function

'Dim MyArray[s][red]()[/red][/s]
Dim MyArray
MyArray = MakeArray()

For i = LBound(MyArray) to UBound(MyArray)
  Response.Write ("Model: " & MyArray(i, 0) & " , Qty ")
  Response.Write MyArray(i, 1) & "<BR>"
Next
%>
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top