0


I'm trying to create an array of objects in vbscript, where each object has a string and a number as properties. The string is coming from a different array, and the number is incremented in the loop.


Here's the error occurring, on the line newValues(i) = (New Pet)(values(i), number):

enter image description here


...and here's my code:

Class Pet
    Public objectName
    Public objectNumber

    ' constructor here:
    Public Default Function Init(name, number)
        objectName = name
        objectNumber = number

        Set Init = Me
    End Function
End Class

values = Array(_
    "Cat",_
    "Dog",_
    "Bird"_
)

number = 3
ReDim newValues(uBound(values))

For i = 0 to uBound(values)
    newValues(i) = (New Pet)(values(i), number)
    number = number + 1
Next
2
  • 1
    Use Set when assigning objects. Set newValues(i) = (New Pet)(values(i), number) Commented Jun 19, 2014 at 15:53
  • Thanks @Bond, post this as an answer and I will accept! Commented Jun 19, 2014 at 16:01

1 Answer 1

2

Use Set when assigning objects.

Set newValues(i) = (New Pet)(values(i), number)
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.