VB6 upgrade problem MSHTML COM with VB.NET [resolved]
I have this code from VB6 that works fine
VB Code:
Dim objLink As HTMLLinkElement
Dim objMSHTML As New MSHTML.HTMLDocument
Dim objDoc As MSHTML.HTMLDocument
Set objDoc = objMSHTML.createDocumentFromUrl("http://www.yahoo.com", vbNullString)
While objDoc.readyState <> "complete"
DoEvents
Wend
'get all Links
For Each objLink In objDoc.links
Debug.Print objLink
Next
I then run it through the VS.Net VB upgrade tool and get this
VB Code:
Dim objLink As mshtml.HTMLLinkElement
Dim objMSHTML As New mshtml.HTMLDocument
Dim objDoc As mshtml.HTMLDocument
objDoc = objMSHTML.createDocumentFromUrl("http://www.yahoo.com", vbNullString)
While objDoc.readyState <> "complete"
System.Windows.Forms.Application.DoEvents()
End While
'get all Links
For Each objLink In objDoc.links
System.Diagnostics.Debug.WriteLine(objLink)
Next objLink
I get an error on the line
VB Code:
objDoc = objMSHTML.createDocumentFromUrl("http://www.yahoo.com", vbNullString)
Saying "An unhandled exception of type 'System.NullReferenceException' occured in mscorlib.dll"
"Additional Information: Object reference not set to an instance of an object"