开发者

How can I return an array from a function in classic asp?

开发者 https://www.devze.com 2023-01-04 14:55 出处:网络
Tried this Function myfunction() Dim myArray(1) myArray(0) 开发者_C百科= \"1\" myArray(1) = \"2\" myfunction = myArray

Tried this

Function myfunction()
Dim myArray(1)
myArray(0) 开发者_C百科= "1"
myArray(1) = "2"

myfunction = myArray
End Function

Dim newarray = myfunction()

And I get 500 error.

I'm using IIS7 with .NET runtime ASP.Net 2.0/3.0/3.5 On Godaddy's free economy hosting if that helps.


Of course you can

Dim myVar : myVar = 1


In VBScript, you can't assign a value to a variable on the same line that you declare it. You'll have to change

Dim newarray = myfunction()

to

Dim newarray
newarray = myfunction()


What is also missing here is an example call to the function, which is important to illustrate, as it is at the calling code where another array has to be defined in the correct manner, as follows:

Dim aResultArray

aResultArray = MyFunction()

Response.Write("Value of aResultArray(0): ") & aResultArray(0) & "<br>"
Response.Write("Value of aResultArray(1): ") & aResultArray(1) & "<br>"

The array declaration is unique, in that it is defined as a standard variable so that it is similar to a pointer in memory, and since the return is an array, it is assigned to the variable as defined. I have personally not seen an array return from an ASP classic function work properly in any other way.


The array is being defined as ("1"), but you are trying to store 2 values in it.

0

精彩评论

暂无评论...
验证码 换一张
取 消