I wrote a following function in vbscript.
Function GetArray()
Dim Array(2)
Array(0) = "1"
Array(1) = "2"
GetArray = Array
End Function
In the page:
<%
Dim IArray()
IArray = GetArray()
%>
But It is not work. How can I do this?
asked Jan 10, 2012 at 7:31
zanhtet
2,0497 gold badges37 silver badges59 bronze badges
-
2What does "it is not work" mean? What happens?Cody Gray– Cody Gray ♦2012年01月10日 07:35:40 +00:00Commented Jan 10, 2012 at 7:35
1 Answer 1
Array is a reserved word in VBScript. Just use different name:
Function GetArray()
Dim MyArray(2)
MyArray(0) = "1"
MyArray(1) = "2"
GetArray = MyArray
End Function
Also, don't declare the IArray as dynamic array just as ordinary variant and it will get assigned the return value of the function no matter what it's going to be:
Dim IArray
IArray = GetArray()
answered Jan 10, 2012 at 7:40
user447356
Sign up to request clarification or add additional context in comments.
2 Comments
AnthonyWJones
+1 To be clear the return type of a function is always a simple Variant Hence when its result is assigned to a variable the variable cannot by Dimmed as an array the variable must be a simple variant. Bearing in mind that a simple variant can still contain as its value an array.
lang-vb