为什么没有触发事件

donghaima 2003-12-18 09:27:34
这是一个ACTIVEX EXE程序

'下面是一个类ZP
'事件
Public Event NewInformation(ByVal Information As String)

'获得网络适配器信息的方法
Public Function AdapterInfor(ByVal Reserve As String) As String
mvarLastError = ""
AdapterInfor = ""

Dim strBuff As String
Dim oClass As Object
Set oClass = CreateObject("QNCOWSC1.Communication")

strBuff = ""
If oClass.EnumAdapter(1, "") = True Then
Do
strBuff = strBuff & "网络适配器名称:" & oClass.AdapterName & vbCrLf
strBuff = strBuff & "网络适配器类型:" & oClass.AdapterType & vbCrLf
strBuff = strBuff & "网络适配器IP:" & oClass.AdapterIPAddress & vbCrLf
strBuff = strBuff & "网络适配器MAC:" & oClass.AdapterPhyAddress & vbCrLf
strBuff = strBuff & "网络适配器描述:" & oClass.AdapterDescription & vbCrLf & vbCrLf
'这里应该将枚举到的信息用事件触发的方式及时通知客户程序,
'但它好象没有工作
RaiseEvent NewInformation(strBuff)
Loop While oClass.EnumAdapter(0, "")
Else
mvarLastError = oClass.LastError
End If
AdapterInfor = strBuff
Set oClass = Nothing
End Function

'客户程序
Private WithEvents zpNewInformation As ZP

Private Sub Form_Load()
Set zpNewInformation = New ZP
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set zpNewInformation = Nothing
End Sub

Private Sub ZP_ADAPTERINFOR_Click()
Dim oClass As New ZP
If oClass.AdapterInfor("") = "" Then
Text1.Text = oClass.LastError
End If
Set oClass = Nothing
End Sub

Private Sub zpNewInformation_NewInformation(ByVal Information As String)
Text1.Text = Information
End Sub

'谁能告诉我错误在哪里,使用事件还需要别的设置吗.
...全文
53 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
donghaima 2003-12-18
  • 打赏
  • 举报
回复
JHZHOU9882问题解决了,谢谢你的启发,
不是把ZPNEWINFORMAITON改成OCLASS
而是反过来.谢谢
donghaima 2003-12-18
  • 打赏
  • 举报
回复
好像不行
jhzhou882 2003-12-18
  • 打赏
  • 举报
回复
Private Sub zpNewInformation_NewInformation(ByVal Information As String)
Text1.Text = Information
End Sub
是不是应该这么写
Private Sub oClass_NewInformation(ByVal Information As String)
Text1.Text = Information
End Sub

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧