Private Sub Class_Initialize()
If gCConnect Is Nothing Then
Dim CConn As Object
ConnNum = 1
Set CConn = New CDataConnection
Set gCConnect = CConn.CConnect
Else
ConnNum = ConnNum + 1
End If
End Sub
Private Sub Class_Terminate()
If ConnNum > 1 Then
ConnNum = ConnNum - 1
Else
gCConnect.Close
Set gCConnect = Nothing
End If
End Sub
'add some label and other objects(name is free)
Private Sub Command1_Click()
Dim objTest As Object
Dim lngLabelsCount As Long
lngLabelsCount = 0
For Each objTest In Form1
If TypeName(objTest) = "Label" Then
lngLabelsCount = lngLabelsCount + 1
End If
Next
MsgBox ("The count of label is" + Str(lngLabelsCount))