kinglau 发表于 2006-3-14 09:47:00

写了段求长宽的程序,怎么没结果,请指点

<P>Sub 长宽()<BR>Dim startPnts As Variant, endPnts As Variant<BR>Dim s1 As Variant, e1 As Variant<BR>Dim l As Double, r As Double&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '左右坐标<BR>Dim t As Double, b As Double&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '上下坐标<BR>Dim x1 As Double, y1 As Double</P>
<P>Dim lineCount As Integer</P>
<P>lineCount = ThisDrawing.ModelSpace.Count<BR>ReDim lineObj(0 To lineCount - 1) As AcadEntity</P>
<P>Set lineObj(0) = ThisDrawing.ModelSpace.Item(0)<BR>startPnts = lineObj(0).StartPoint<BR>endPnts = lineObj(0).EndPoint<BR>r = Max1(startPnts(0), endPnts(0))<BR>t = Max1(startPnts(1), endPnts(1))<BR>l = Min1(startPnts(0), endPnts(0))<BR>b = Min1(startPnts(1), endPnts(1))</P>
<P>For i = 0 To lineCount - 1<BR>Set lineObj(i) = ThisDrawing.ModelSpace.Item(i)<BR>s1 = lineObj(i).StartPoint<BR>e1 = lineObj(i).EndPoint<BR>r = Max(s1(0), e1(0), r)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '求极值点<BR>t = Max(s1(1), e1(1), t)<BR>l = Min(s1(0), e1(0), l)<BR>b = Min(s1(1), e1(1), b)<BR>Next<BR>&nbsp; xl = r - l<BR>&nbsp; yl = t - b<BR>&nbsp; MsgBox x1<BR>&nbsp; MsgBox y1<BR>End Sub<BR>'以下为定义的求极值的函数</P>
<P>Public Function Min1(x As Variant, y As Variant)<BR>&nbsp; If x &lt; y Then<BR>&nbsp;&nbsp;&nbsp; Min1 = x<BR>&nbsp; Else<BR>&nbsp;&nbsp;&nbsp; Min1 = y<BR>&nbsp; End If<BR>&nbsp;<BR>&nbsp; <BR>End Function</P>
<P>Public Function Min(x As Variant, y As Variant, z As Variant)<BR>&nbsp;If x &gt; y Then<BR>&nbsp;&nbsp;&nbsp; x = y<BR>&nbsp;&nbsp; If x &gt; z Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = z<BR>&nbsp;&nbsp; End If<BR>&nbsp;Else<BR>&nbsp;&nbsp; If x &gt; z Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = z<BR>&nbsp;&nbsp; End If<BR>&nbsp;End If<BR>&nbsp;Min = x<BR>&nbsp;<BR>End Function</P>
<P><BR>Public Function Max1(x As Variant, y As Variant)<BR>&nbsp; If x &gt; y Then<BR>&nbsp;&nbsp;&nbsp; Max1 = x<BR>&nbsp; Else<BR>&nbsp;&nbsp;&nbsp; Max1 = y<BR>&nbsp; End If<BR>&nbsp; <BR>&nbsp; <BR>End Function</P>
<P>Public Function Max(x As Variant, y As Variant, z As Variant)<BR>&nbsp;If x &lt; y Then<BR>&nbsp;&nbsp;&nbsp; x = y<BR>&nbsp;&nbsp; If x &lt; z Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = z<BR>&nbsp;&nbsp; End If<BR>&nbsp;Else<BR>&nbsp;&nbsp; If x &lt; z Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = z<BR>&nbsp;&nbsp; End If<BR>&nbsp;End If<BR>&nbsp;Max = x<BR>&nbsp;<BR>End Function</P>

<P>运行结果为0,不知道是哪里出错了<BR></P>

kinglau 发表于 2006-3-14 16:04:00

<P>没人说几句么?</P>

cdb 发表于 2006-3-14 16:25:00

&nbsp; xl = r - l<BR>&nbsp; yl = t - b<BR>中的xl、yl有问题,应为x1、y1
页: [1]
查看完整版本: 写了段求长宽的程序,怎么没结果,请指点