Syntax 

[ | Private | Public ] _

Class name

    ...

End Class


Group 

Declaration 


Description 

A class implements an object.


  • Has a set of Public procedures accessible from other macros.
  • These public symbols are accessed via an object variable.
  • Has an optional set of Events that can be raised.
  • To create an instance use:

    Dim Obj As classname
    Set Obj = New classname


Macro

One or more Class blocks can be declared in a macro in addition to variable and procedure declarations.


Option Explicit

Class Class1

    Public Data As String

    Private Sub Class_Initialize

        Data = "Hello"

    End Sub

End Class

Sub Main

    Dim c1 As New Class1

    Debug.Print c1.Data '"Hello"

    c1.Data = "Bye"

    Debug.Print c1.Data '"Bye"

End Sub


Example

Option Explicit

Class File

    Dim FN As Integer

 

    Public Sub Attach(FileName As String)

        FN = FreeFile

        Open FileName For Input As #FN

    End Sub

 

    Public Sub Detach()

        If FN <> 0 Then Close #FN

        FN = 0

    End Sub

 

    Public Function ReadLine() As String

        Line Input '#'FN, ReadLine

    End Function

End Class