vb.net - Exception 0x800A01B6 using getElementById after the first load -
i have created ribbon powerpoint visual studio xml ribbon. ribbon has button that, simplifying, this:
- opens ie browser
- search element (hiddenfield) in code id
- get value of element
- print value in actual slide
it works correctly first time click button of ribbon, throws exception 0x800a01b6 following times click button.
this code executed when click button:
dim otype type = type.gettypefromprogid("internetexplorer.application") if otype isnot nothing dim ie shdocvw.internetexplorer ie = nothing ie = trycast(activator.createinstance(otype), shdocvw.internetexplorer) if ie isnot nothing dim oempty object = [string].empty dim ourl object = targeturl ie.addressbar = false ie.menubar = false ie.toolbar = 0 ie.visible = true ie.height = 800 ie.width = 1100 ie.navigate(ourl, oempty, oempty, oempty, oempty) end if while (ie.busy or ie.readystate <> readystate.readystate_complete) sleep(1000) application.doevents() loop sleep(10000) ' 10 seconds testing purpose dim str string = string.empty dim hdnstring htmlinputelement = ie.document.getelementbyid("hdnstring") str = hdnstring.value dosomething(str) ie.quit() ie = nothing end if this code of website opens (targeturl), code remains identical in every load , hidden value changes:
<html> <body> <form name="form1" id="form1"> <input type="hidden" name="hdnstring" id="hdnstring" value="get string" /> </form> </body> </html> the second time (and following) execute function: ie opens, website loads, waits 10 seconds , error in line:
dim hdnstring htmlinputelement = ie.document.getelementbyid("hdnstring") with exception 0x800a01b6 message.
the strange thing if click viewsource in ie contextual menu while 10 seconds delay (the ones testing purpose), works perfect every time click button; if don't, exception 0x800a01b6 appers.
any idea of i'm doing wrong?
error details image:
the type of document property resolved @ run-time, it's object until then. why calling methods in results in so-called late binding - not yet know if getelementbyid method exists or not, has determined run-time.
you error because document not of ihtmldocument3 type, document type includes getelementbyid method.
what can try casting document ihtmldocument3 interface. since inherits ihtmldocument , ihtmldocument2 can cast between them if document 1 of earlier types.
directcast(ie.document, ihtmldocument3).getelementbyid("hdnstring") 
Comments
Post a Comment