0

I've been looking online for a way to make a vbscript function to return an object I created:

<%

dim myArray(5)
set myArray(5) = new MyClass

for i = 0 to 5
response.write("i :" & i & "<br/>")
set myArray(i) = new MyClass
myArray(i).MyText = "Number " & i
next

class MyClass

    public MyText

End class

function getMyClass(text)

    set getMyClass = new MyClass
    getMyClass.MyText = text

end function


    response.write(getmyclass("Here!").mytext & "<br/>")

function getMyArray(number)

    response.write("check: " & myArray(number).MyText & "<br/>")
    set getMyArray = new MyClass
    getMyArray = myArray(number)

end function

    response.write(getMyArray(1).mytext)

%>

This is the error I'm getting:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method

/carousel classes/funcarray.asp, line 32

And it refers to the function "getMyArray(number)"

1 Answer 1

0

I had to recode this to make it work...

<%

dim myArray(5), i

for i = 0 to 5
    response.write("i :" & i & "<br/>")
    set myArray(i) = new MyClass
    myArray(i).MyText = "Number " & i
next

class MyClass

    public MyText

End class

function getMyClass(text)
    dim rv
    set rv = new MyClass
    rv.MyText = text
    set getMyClass = rv
end function

response.write(getmyclass("Here!").mytext & "<br/>")

function getMyArray(number)
    response.write("check: " & myArray(number).MyText & "<br/>")
    set getMyArray = myArray(number)
end function

response.write(getMyArray(1).mytext)

%>

NOTES:

I removed the second line as it doesn't do what you think.

I found that the problem with your getMyClass function was that as soon as you Set the function name then the value is returned and no value will be passed to the MyText field.

The second function was nearly there and simply required the function name to be Set to one of the predefined array entries.

Sign up to request clarification or add additional context in comments.

Comments

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.