写了段求长宽的程序,怎么没结果,请指点
<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 '左右坐标<BR>Dim t As Double, b As Double '上下坐标<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) '求极值点<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> xl = r - l<BR> yl = t - b<BR> MsgBox x1<BR> MsgBox y1<BR>End Sub<BR>'以下为定义的求极值的函数</P>
<P>Public Function Min1(x As Variant, y As Variant)<BR> If x < y Then<BR> Min1 = x<BR> Else<BR> Min1 = y<BR> End If<BR> <BR> <BR>End Function</P>
<P>Public Function Min(x As Variant, y As Variant, z As Variant)<BR> If x > y Then<BR> x = y<BR> If x > z Then<BR> x = z<BR> End If<BR> Else<BR> If x > z Then<BR> x = z<BR> End If<BR> End If<BR> Min = x<BR> <BR>End Function</P>
<P><BR>Public Function Max1(x As Variant, y As Variant)<BR> If x > y Then<BR> Max1 = x<BR> Else<BR> Max1 = y<BR> End If<BR> <BR> <BR>End Function</P>
<P>Public Function Max(x As Variant, y As Variant, z As Variant)<BR> If x < y Then<BR> x = y<BR> If x < z Then<BR> x = z<BR> End If<BR> Else<BR> If x < z Then<BR> x = z<BR> End If<BR> End If<BR> Max = x<BR> <BR>End Function</P>
<P>运行结果为0,不知道是哪里出错了<BR></P> <P>没人说几句么?</P> xl = r - l<BR> yl = t - b<BR>中的xl、yl有问题,应为x1、y1
页:
[1]