明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 669|回复: 4

【求助】大神看一下我的代码错在哪里?

[复制链接]
发表于 2017-11-3 11:25 | 显示全部楼层 |阅读模式
代码运行后,不能停止循环,按ESC也不行。
Public Sub CreateXH()
    On Error Resume Next
    Dim color As New AcadAcCmColor '设置颜色
    color.ColorIndex = acGreen

    Dim pt1 As Variant
    Dim pt2(0 To 2) As Double
    Dim textObj As AcadText
    Dim num As Long
    Dim i As Long
    Dim height As Double
    Dim radius As Double
    Dim ptMin As Variant
    Dim ptMax As Variant
    Dim objCircle As AcadCircle

    radius = 5
    height = 5
    num = 1

    If KeyCode = vbKeyEscape Then
        Exit Sub
    End If
    For num = num To 99999
        If KeyCode = vbKeyEscape Then
            Exit Sub
        End If
        pt1 = ThisDrawing.Utility.GetPoint(, "请指定点:")
        Set textObj = ThisDrawing.ModelSpace.AddText(num, pt1, height)
        textObj.TrueColor = color
        textObj.GetBoundingBox ptMin, ptMax
        pt2(0) = (ptMin(0) + ptMax(0)) / 2
        pt2(1) = (ptMin(1) + ptMax(1)) / 2
        pt2(2) = (ptMin(2) + ptMax(2)) / 2
        Set objCircle = ThisDrawing.ModelSpace.AddCircle(pt2, radius)
        objCircle.TrueColor = color
        textObj.Update
    Next

End Sub


 楼主| 发表于 2017-11-3 11:25 | 显示全部楼层
消灭零回复
发表于 2017-11-3 14:03 | 显示全部楼层
    Err.Clear
    endPnt = ActiveDocument.Utility.GetPoint(endPnt, vbLf & "继续选择目标点,按右键或ESC退出:")
    If Not ((Err.Number = -2147467259) Or (Err.Number = -2147352567) Or (Err.Number = -2145320928)) Then GoTo MultiCopy
发表于 2017-11-9 17:27 | 显示全部楼层
怎么可能在程序运行到IF之前响应到ESC按键呢?所以不会停
发表于 2020-1-10 16:56 | 显示全部楼层
循环内加一个 on error goto uuu
代码底部加一个 uuu:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-20 11:58 , Processed in 0.195253 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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