乐筑天下

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

从帮助里拷贝的代码出问题了,大家帮忙看一下。

[复制链接]

32

主题

73

帖子

3

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
201
发表于 2004-7-10 10:35:00 | 显示全部楼层 |阅读模式
错误提示在WithEvents上,提示:仅在模块中有效。不过变量声明是在模块中啊。 以下是从帮助里拷贝的代码:
Option Explicit
Public WithEvents PLine As AcadLWPolyline
Sub Example_Modified()
                                 ' This example creates a lightweight polyline in model space and
                                 ' references the PolyLine using the public variable (PLine) which
                                 ' is set up to intercept Modified events.
                                 '
                                 ' This example then modifies the new object, triggering the code
                                 ' in the Modified event.
                         
                         Dim points(0 To 9) As Double
                         
                         ' Define the 2D polyline points
                         points(0) = 1: points(1) = 1
                         points(2) = 1: points(3) = 2
                         points(4) = 2: points(5) = 2
                         points(6) = 3: points(7) = 2
                         points(8) = 4: points(9) = 4
                                                         
                         ' Create a lightweight Polyline object in model space
                         '
                         ' * Note: We are returning the new PolyLine object into a Module
                         ' level variable.         This allows us to intercept events associated
                         ' with that particular object.
                         Set PLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
                         
                         ThisDrawing.Application.ZoomAll
                         
                         ' Modify object to trigger event.
                         '
                         ' * Note: The event code for the PolyLine modification will be triggered
                         ' before we move forward and refresh the view, so the line will not
                         ' appear blue when the event message box is displayed.
                         Dim color As AcadAcCmColor
                         Set color = AcadApplication.GetInterfaceObject(".AcCmColor.16")
                         Call color.SetRGB(80, 100, 244)
                         PLine.TrueColor = color
                         ThisDrawing.Regen acAllViewports
                         
End Sub
Private Sub PLine_Modified(ByVal pObject As AutoCAD.IAcadObject)
                         ' This example intercepts an object's Modified event.
                         '
                         ' This event is triggered when an object supporting this event is modified.
                         '
                         ' To trigger this code: Modify an object connected to this event
                         ' * Note: By connected, we mean the object set up to intercept events using
                         ' the VBA WithEvents statement
                         ' Use the "pObject" variable to determine which object was modified
                         MsgBox "You just modified an object with an ID of: " & pObject.ObjectID
                         
End Sub
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2004-7-10 14:12:00 | 显示全部楼层
放在ThisDrawing模块里
回复

使用道具 举报

32

主题

73

帖子

3

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
201
发表于 2004-7-10 18:49:00 | 显示全部楼层
放在类模块里可以。
不知道在VB里放在一般模块、类模块里可不可以。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-15 21:11 , Processed in 0.491229 second(s), 58 queries .

© 2020-2025 乐筑天下

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