none
HTMLDocument RRS feed

  • Question

  • Hello all,

    This probably isnt the right forum to post this in but I know a few of you out there use Visual Studios. I and trying to convert my vba code to use in my vb.net windows form. Maybe theres a better way of doing this, Im not sure. Im getting ERROR Object reference not set to an instance of an object.

            Dim URL As String = "http://www.footballlocks.com/nfl_odds.shtml"
            Dim XMLHttp As MSXML2.XMLHTTP
            Dim HTMLDoc As HTMLDocument
            Dim table As HTMLTable
            Dim tableRow As HTMLTableRow
            Dim tableCell As HTMLTableCell
    
            XMLHttp = New MSXML2.XMLHTTP
            XMLHttp.open("GET", URL, False)
            XMLHttp.send()
            HTMLDoc = New HTMLDocument
            'Console.Writeline(XMLHttp.responseText) ' It returns the XMLHttp.responseText
            HTMLDoc.body.innerText = XMLHttp.responseText ' ERROR on this line Object reference not set to an instance of an object.
            table = HTMLDoc.getElementsByTagName("TABLE")(39)
            For Each tableRow In table.rows
                For Each tableCell In tableRow.cells
                    Console.WriteLine(tableCell.innerText)
                Next
            Next



    • Edited by Mike7952 Tuesday, May 22, 2012 11:00 PM
    Tuesday, May 22, 2012 10:22 PM

Answers

  • replace HTMLDoc.body.innerText = XMLHttp.responseText with HTMLDoc.body.innerHTML = XMLHttp.responseText

    and it will/should work.

    Wednesday, May 23, 2012 2:37 PM

All replies

  • Do you have your references set properly?  I run this in XL VBA with a reference set to Microsoft XML v6 and the Microsoft HTML Object Library and it errors out for me on the 'table=' line [but I do get past the assignment of .responseText]

    I did have to reconvert the code to VBA a little by using SET statements etc.


    HTH,

    Eric

    Tu ne cede malis sed contra audentior ito

    Wednesday, May 23, 2012 2:07 PM
  • replace HTMLDoc.body.innerText = XMLHttp.responseText with HTMLDoc.body.innerHTML = XMLHttp.responseText

    and it will/should work.

    Wednesday, May 23, 2012 2:37 PM
  • Hi Mike7952,

    I’m glad to hear you have solved your issue. Thank you very much for sharing your solution here, and it’s very beneficial for other community members who have similar problem.

    Best Regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 28, 2012 1:50 AM
    Moderator