Public Event helloworld()Private Sub Command1_Click()
RaiseEvent helloworld
End Sub还需要什么? 事件怎么定义让他干什么? 比如就print "hello world"
RaiseEvent helloworld
End Sub还需要什么? 事件怎么定义让他干什么? 比如就print "hello world"
解决方案 »
- 关于VB实现禁用 Server服务的问题
- VB配置文件调用问题--新手
- 取得当前Now()的前30分钟?
- 如题,我在2000,xp下打印都没问题,就是在98下打印出来的格式不对,有些汉字挤到一块了,数字都往后移了0.5cm左右,不知这是何原因?
- vb6 数据太多DataGrid怎么分页显示呀。
- 诚询MID安卓系统,合作方案将打印机和visa刷卡POS整合在一起,
- 软件终于有第一个人注册了,散点分!(内有小调查)
- 关于右键快捷菜单的问题?
- 烦死了~ 救救我的程序,为什么不行?
- *****有谁知道这首歌是谁唱的?******
- 求VB高手和软件测试员
- update或INSERT时报语法出错,可拷到access里能用,究竟是为什么啊?
Call printstr
End Sub
-------------------------------
Private Sub printstr()
Print "hi"
End Sub
然后在窗口中,才能体现这些事件。
Public Event helloworld()然后再一个标准工程中引用了这个控件
Private Sub Command1_Click()
RaiseEvent helloworld
End Sub什么也没有发生的啊
要如何才能让他发生些什么
Public Class ThisClass
' [variable, property, method and event declarations]
End Class一个类的源代码在哪里声明的?如何看到比如我有两个按钮 我发现可以这样调用一个事件
Private Sub Command1_Click()
RaiseEvent Command2.Drag
End Sub但是这个按钮的事件也太少了 竟然没有click
'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
下面的示例是在百米赛跑演示中使用事件来计时。代码说明了所有与事件相关的方法、属性和语句,包括 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
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