xinghesnak 发表于 2006-3-9 13:22:00

isnumber是VB自带的函数啊!有问题?

雪山飞狐_lzh 发表于 2006-3-9 13:51:00

Sub tt()<BR>On Error Resume Next<BR>Dim ss As AcadSelectionSet<BR>Dim ft(0) As Integer, fd(0)<BR>ThisDrawing.SelectionSets("Test").Delete<BR>Set ss = ThisDrawing.SelectionSets.Add("Test")<BR>ft(0) = 0: fd(0) = "*Text"<BR>&nbsp;&nbsp;&nbsp; ss.SelectOnScreen ft, fd<BR>&nbsp;&nbsp;&nbsp; textvalue = 0<BR>&nbsp;&nbsp;&nbsp; For Each i In ss<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If IsNumeric(i.TextString) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textvalue = textvalue + Val(i.TextString)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; MsgBox "The result is:" &amp; textvalue<BR>End Sub<BR>

xinghesnak 发表于 2006-3-9 14:56:00

<P>呵呵!是IsNumeric不是IsNumber,记错了......</P>

雪山飞狐_lzh 发表于 2006-3-22 22:01:00

<P>这样可以只选择数据字符,就不用IsNumeric判断了</P>
<P>Sub tt()<BR>On Error Resume Next<BR>Dim ss As AcadSelectionSet<BR>Dim ft(2) As Integer, fd(2)<BR>ThisDrawing.SelectionSets("Test").Delete<BR>Set ss = ThisDrawing.SelectionSets.Add("Test")<BR>ft(0) = 0: fd(0) = "*Text"<BR>ft(1) = 1: fd(1) = "~*[~.0-9]*"<BR>ft(2) = 1: fd(2) = "~*.*.*"<BR>&nbsp;&nbsp;&nbsp; ss.SelectOnScreen ft, fd<BR>&nbsp;&nbsp;&nbsp; textvalue = 0<BR>&nbsp;&nbsp;&nbsp; For Each i In ss<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textvalue = textvalue + Val(i.TextString)<BR>&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; MsgBox "The result is:" &amp; textvalue<BR>End Sub</P>
<P><BR>&nbsp;</P>
页: 1 [2]
查看完整版本: 请教高手怎样选择框内数字,并将他们相加,计算和是多少?