home *** CD-ROM | disk | FTP | other *** search
- *ERRTEXT
- ' Define your custom errors here. Be sure to use numbers
- ' greater than 512, to avoid conflicts with OLE error numbers.
- Public Const MyObjectError1 = 1000
- Public Const MyObjectError2 = 1010
- Public Const MyObjectErrorN = 1234
- Public Const MyUnhandledError = 9999
-
-
- Private Function GetErrorTextFromResource(ErrorNum As Long) _
- As String
- Dim strMsg As String
-
- ' this function will retrieve an error description from a resource
- ' file (.RES). The ErrorNum is the index of the string
- ' in the resource file. Called by RaiseError
-
- On Error GoTo GetErrorTextFromResourceError
-
- ' get the string from a resource file
- GetErrorTextFromResource = LoadResString(ErrorNum)
-
- Exit Function
-
- GetErrorTextFromResourceError:
-
- If Err.Number <> 0 Then
- GetErrorTextFromResource = "An unknown error has occurred!"
- End If
-
- End Function
-
- Public Sub RaiseError(ErrorNumber As Long, Source As String)
- Dim strErrorText As String
-
- 'there are a number of methods for retrieving the error
- 'message. The following method uses a resource file to
- 'retrieve strings indexed by the error number you are
- 'raising.
- strErrorText = GetErrorTextFromResource(ErrorNumber)
-
- 'raise an error back to the client
- Err.Raise vbObjectError + ErrorNumber, Source, strErrorText
-
- End Sub
- *END
-
- *CLASSID
- Function GetNextClassDebugID() As Long
- 'class ID generator
- Static lClassDebugID As Long
- lClassDebugID = lClassDebugID + 1
- GetNextClassDebugID = lClassDebugID
- End Function
- *END
-
- *INITTERM
- 'set this to 0 to disable debug code in this class
- #Const DebugMode = 1
-
- #If DebugMode Then
- 'local variable to hold the serialized class ID that was created in Class_Initialize
- Private mlClassDebugID As Long
- #End If
-
- Private Sub Class_Initialize()
- #If DebugMode Then
- 'get the next available class ID, and print out
- 'that the class was created successfully
- mlClassDebugID = GetNextClassDebugID()
- Debug.Print "'" & TypeName(Me) & "' instance " & mlClassDebugID & " created"
- #End If
- End Sub
-
- Private Sub Class_Terminate()
- 'the class is being destroyed
- #If DebugMode Then
- Debug.Print "'" & TypeName(Me) & "' instance " & CStr(mlClassDebugID) & " is terminating"
- #End If
- End Sub
-
- #If DebugMode Then
- Public Property Get ClassDebugID()
- 'if we are in debug mode, surface this property that consumers can query
- ClassDebugID = mlClassDebugID
- End Property
- #End If
- *END
-
- *COLLMETH
- 'local variable to hold collection
- Private mCol As Collection
-
- Public Property Get Count() As Long
- 'used when retrieving the number of elements in the
- 'collection. Syntax: Debug.Print x.Count
- Count = mCol.Count
- End Property
-
- Public Sub Remove(vntIndexKey As Variant)
- 'used when removing an element from the collection
- 'vntIndexKey contains either the Index or Key, which is why
- 'it is declared as a Variant
- 'Syntax: x.Remove(xyz)
-
- mCol.Remove vntIndexKey
- End Sub
-
- Public Property Get NewEnum() As IUnknown
- 'this property allows you to enumerate
- 'this collection with the For...Each syntax
- Set NewEnum = mCol.[_NewEnum]
- End Property
-
- Private Sub Class_Initialize()
- 'creates the collection when this class is created
- Set mCol = New Collection
- End Sub
-
- Private Sub Class_Terminate()
- 'destroys collection when this class is terminated
- Set mCol = Nothing
- End Sub
- *END
-
- *COLLITEMMETH
- 'used when referencing an element in the collection
- 'vntIndexKey contains either the Index or Key to the collection,
- 'this is why it is declared as a Variant
- 'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
- *END