Events VBScript中的COM事件处理程序

Events VBScript中的COM事件处理程序,events,object,com,vbscript,handler,Events,Object,Com,Vbscript,Handler,我想捕获NewCivicAddressReport事件,这意味着我需要实现事件处理程序。有人能解释为什么html页面中嵌入的VBScript代码可以工作,而VBS文件不能工作吗 这是一个html页面,在该页面中,可以使用CivicFactory_NewCivicAddressReport()函数处理NewCivicAddressReport事件。我想这是因为事件处理程序的命名约定。如果我错了,请纠正我。 顺便问一下,有人能告诉我创建对象的两种方法:WScript.CreateObject()和

我想捕获NewCivicAddressReport事件,这意味着我需要实现事件处理程序。有人能解释为什么html页面中嵌入的VBScript代码可以工作,而VBS文件不能工作吗

这是一个html页面,在该页面中,可以使用CivicFactory_NewCivicAddressReport()函数处理NewCivicAddressReport事件。我想这是因为事件处理程序的命名约定。如果我错了,请纠正我。

顺便问一下,有人能告诉我创建对象的两种方法:WScript.CreateObject()和WScript.CreateObject()之间的区别吗

提前谢谢

的第二个参数是事件处理函数中使用的前缀。要使其工作,请将对CreateObject的调用更改为以下内容

Set CivicFactory = _
    WScript.CreateObject("LocationDisp.CivicAddressReportFactory", _
        "CivicFactory_")
WScript.CreateObject和CreateObject之间的区别在于WScript.CreateObject支持事件

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
Set CivicFactory = _
    WScript.CreateObject("LocationDisp.CivicAddressReportFactory", _
        "CivicFactory_")