Pergunta

I was wondering if what I am trying to do is possible. I have created a C# class library which invokes a form when called from VBScript using CreateObject.

I have a VBS that passes some data to the Form and once the script is complete, obviously all references are lost. I wanted to know if there is a way for me to connect and use the existing form the next time I call the VBS script again?

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?'

*Edit: Currently, I am using my class lib to close the existing form when the script is called again. However, I have a user request to keep it open regardless of how many times the script is called. I am not sure how I can use the existing form for the next time CreateObject is called. Is it possible?

Foi útil?

Solução

Try it like this

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

See http://technet.microsoft.com/en-us/library/ee176980.aspx for more info.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top