【发布时间】:2011-08-14 16:40:28
【问题描述】:
我想捕捉 NewCivicAddressReport 事件,这意味着我需要实现事件处理程序。谁能解释为什么嵌入在 html 页面中的 VBScript 代码有效,而 VBS 文件无效?
这里是可以在 CivicFactory_NewCivicAddressReport() 函数中处理 NewCivicAddressReport 事件的 html 页面。我想这是因为事件处理程序命名约定。如果我错了纠正我。
<!-- Civic address Location report factory object -->
<object id="CivicFactory"
classid="clsid:2A11F42C-3E81-4ad4-9CBE-45579D89671A"
type="application/x-oleobject">
</object>
<script language="vbscript">
Function CivicFactory_NewCivicAddressReport(report)
MsgBox "New civic address report!"
End Function
Sub OnLoadPage()
CivicFactory.ListenForReports(1000)
End Sub
Sub DisplayStatus(status)
MsgBox "status displayed"
End Sub
</script>
下面是不起作用的 VBS 文件 - 事件处理函数似乎永远不会被调用。
Dim CivicFactory
Set CivicFactory = WScript.CreateObject("LocationDisp.CivicAddressReportFactory")
Function CivicFactory_NewCivicAddressReport(report)
MsgBox "Location changed!"
keepSleeping=false
End Function
CivicFactory.ListenForReports(1000)
dim keepSleeping
keepSleeping=true
while keepSleeping
WScript.Sleep 200
wend
顺便问一下,谁能告诉我两种创建对象的方法:和WScript.CreateObject()的区别?
提前致谢!
【问题讨论】:
标签: events object com vbscript handler