Share this Page URL

A VBA Language Primer > Collections - Pg. 422

However you create an object, you can then call the object's methods and access its properties by typing the object variable followed by a dot and a method or property name (this is called dot notation ). When you're done using an object, you need to get rid of it. You do this by setting your variable to the special object value Noth ing . This will delete the object's memory, and keep it from consuming resources on your machine unnecessarily. Example 18-23 illustrates these concepts. Example 18-23. Creating, Calling, and Destroying an Object ' One line object creation Dim objWidget As New Widget ' Object variable declaration, followed by assignment of a ' new object Dim objThing As Thingamabob Set objThing = New Thingamabob Dim nResult As Integer Dim nPropVal As Integer ' Calling an object method (subprocedure) objWidget.DoSomething ' Calling an object method (function) nResult = objThing.Calculate(5,3) ' Setting a property objThing.Size = 5