将数字求和的程序
本帖最后由 作者 于 2004-2-19 18:52:29 编辑 <br /><br /> Sub totalnumber()<BR> Dim total As Double<BR> total = 0<BR> Dim ssetObj As AcadSelectionSet<BR> Set ssetObj = CreateSelectionSet("numberobj")<BR> Dim ftype, fdata<BR> BuildFilter ftype, fdata, 0, "text"<BR> ssetObj.SelectOnScreen ftype, fdata<BR> For i = 0 To ssetObj.Count - 1<BR> If IsNumeric(ssetObj.Item(i).TextString) Then<BR> total = total + ssetObj.Item(i).TextString<BR> Else<BR> End If<BR> Next issetobj.delete<BR> ActiveDocument.Utility.Prompt "总和=" & total<BR>End Sub<BR>Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet<BR> '返回一个空白选择集<BR> <BR> Dim ss As AcadSelectionSet<BR> <BR> On Error Resume Next<BR> Set ss = ThisDrawing.SelectionSets(ssName)<BR> If err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)<BR> ss.Clear<BR> Set CreateSelectionSet = ss<BR>End Function<BR>Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())<BR> '用数组方式填充一对变量以用作为选择集过滤器使用<BR> Dim ftype() As Integer, fdata()<BR> Dim index As Long, i As Long<BR> <BR> index = LBound(gCodes) - 1<BR> <BR> For i = LBound(gCodes) To UBound(gCodes) Step 2<BR> index = index + 1<BR> ReDim Preserve ftype(0 To index)<BR> ReDim Preserve fdata(0 To index)<BR> ftype(index) = CInt(gCodes(i))<BR> fdata(index) = gCodes(i + 1)<BR> Next<BR> typeArray = ftype: dataArray = fdata<BR>End Sub 参考了<B>subtlation</B>的相关程序,在此感谢!
将所选图元中的内容为数字的字符求和,对统计材料有一定帮助. 好程序,很简洁。提个小建议,最好在程序的结束前加上:ssetobj.delete
这样可以清除选择集。 已改过,谢谢.
现在框选时是将所有的文本都选中,能不能做到只选中内容为数字的文本? 我不会用,谁教我一下好吗? 我很需要这个程序,可是我不会用,希望谁帮我解答一下!万分感谢! 能不能将求得的结果以指定位置写入图中 怎么加载这个程序,哪位大侠帮忙! 学习中 对于如:DN50-100,没法统计,能不能改进呢?