各位高手:请问遍历选择集时循环为什么从0到SSetObj.Count – 1,而不是从1到SSetObj.Count?当然如用For……Each循环不存在这个问题。请参阅以下程序,先谢谢各位!
用VBA清理空文本
Public Sub TextPurge()
Dim SSetObj As AcadSelectionSet '创建名为TextPurge选择集
Set SSetObj = ThisDrawing.SelectionSets.Add("TextPurge")
'创建过滤器,仅选择Attdef(属性定义)、Text(单行文本)、Mtext(多行文本)
'关于过滤器的使用,请参考有关书籍
Dim fType(0) As Integer '本句还可写成:Dim fType(0 To 0) As Integer
Dim fData(0) As String '本句还可写成:Dim fData(0 To 0) As Variant
fType(0) = 0
fData(0) = "Attdef,Text,Mtext"
'选择全部的Attdef、Text、Mtext
SSetObj.Select acSelectionSetAll, , , fType, fData
If SSetObj.Count <> 0 Then
Dim i As Integer
For i = 0 To SSetObj.Count – 1 '计数循环遍历选择集范例代码(一般提倡用For……Each循环)
'在Attdef中显示的是TagString,在Text和Mtext中显示的是TextString
If TypeOf SSetObj(i) Is AcadAttribute Then
If SSetObj(i).TagString = "" Then SSetObj(i).Delete '条件判断
Else
If SSetObj(i).TextString = "" Then SSetObj(i).Delete
End If
Next
End If
SSetObj.Delete
Set SSetObj = Nothing
End Sub
黄玉宏 2006.6.1
|