tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
We can easily add a class to a collection as follows:
Class1
Standard module:
Can I add a class to an array? This doesn't work:
It shows an error on this line:
with the message:
Thanks
Class1
Code:
Option Explicit
Public name As String
Public age As Integer
Standard module:
Code:
Sub UsingCollection()
Dim a As Class1
Set a = New Class1
a.age = 10
a.name = "Apple"
Dim Coll As Collection
Set Coll = New Collection
Coll.Add a
End Sub
Can I add a class to an array? This doesn't work:
Code:
Sub UsingArray()
Dim MyArray(1 To 2, 1 To 1) As Variant
Dim b As Class1
Set b = New Class1
b.age = 20
b.name = "Orange"
MyArray(1, 1) = b
End Sub
It shows an error on this line:
Code:
MyArray(1, 1) = b
with the message:
Code:
object doesn't support this property or method
Thanks