VB统计CAD同名图块数量,请指点错误
Private Sub 同名图块数量统计_Click()On Error Resume Next
Dim returnobj As AcadObject
Dim basepnt As Variant
Dim icount, ocount,i
Thisdrawing.Utility.GetEntity returnobj, basepnt, "请选择一个统计对象"
Thisdrawing.SelectionSets("XZJ001").Delete
Set oSSet = Thisdrawing.SelectionSets.Add("XZJ001")
oSSet.SelectOnScreen
icount = 0
ocount = oSSet.count
For i = 0 To ocount
If oSSet(i).Name = returnobj.Name Then icount = icount + 1 ’问题在此,不论条件成立与否,都会执行then后的+1语句,求解
Next i
msgbox icount
oSSet.Delete
End Sub
Private Sub test_Click()
On Error Resume Next
Dim returnobj As AcadEntity
Dim mm As AcadEntity
Dim basepnt As Variant
Dim icount, ocount, i
ThisDrawing.Utility.GetEntity returnobj, basepnt, "ÇëÑ¡ÔñÒ»¸öͳ¼Æ¶ÔÏó"
ThisDrawing.SelectionSets("XZJ001").Delete
Set osset = ThisDrawing.SelectionSets.Add("XZJ001")
osset.SelectOnScreen
icount = 0
ocount = osset.Count
For Each mm In osset
If mm.name = returnobj.name Then icount = icount + 1
Next mm
MsgBox icount
osset.Delete
End Sub
验证通过 非常感谢您的回复,对我很有启示,多谢了。就是有点不明白"ÇëÑ¡ÔñÒ»¸öͳ¼Æ¶ÔÏó"是什么意思。 什么意思都不是,就是你的程序里的 "请选择一个统计对象"提示,不知什么原因从VBA拷出来的程序中文都是乱码
页:
[1]