Creates a Global Default Instance of a class. The default instance is accessed via the name of the class.
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Class1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Function GiveMeATwo() As Integer
GiveMeATwo = 2
End Function
Debug.Print Class1.GiveMeATwo
In some ways, this simulates the behavior of static classes in other languages, but unlike other languages, you can still create an instance of the class.
Dim cls As Class1
Set cls = New Class1
Debug.Print cls.GiveMeATwo