明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1589|回复: 2

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

[复制链接]
发表于 2006-3-14 09:47:00 | 显示全部楼层 |阅读模式

Sub 长宽()
Dim startPnts As Variant, endPnts As Variant
Dim s1 As Variant, e1 As Variant
Dim l As Double, r As Double                          '左右坐标
Dim t As Double, b As Double                            '上下坐标
Dim x1 As Double, y1 As Double

Dim lineCount As Integer

lineCount = ThisDrawing.ModelSpace.Count
ReDim lineObj(0 To lineCount - 1) As AcadEntity

Set lineObj(0) = ThisDrawing.ModelSpace.Item(0)
startPnts = lineObj(0).StartPoint
endPnts = lineObj(0).EndPoint
r = Max1(startPnts(0), endPnts(0))
t = Max1(startPnts(1), endPnts(1))
l = Min1(startPnts(0), endPnts(0))
b = Min1(startPnts(1), endPnts(1))

For i = 0 To lineCount - 1
Set lineObj(i) = ThisDrawing.ModelSpace.Item(i)
s1 = lineObj(i).StartPoint
e1 = lineObj(i).EndPoint
r = Max(s1(0), e1(0), r)                          '求极值点
t = Max(s1(1), e1(1), t)
l = Min(s1(0), e1(0), l)
b = Min(s1(1), e1(1), b)
Next
  xl = r - l
  yl = t - b
  MsgBox x1
  MsgBox y1
End Sub
'以下为定义的求极值的函数

Public Function Min1(x As Variant, y As Variant)
  If x < y Then
    Min1 = x
  Else
    Min1 = y
  End If
 
 
End Function

Public Function Min(x As Variant, y As Variant, z As Variant)
 If x > y Then
    x = y
   If x > z Then
      x = z
   End If
 Else
   If x > z Then
      x = z
   End If
 End If
 Min = x
 
End Function


Public Function Max1(x As Variant, y As Variant)
  If x > y Then
    Max1 = x
  Else
    Max1 = y
  End If
 
 
End Function

Public Function Max(x As Variant, y As Variant, z As Variant)
 If x < y Then
    x = y
   If x < z Then
      x = z
   End If
 Else
   If x < z Then
      x = z
   End If
 End If
 Max = x
 
End Function

运行结果为0,不知道是哪里出错了

 楼主| 发表于 2006-3-14 16:04:00 | 显示全部楼层

没人说几句么?

发表于 2006-3-14 16:25:00 | 显示全部楼层
  xl = r - l
  yl = t - b
中的xl、yl有问题,应为x1、y1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 06:28 , Processed in 0.228995 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表