luckyliya 发表于 2006-3-27 16:03:00

(求助)有关周长的问题,帮忙看一下代码

<P>想求多个面域的累加周长,怎么做?有一段代码是求多个面域的累加面积的,程序正确.我把其中的area必成list ,想求周长,但运行时出错.</P>
<P>求累加面积的正确代码:</P>
<P>&nbsp;Public Sub carea()</P>
<P>&nbsp; On Error GoTo ErrorHandler</P>
<P>&nbsp; Dim pt As Variant<BR>&nbsp; Dim spt As String<BR>&nbsp; Dim i As Integer<BR>&nbsp; Dim zarea As Double<BR>&nbsp; zarea = 0</P>
<P>&nbsp; For i = 0 To 500<BR>&nbsp;&nbsp; pt = ThisDrawing.Utility.GetPoint(, vbCrLf &amp; "输入要计算面积对象的内部一点:")</P>
<P>&nbsp;&nbsp; spt = pt(0) &amp; "," &amp; pt(1)</P>
<P>&nbsp;&nbsp; With ThisDrawing<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "-boundary "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand spt &amp; " "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand " "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "area "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "o "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "last "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "erase "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "last "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand " "<BR>&nbsp;&nbsp; End With</P>
<P>&nbsp;&nbsp; zarea = zarea + ThisDrawing.GetVariable("AREA")<BR>&nbsp;&nbsp; ThisDrawing.Utility.Prompt vbCrLf &amp; "选定对象的总面积为: " &amp; zarea &amp; vbCrLf<BR>&nbsp; Next</P>
<P>ErrorHandler:<BR>&nbsp; Exit Sub<BR>End Sub</P>
<P>我改后的代码:</P>
<P>Public Sub clist()<BR>&nbsp; Dim pt As Variant<BR>&nbsp; Dim spt As String<BR>&nbsp; Dim i As Integer<BR>&nbsp; Dim zlist As Double<BR>&nbsp; zlist = 0</P>
<P>&nbsp; For i = 0 To ThisDrawing.ModelSpace.Count<BR>&nbsp;&nbsp; pt = ThisDrawing.Utility.GetPoint(, vbCrLf &amp; "输入要计算周长对象的内部一点:")</P>
<P>&nbsp;&nbsp; spt = pt(0) &amp; "," &amp; pt(1)</P>
<P>&nbsp;&nbsp; With ThisDrawing<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "-boundary "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand spt &amp; " "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand " "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "list"<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "last "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "erase "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand "last "<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendCommand " "<BR>&nbsp;&nbsp; End With</P>
<P>&nbsp;&nbsp; zlist = ThisDrawing.GetVariable("list")<BR>&nbsp;&nbsp; ThisDrawing.Utility.Prompt vbCrLf &amp; "选定对象的总面积为: " &amp; zlist<BR>&nbsp; Next</P>
<P>ErrorHandler:<BR>&nbsp; Exit Sub<BR>End Sub<BR></P>
<P>请大家多多指教,不胜感激.</P>

雪山飞狐_lzh 发表于 2006-3-27 16:42:00

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

luckyliya 发表于 2006-3-27 22:11:00

<P>我试过了,所有的内部面域都好用,但为什么最外的那个面域求得的结果不对呢,它的周长应该是最大的呀,可结果却是最小的</P>

luckyliya 发表于 2006-3-27 22:13:00

页: [1]
查看完整版本: (求助)有关周长的问题,帮忙看一下代码