乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 36|回复: 3

请教VBA的错误处理

[复制链接]

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2004-8-19 16:19:00 | 显示全部楼层 |阅读模式
我希望第二次使用程序时不会提示“ 所命名的选择集已经存在”, 用下列代码:
On Error Resume Next
Set sset = ThisDrawing.SelectionSets.Add(62)
       
       
       
If Err Then
        Err.Clear
       
       
         sset.Delete
        End If
Set sset = ThisDrawing.SelectionSets.Add(62)
         sset.SelectOnScreen
        For Each ent In sset
                         If ent.EntityName = "AcDbLine" Then
                                         
                         pstart = ent.StartPoint
                         pend = ent.EndPoint
                         End If
         Next
        运行时不会提示错误, 但却不让选择图元, 直接运行这段代码以后的语句。
                请各位帮忙解决。 谢谢!
回复

使用道具 举报

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2004-8-19 21:33:00 | 显示全部楼层
我已经找到错误的地方, 以下这样就可以了:
         On Error Resume Next
Set sset = ThisDrawing.SelectionSets("62")
       
       
       
If Err Then
        Err.Clear
       
       
         sset.Delete
        End If
Set sset = ThisDrawing.SelectionSets.Add("62")
         sset.SelectOnScreen
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2004-8-19 21:36:00 | 显示全部楼层
复制代码
回复

使用道具 举报

124

主题

837

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1333
发表于 2004-8-20 09:54:00 | 显示全部楼层
建立一个函数:
Private Function CreateSSet(ByVal name As String) As AcadSelectionSet
                         On Error GoTo ERR_HANDLER
                         
                         Dim ssetObj As AcadSelectionSet
                         Dim SSetColl As AcadSelectionSets
                         Set SSetColl = ThisDrawing.SelectionSets
                         
                         Dim index As Integer
                         Dim found As Boolean
                         
                         found = False
                         For index = 0 To SSetColl.Count - 1
                                                         Set ssetObj = SSetColl.Item(index)
                                                         If StrComp(ssetObj.name, name, 1) = 0 Then
                                                                                         found = True
                                                                                         Exit For                         'Important.
                                                         End If
                         Next
                         
                         If Not (found) Then
                                                         Set ssetObj = SSetColl.Add(name)
                         Else
                                                         ssetObj.Delete         '
                                                         Set ssetObj = SSetColl.Add(name)
                         End If
                         
                         Set CreateSSet = ssetObj
                         
                         Exit Function
ERR_HANDLER:
                         '-----------------------------------------------
                         ' just print the error the the debug window.
                         Debug.Print "Error in sub CreateSSet: " & Err.Number & " -- "; Err.Description
                         Resume ERR_END
                         
ERR_END:
End Function
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-8-19 14:57 , Processed in 3.457277 second(s), 61 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表