VB6中:'类的声明: class1.cls
Public Event EventHelloWorld(msg As String)
Public Sub RaiseMyEvent()
    RaiseEvent EventHelloWorld("Hello!!!")
End Sub'模块: module1.bas
Public WithEvent myobj as Class1 '编译错误: 缺少:语句结束如何才能在模块中定义带事件的对象?

解决方案 »

  1.   

    MSDN:WithEvents is valid only in class modules. You can declare as many individual variables as you like using WithEvents, but you can't create arrays with WithEvents. You can't use New with WithEvents.
      

  2.   

    "WithEvents is valid only in class modules"
    窗体模块里不也是可以声明WithEvents的对象的吗?
      

  3.   

    WithEvents 只能在类或窗体使用, 不可以在模块使用, 应为模块不是事件驱动的!
      

  4.   

    要么你把事件封装在DLL中,然后再在窗体中调用