绑定到使用CreateObject创建的已打开表单

时间:2012-06-17 08:31:51

标签: c# .net com vbscript createobject

我想知道我想做什么是可能的。我创建了一个C#类库,它在使用CreateObject从VBScript调用时调用表单。

我有一个VBS将一些数据传递给Form,一旦脚本完成,很明显所有引用都会丢失。我想知道下次再次调用VBS脚本时是否有办法连接和使用现有表单?

Set e = CreateObject("MyObject")
'SendEvents to Form'
'Script ends.. all references lost'

'Script is run again'
Set e = CreateObject("MyObject")
'Is it possible to send events to the existing form, instead of closing it and creating new one?'

*编辑:目前,我正在使用我的类lib在再次调用脚本时关闭现有表单。但是,无论脚本被调用多少次,我都有一个用户请求保持打开状态。我不确定如何在下次调用CreateObject时使用现有表单。有可能吗?

1 个答案:

答案 0 :(得分:3)

尝试这样

Set e = CreateObject("MyObject")
'SendEvents to Form'
'Script ends.. all references lost'

'Script is run again'
Set e = GetObject(, "MyObject") 'no, the empty parameter is no typo

有关详细信息,请参阅http://technet.microsoft.com/en-us/library/ee176980.aspx