1

I have create a Node Object:

Public value As Integer
Public marked As Boolean

Private Sub Class_Initialize()
     value = 0
     marked = False
End Sub

Then I tried to add some Node Objects to a Collection in a for loop:

Dim inp As Integer
Dim counter As Integer
Dim n As node
Dim arr As Collection

Sub MySub()

    inp = InputBox("Insert a number: ")

    For counter = 2 To inp
        Set n = New node
        With n
            .value = counter
            .marked = False
        End With
        arr.Add n
    Next counter

End Sub

But when I try to run it it only says:

Object variable or With block variable not set (Error 91)

Why is that happening?

2
  • You're missing a Set arr = New Collection line. Commented Mar 17, 2017 at 14:57
  • @Rory Wow thanks, that was simple..... Write it as Answer, so that I can tick it :) Commented Mar 17, 2017 at 14:59

1 Answer 1

2

You're missing a line before your loop:

Set arr = New Collection
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.