Cconsider spending more time on language and
framework theory and concepts, and learning to
use the language correctly.
IOW, you're using constructs like 'Try/Finally'
and 'Using', without really understanding exactly
what they are or how they work.
Your mixing the use of 'Using' with Try/Finally to
manage transactions, and also not knowing how to
deal with different types of objects, makes it clear
that you're still missing some basic key concepts
that you need, before you can write working code
that you can be reasonably confident will not blow
up when you try to use it.
Here is a sample sub that shows the correct way to
deal with transactions (call Commit() when you're
done, or let the transaction abort if your code fails
before that) and how to test the type of an object,
and then cast to a more specific type.
To get any type of valid candidate entity, you assign
first to the more generic 'Entity' type, and then test
the object's actual type using TypeOf to see if it is
DBText or MTEXT. Once you know which type it is,
you can then cast the object to a variable of that
type (DBText or MText in this case).
As far as combining the two subs you have, I'm
not going to do that, but this should give you an
idea of how to do it yourself.
Private Sub Example()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim Values() As TypedValue = {New TypedValue(DxfCode.Start, "TEXT")}
Dim prFilter As SelectionFilter = New SelectionFilter(Values)
Dim res As PromptSelectionResult = ed.SelectAll(prFilter)
If res.Status = PromptStatus.Error Then Return
Dim SS As SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()
For i As Integer = 0 To idarray.Length - 1
Dim id As ObjectId = res.Value.Item(i).ObjectId
' all objects encountered here must derive from 'Entity',
' so that is the type you cast to first:
Dim ent1 As Entity = DirectCast(trans.GetObject(id, OpenMode.ForWrite), Entity)
' Next see if the entity's actual type is DBText or MText,
' branch accordingly and cast to a variable of the actual
' type, and then work with the object:
If TypeOf ent1 Is DBText Then
Dim dbtext As DBText = DirectCast(ent1, DBText)
Console.Write("This is a TEXT object")
' code to handle TEXT here
ElseIf TypeOf ent1 Is MText Then
Dim mtext as MText = DirectCast(ent1, MText)
Console.Write("This is an MTEXT object")
' code to handle MTEXT here
End If
Next
' ------------------------------------------------------
' Don't put Commit() in a 'Finally' because you don't
' want to commit the transaction if something
' goes wrong above, and the flow of execution
' transfers out of the Using block prematurely.
' ------------------------------------------------------
trans.Commit()
' The Using construct automatically calls Dispose()
' on the Transaction object here, so you do not need
' to do that manually.
End Using
End Sub
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
wrote in message news:5494053@discussion.autodesk.com...
Thanks for your concern,Tony.
Of course, I know how to.
I attached file working in the each subroutine.
I wish to merge this two subroutines to unique one.