计算选择集中某个字符个数的问题:
以下是我的代码:
Public Sub count()
On Error Resume Next Dim objtext As AcadText Dim height As Double Dim width As Double Dim SSet As AcadSelectionSet If Not IsNull(ThisDrawing.SelectionSets.Item("this")) Then Set SSet = ThisDrawing.SelectionSets.Item("this") SSet.Delete End If Set SSet = ThisDrawing.SelectionSets.Add("this") Dim filterType(0) As Integer Dim filterData(0) As Variant filterType(0) = 0 filterData(0) = "Text" SSet.SelectOnScreen filterType, filterData Dim pt1(0 To 2) As Double Dim pt2(0 To 2) As Double pt1(0) = 0: pt1(1) = 0: pt1(2) = 0 pt2(0) = 0: pt2(1) = 180: pt2(2) = 0 Dim n As Integer n = 0 For Each objtext In SSet If objtext.TextString = "T" Then n = n + 1 AddLine pt1, pt2 MsgBox "一共有" & n & "个字符", vbOKOnly EXIT FOR Next End Sub
运行得到的结果却与想象中的相差较远,
我本想输出选择集中“T”的数量,(例如T是选择集中任一字符),而输出结果为0,
请问上面的函数该如何修正?
是否要用LEN函数来统计字符数量? |