Object (data type)

Syntax Object
Description A data type used to declare OLE automation variables.
Comments The Object type is used to declare variables that reference objects within an application using OLE automation. Each object is a 4-byte (32-bit) value that references the object internally. The value 0 (or Nothing ) indicates that the variable does not reference a valid object, as is the case when the object has not yet been given a value. Accessing properties or methods of such Object variables generates a runtime error.
Using Objects Object variables are declared using the Dim, Public, or Private statement:
  Dim MyApp As Object
Object variables can be assigned values (thereby referencing a real physical object) using the Set statement:
  Set MyApp = CreateObject("phantom.application")
  Set MyApp = Nothing
Properties of an Object are accessed using the dot (.) separator:
  MyApp.Color = 10
  i% = MyApp.Color
Methods of an Object are also accessed using the dot (.) separator:
  MyApp.Open "sample.txt"
  isSuccess = MyApp.Save("new.txt",15)
Automatic Destruction The Basic Control Engine keeps track of the number of variables that reference a given object so that the object can be destroyed when there are no longer any references to it:
  Sub Main()               'Number of references to object
    Dim a As Object                 '0
    Dim b As Object                 '0
    Set a = CreateObject("phantom.application)  '1
    Set b = a                        '2
    Set a = Nothing                  '1
  End Sub                            '0 (object destroyed)
Note An OLE automation object is instructed by the Basic Control Engine to destroy itself when no variables reference that object. However, it is the responsibility of the OLE automation server to destroy it. Some servers do not destroy their objects—usually when the objects have a visual component and can be destroyed manually by the user.
See Also Currency (data type); Date (data type); Double (data type); Integer (data type); Long (data type); Single (data type); String (data type); Variant (data type); Boolean (data type); DefType (statement).