I also have 2 types of error checking in this function. As it is writen right now, the error handler takes care of the error. to utilize the other method, the ' needs to be removed in fron of IF and END IF
Private Sub LLayer(ByRef Lname As String, Optional Lcolor As Integer, Optional Ltype As String)
Dim objLayer As AcadLayer
On Error GoTo ErrorHandler
If DoesLayerExist(Lname) = False Then
Set objLayer = ThisDrawing.Layers.Add(Lname)
'SHOW 2 WAYS TO ERROR TRAP THIS
' If Lcolor <> 0 Then
objLayer.color = Lcolor
' End If
' If Ltype <> "" Then
objLayer.Linetype = Ltype
' End If
End If
GoTo Clean_Up
ErrorHandler:
Select Case Err
Case -2145320939:
Err.Clear
MsgBox "Invalid Color call"
Resume Next
Case -2145386493:
Err.Clear
MsgBox "Invalid Linetype call"
Resume Next
Case Else:
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Select
Clean_Up:
Set objLayer = Nothing
Lcolor = 0
Lname = ""
Ltype = ""
Exit Sub
End Sub
Notice the commented out lines (the lines beginning with an ')
There are 2 ways to error check this function, and I'm not sure I should show this, but it might inspire somebody to great things.
One way should be very obvious: On Error GoTo ErrorHandler.
The second way uses If..Then statements to test the values of the Arguments passed in to check their values. When we do not pass in an integer, Lcolor defaults to 0 (Zero). A layer can not have a color of 0, agreed? So, we can trap this 2 ways.
1- Let the ErrorHandler handle the error created when objLayer.color=0 is called or
2- Check to see IF Lcolor <> (is not equal to) 0 and if its not, THEN set objLayer.color = ArgumentColor
Does everyone understand this?