Class Module
Group:Declaration
Description:
A class module
implements an ActiveX Automation object.
• Has a set of Publicprocedures accessible from other macros and modules.
• These public symbols are accessed via an object variable.
• Public Consts, Types, arrays, fixed length strings are not allowed.
• A class module is similar to a object module except that no instance is automatically created.
• To create an instance use:
Dim Obj As classname
Set Obj = New classname
See Also:Code Module, Object Module, Uses.
Example:
'A.WWB
'#Uses "File.CLS"
Sub Main
Dim File As New File
File.Attach "C:\AUTOEXEC.BAT"
Debug.Print File.ReadLine
EndSub
'File.CLS
'File|New Module|Class Module
'Edit|Properties|Name=File
Option Explicit
Dim FN As Integer
PublicSub Attach(FileName As String)
FN = FreeFile
Open FileName ForInput As #FN
EndSub
PublicSub Detach()
If FN <> 0 Then Close #FN
FN = 0
EndSub
PublicFunction ReadLine() As String
LineInput #FN,ReadLine
EndFunction
PrivateSub Class_Initialize()
Debug.Print "Class_Initialize"
EndSub
PrivateSub Class_Terminate()
Debug.Print "Class_Terminate"
Detach