Public Event helloworld()Private Sub Command1_Click()
    RaiseEvent helloworld
End Sub还需要什么? 事件怎么定义让他干什么? 比如就print "hello world"

解决方案 »

  1.   

    Private Sub Command1_Click()
        Call printstr
    End Sub
    -------------------------------
    Private Sub printstr()
            Print "hi"
    End Sub
      

  2.   

    楼上的没有 event 啊我得到的开发接口 是定义了event的 必须用到
      

  3.   

    一个对象定义的事件,它的实例中才能体现出来。例如在 class / UserControl 等等
    然后在窗口中,才能体现这些事件。
      
      

  4.   

    楼上的请再具体一点我在ActiveX 里面 写了Option Explicit
    Public Event helloworld()然后再一个标准工程中引用了这个控件
    Private Sub Command1_Click()
        RaiseEvent helloworld
    End Sub什么也没有发生的啊
    要如何才能让他发生些什么
      

  5.   

    VB里面的类如何定义? MSDN里面给了这样一句,为啥编译不过?
    Public Class ThisClass
      ' [variable, property, method and event declarations]
    End Class一个类的源代码在哪里声明的?如何看到比如我有两个按钮 我发现可以这样调用一个事件
    Private Sub Command1_Click()
        RaiseEvent Command2.Drag
    End Sub但是这个按钮的事件也太少了 竟然没有click
      

  6.   

    'Form1.frm
    'A form , a CommandButton name Command1
    Option Explicit
    Dim WithEvents cls As Class1Private Sub cls_MyHelloFunc(name As String)
      MsgBox "now, name=" & name
      name = "I am Simon!"
    End SubPrivate Sub Command1_Click()
      cls.test ""
    End SubPrivate Sub Form_Load()
      Set cls = New Class1
      
    End Sub'Class1.clsOption ExplicitPublic Event MyHelloFunc(name As String)Public Sub test(ByVal condiction As String)
      Dim name As String
      name = "Hello"
      RaiseEvent MyHelloFunc(name)
      
      MsgBox "last name=" & name
    End Sub
      
      

  7.   

    Event 语句示例
    下面的示例是在百米赛跑演示中使用事件来计时。代码说明了所有与事件相关的方法、属性和语句,包括 Event 语句。产生事件的类是事件源,实现该事件的类则是事件吸收。一个事件源可以有多个针对其所产生的事件的漏。事件可以被每个选定出为对象的实例吸收事件的类所触发。该示例使用了一个窗体 (Form1),该窗体有一个按钮 (Command1),一个标签 (Label1),以及两个文本框 (Text1 和 Text2)。单击按钮后,第一个文本框显示 "From Now",第二个文本框中时钟开始计时。当经过 9.84 秒(百米记录)之后,第一个文本框显示 "Until Now",第二个则显示 "9.84"。Form1 代码用于指定该窗体的初始状态和终止状态,也包含了事件产生后所要执行的代码。Option ExplicitPrivate WithEvents mText As TimerStatePrivate Sub Command1_Click()
    Text1.Text = "From Now"
        Text1.Refresh
        Text2.Text = "0"
        Text2.Refresh
    Call mText.TimerTask(9.84)
    End SubPrivate Sub Form_Load()
        Command1.Caption = "Click to Start Timer"
        Text1.Text = ""
        Text2.Text = ""
        Label1.Caption = "The fastest 100 meter run took this long:"
        Set mText = New TimerState
        End SubPrivate Sub mText_ChangeText()
        Text1.Text = "Until Now"
        Text2.Text = "9.84"
    End SubPrivate Sub mText_UpdateTime(ByVal dblJump As Double)
        Text2.Text = Str(Format(dblJump, "0"))
        DoEvents
    End Sub下面是 TimerState 类模块的代码。事件产生后 Event 语句声明被初始化的过程。Option Explicit
    Public Event UpdateTime(ByVal dblJump As Double)
    Public Event ChangeText()Public Sub TimerTask(ByVal Duration As Double)
        Dim dblStart As Double
        Dim dblSecond As Double
        Dim dblSoFar As Double
        dblStart = Timer
        dblSoFar = dblStart
        
        Do While Timer < dblStart + Duration
            If Timer - dblSoFar >= 1 Then
                dblSoFar = dblSoFar + 1
                RaiseEvent UpdateTime(Timer - dblStart)
            End If
        Loop
        
        RaiseEvent ChangeText
        
    End Sub
      

  8.   

    类模块中:
    Public Event helloworld()
    Public Function fun()
       RaiseEvent helloworld
    End Function
    窗口中:
    Dim WithEvents c As Class1Private Sub c_helloworld()
    MsgBox "helloworld"
    End SubPrivate Sub Form_Load()
    Set c = New Class1
    c.fun
    End Sub