Wednesday, November 09, 2005

Help in VB!

Yes - I'm coding in VB!! I'm writing an MS Excel macro to automate some tasks here @ EVS and I've run into a strange problem. Please see if you can help me out!

In short: How do I return an object from a function and make sure that the returned object retains *all* the member variables? I think it's called a 'deep copy' - I may be wrong.

In Long: Read the inline comments...

Function A(ByVal x As String) As MSHTML.HTMLDocument
'creates an object of type MSHTML.HTMLDocument
'and does some stuff with it
'now the *entire* object needs to be returned back
Set A = tempObj
End Function

Sub B()
Dim obj As MSHTML.HTMLDocument
Set obj=A("xyz")

'Run-time error in the following statement cuz the object which obj refers to

'does not have all the member variables
'objects within the object are discarded, for example obj.body (an object of IHTMLElement) is 'Nothing'
'when in fact it should have lots of things!
Msgbox(obj.getElementById("link1"))
End Sub

No comments:

Post a Comment