(求助)有关周长的问题,帮忙看一下代码
<P>想求多个面域的累加周长,怎么做?有一段代码是求多个面域的累加面积的,程序正确.我把其中的area必成list ,想求周长,但运行时出错.</P><P>求累加面积的正确代码:</P>
<P> Public Sub carea()</P>
<P> On Error GoTo ErrorHandler</P>
<P> Dim pt As Variant<BR> Dim spt As String<BR> Dim i As Integer<BR> Dim zarea As Double<BR> zarea = 0</P>
<P> For i = 0 To 500<BR> pt = ThisDrawing.Utility.GetPoint(, vbCrLf & "输入要计算面积对象的内部一点:")</P>
<P> spt = pt(0) & "," & pt(1)</P>
<P> With ThisDrawing<BR> SendCommand "-boundary "<BR> SendCommand spt & " "<BR> SendCommand " "<BR> SendCommand "area "<BR> SendCommand "o "<BR> SendCommand "last "<BR> SendCommand "erase "<BR> SendCommand "last "<BR> SendCommand " "<BR> End With</P>
<P> zarea = zarea + ThisDrawing.GetVariable("AREA")<BR> ThisDrawing.Utility.Prompt vbCrLf & "选定对象的总面积为: " & zarea & vbCrLf<BR> Next</P>
<P>ErrorHandler:<BR> Exit Sub<BR>End Sub</P>
<P>我改后的代码:</P>
<P>Public Sub clist()<BR> Dim pt As Variant<BR> Dim spt As String<BR> Dim i As Integer<BR> Dim zlist As Double<BR> zlist = 0</P>
<P> For i = 0 To ThisDrawing.ModelSpace.Count<BR> pt = ThisDrawing.Utility.GetPoint(, vbCrLf & "输入要计算周长对象的内部一点:")</P>
<P> spt = pt(0) & "," & pt(1)</P>
<P> With ThisDrawing<BR> SendCommand "-boundary "<BR> SendCommand spt & " "<BR> SendCommand " "<BR> SendCommand "list"<BR> SendCommand "last "<BR> SendCommand "erase "<BR> SendCommand "last "<BR> SendCommand " "<BR> End With</P>
<P> zlist = ThisDrawing.GetVariable("list")<BR> ThisDrawing.Utility.Prompt vbCrLf & "选定对象的总面积为: " & zlist<BR> Next</P>
<P>ErrorHandler:<BR> Exit Sub<BR>End Sub<BR></P>
<P>请大家多多指教,不胜感激.</P> Public Sub clist()
Dim pt As Variant
Dim spt As String
Dim i As Integer
pt = ThisDrawing.Utility.getpoint(, vbCrLf & "输入要计算周长对象的内部一点:")
spt = pt(0) & "," & pt(1)
ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "o" & vbCr & "r" & vbCr & vbCr & spt & vbCr & vbCr
If (ThisDrawing.GetVariable("LASTPROMPT") <> "已创建 0 个面域。") Then
MsgBox ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1).Perimeter
ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1).Delete
End If
End Sub
<P>我试过了,所有的内部面域都好用,但为什么最外的那个面域求得的结果不对呢,它的周长应该是最大的呀,可结果却是最小的</P>
页:
[1]