明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2100|回复: 6

[求助]如何加while语句

[复制链接]
发表于 2005-4-12 17:10:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2005-4-12 19:41:53 编辑

下面程序如何加while语句,我想循环选择圆弧,直到回车结束程序。谢谢! Sub arc_to_circle()
Dim cen As Variant
Dim radius As Single
Dim obj As AcadArc
Dim circleObj As AcadCircle ThisDrawing.Utility.GetEntity obj, point, "选择圆弧:"
cen = obj.Center
radius = obj.radius
obj.Delete
Set circleObj = ThisDrawing.ModelSpace.AddCircle(cen, radius)
End Sub
发表于 2005-4-12 21:16:00 | 显示全部楼层
Sub arc_to_circle()
On Error GoTo ErrHandle
Dim cen As Variant
Dim radius As Single
Dim obj As AcadArc
Dim circleObj As AcadCircle
Do While True
ThisDrawing.Utility.GetEntity obj, Point, "选择圆弧:"
cen = obj.Center
radius = obj.radius
obj.Delete
Set circleObj = ThisDrawing.ModelSpace.AddCircle(cen, radius)
Loop
ErrHandle:
End Sub
 楼主| 发表于 2005-4-12 21:28:00 | 显示全部楼层
多谢版主指点,现在明白了!我刚开始接触VBA,所以有很多东西要学,还望你们多多指教!!
发表于 2005-4-12 21:55:00 | 显示全部楼层
Sub arc_to_circle()
Dim Centre As Variant
Dim BasePnt As Variant
Dim Rad As Double
Dim ReturnObj As AcadArc
Dim circleObj As AcadCircle
Dim Descript As String
Do
On Error Resume Next
ThisDrawing.Utility.InitializeUserInput 1, " "
ThisDrawing.Utility.GetEntity ReturnObj, BasePnt, "选择圆弧<Enter结束>:"
If Err <> 0 Then
Descript = Err.Description
Err.Clear
If Descript = "类型不匹配" Then
MsgBox "不是圆弧!"
Else
If Descript = "用户输入的是关键字" Then
Exit Do
Else
MsgBox "没有选择!"
End If
End If
Else
Centre = ReturnObj.center
Rad = ReturnObj.radius
ReturnObj.Delete
Set circleObj = ThisDrawing.ModelSpace.AddCircle(Centre, Rad)
End If
Loop
End Sub
发表于 2005-4-12 21:58:00 | 显示全部楼层
我的建议,尽量少用Err.Description,而用Err.Number好些,这样可以避免不同语言版本的问题。
发表于 2005-4-12 22:01:00 | 显示全部楼层
谢谢明总指教,呵呵
发表于 2005-4-13 09:47:00 | 显示全部楼层
我见好多代码里面都用 On Error Resume Next 这样好不好的啊?什么情况下应该而且提倡用,什么情况下最好不要用 啊,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 18:48 , Processed in 0.790313 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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