- 积分
- 34652
- 明经币
- 个
- 注册时间
- 2003-11-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 2004-2-19 18:52:29 编辑
Sub totalnumber() Dim total As Double total = 0 Dim ssetObj As AcadSelectionSet Set ssetObj = CreateSelectionSet("numberobj") Dim ftype, fdata BuildFilter ftype, fdata, 0, "text" ssetObj.SelectOnScreen ftype, fdata For i = 0 To ssetObj.Count - 1 If IsNumeric(ssetObj.Item(i).TextString) Then total = total + ssetObj.Item(i).TextString Else End If Next i
ssetobj.delete ActiveDocument.Utility.Prompt "总和=" & total End Sub Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet '返回一个空白选择集 Dim ss As AcadSelectionSet On Error Resume Next Set ss = ThisDrawing.SelectionSets(ssName) If err Then Set ss = ThisDrawing.SelectionSets.Add(ssName) ss.Clear Set CreateSelectionSet = ss End Function Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes()) '用数组方式填充一对变量以用作为选择集过滤器使用 Dim ftype() As Integer, fdata() Dim index As Long, i As Long index = LBound(gCodes) - 1 For i = LBound(gCodes) To UBound(gCodes) Step 2 index = index + 1 ReDim Preserve ftype(0 To index) ReDim Preserve fdata(0 To index) ftype(index) = CInt(gCodes(i)) fdata(index) = gCodes(i + 1) Next typeArray = ftype: dataArray = fdata End Sub |
|