0

I created a class module Rect:

Public top As Single

Public left As Single

Public bottom As Single

Public right As Single

Public Sub Class_Initialize()
    Me.top = 0
    Me.bottom = 0
    Me.left = 0
    Me.right = 0
End Sub

And a factory function to create Rect objects:

Private Function n() As Rect
    Dim r As New Rect
    n = r
End Function

When I call function n() I got runtime error '91'. I don't know what is wrong...

JSPDeveloper01
  • 770
  • 2
  • 10
  • 25

1 Answers1

1

For object variables, you need to use Set to assign them:

Set n = r

See e.g. What does the keyword Set actually do in VBA?

Community
  • 1
  • 1
Andre
  • 26,751
  • 7
  • 36
  • 80
  • The call to the rect object returned by the function **n()** would have to be Set as well. `Dim newer as object: Set newer = n()`. I must be missing something. –  Aug 23 '15 at 08:57