Hi susan.lee
Welcome on board
One possible and easy way is to use boolean variable
for final information at the end of program, you may want to
use instead other variables say one for particular action
within your program, but then you have to display al of then
in the screen or in the command line
(I'm personally still avoid to use MsgBox)
Give this a try:
Code:
<CommandMethod("tex")> _
Public Shared Sub TestForExceptionMessages()
'create variable to inform user about exception
Dim what As Boolean = True
' create variable for informative string
Dim result As String = String.Empty
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim peo As New PromptEntityOptions(vbLf & "Please, select a line: ")
peo.SetRejectMessage(vbLf & "Not a line...")
peo.AllowNone = False
peo.AddAllowedClass(GetType(Line), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Dim ppo As New PromptPointOptions(vbLf & "Please, specify a point: ")
ppo.AllowNone = True
Dim tm As Autodesk.AutoCAD.ApplicationServices.TransactionManager = doc.TransactionManager
'to force draw entity on screen
tm.EnableGraphicsFlush(True)
Using tr As Transaction = tm.StartTransaction()
'cast selected objec as line
Dim ln As Line = DirectCast(tr.GetObject(per.ObjectId, OpenMode.ForRead), Line)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
'create variable to count picked points
Dim pcount As Integer = 0
Dim id As ObjectId = ObjectId.Null
Try
While True
Dim ppr As PromptPointResult = ed.GetPoint(ppo)
If ppr.Status <> PromptStatus.OK Then
ed.WriteMessage(vbLf & "Inerrupted by user.")
Exit While
ElseIf ppr.Status = PromptStatus.OK Then
'count picked points
pcount += 1
End If
ppo.Message = vbLf & "Specify next point: "
Dim pt As Point3d = ppr.Value
Dim nl As New Line(pt, ln.EndPoint)
id = btr.AppendEntity(nl)
tm.AddNewlyCreatedDBObject(nl, True)
' force to draw entity
tm.QueueForGraphicsFlush()
' confirm force
tm.FlushGraphics()
ed.UpdateScreen()
End While
ed.WriteMessage(vbLf & "Number of oints: {0}: " & vbLf, pcount)
' gather all possible exceptions
If pcount < 1 Then what = False
' build informative string, e.g.:
result = IIf(what = True, "Success", "Fail")
'catch autocad based exception
Catch ex As Autodesk.AutoCAD.Runtime.Exception
what = False
ed.WriteMessage(vbLf & ex.Message & vbLf & ex.StackTrace & vbLf)
'catch high level exception
Catch exsys As System.Exception
what = False
ed.WriteMessage(vbLf & exsys.Message & vbLf & exsys.StackTrace & vbLf)
Finally
' commit transaction
tr.Commit()
' inform user about how to program ended up with
ed.WriteMessage(vbLf & "Program ended up with result of ""{0}""" & vbLf, result)
End Try
End Using
End Sub
So my recommendation is necessary to check each user input and each execution of individual commands
in your program and report these results to the command line, then after a thorough check of this program
you have remove some of them