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