1

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?

1
  • 2
    What does "it is not work" mean? What happens? Commented Jan 10, 2012 at 7:35

1 Answer 1

6

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()
Sign up to request clarification or add additional context in comments.

2 Comments

+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.
@Anthony thanks for the clarification, wasn't sure about those technical details. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.