Given the example I posted earlier,
Dim A as interger
A=3
Select Case A
Case 1:
Msgbox "A = 1"
Case 2:
Msgbox "A = 2"
Case 3:
Msgbox "A = 3"
Case Else:
Msgbox "A is not in the List"
End Select
Lets look at what is going on in this code. First I have to create the variable, A, so Dim A as integer.
Im using an integer just as an example. Then Set A=3. So everyone agrees A=3 right? OK, now the
Select Case statement.
Select Case A - which means, evaluate A, and see if it matches any of the choices that follow.
Case 1: - which means Does A=1? No, so go to next case.
Case 2: Does A=2? No, go to next case
Case 3: Does A=3? Yes, so do what follows which is a messagebox that says A=3
Had A not equaled 1, 2, or 3, the Case Else: would have been used as a catch all, w/ a box that said A is not in list.
Now how could we use that logic and trap an error for loading a linetype?
Public Sub LLINE()
On Error GoTo ErrorHandler
. . . . .
End Sub
We start by telling the code to GoTo the ErrorHandler if there is a problem. Following this, we can begin coding our app.
At some point, we put in the error handler
Public Sub LLINE()
On Error GoTo ErrorHandler
ThisDrawing.Linetypes.Load "HIDDEN", "ACAD.LIN"
ThisDrawing.Linetypes.Load "DASHED", "ACAD.LIN"
Exit Sub
ErrorHandler:
. . . . . .
End Sub
OK, so we have told Vb to use the error handler if needed, and we go to our first line, which says load the Hidden linetype.
If the linetype is already loaded, VB will raise an error code, specifially code " -2145386405" which is what we want to trap on.
So,Public Sub LLINE()
On Error GoTo ErrorHandler
ThisDrawing.Linetypes.Load "HIDDEN", "J:\TEP SUPPORT\ACAD.LIN"
ThisDrawing.Linetypes.Load "DASHED", "J:\TEP SUPPORT\ACAD.LIN"
Exit Sub
ErrorHandler:
Select Case Err
Case -2145386405:
Err.Clear
Resume Next
Case Else:
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Select
End Sub
So if Err = -2145386405, Clear the Err and then resume the program with the next line.
Knowing that the error was caused by the linetype already being loaded, we can trap that and move on without the user seeing
an error message.
Was everybody able to generate an error message before? Was the number the same? It should have been, because that is the number for duplicate linetypes