This doesn't work:
clsTestDefaultInstance
Dim HowAmIInitialised As Integer
Private Sub Class_Initialize()
HowAmIInitialised = 99
End Sub
Public Sub CallMe()
Debug.Print "HowAmIInitialised=" & HowAmIInitialised
End Sub
i.e clsTestDefaultInstance.CallMe() outputs HowAmIInitialised=99 because Class_Initialize() is called even for the default instance.
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsTestDefaultInstance"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit
' test how class instance can tell if it is default
'clsTestDefaultInstance
Dim HowAmIInitialised As Integer
Private Sub Class_Initialize()
HowAmIInitialised = HowAmIInitialised + 1
End Sub
Public Sub CallMe()
Debug.Print "HowAmIInitialised=" & HowAmIInitialised
End Sub
VB_PredeclaredId =Trueand then you can create a global default instance of your user-defined class. Question is: Why need the OP to find out if he is using a default instance of his own class. That seems strange to me. Either you know it when you write the code or ...Class_Initialize()might not be called for the global default, but my test shows it is (as does putting a breakpoint on that routine)