0
votes

Sorry guys, I CTRL-A my original post.. of course.

It was just simply inquiring about a late binding error I was getting with Option Strict On, which was also creating really odd adverse effects during publishing the console app. Doing the below, thanks to very helpful answers solved my issues.

I would say after getting a better grasp on late and early binding, I can see why people shoot for early, there are a lot of really cool and helpful tools that come with it, and it also seems to really aid in avoiding those crash issues.

Dim ie As InternetExplorer Dim document As HTMLDocument Dim ele As HTMLInputElement ie = New InternetExplorer

    ie.Visible = True
    ie.Navigate("www.google.com")
    While ie.ReadyState <> 4
    End While

    document = CType(ie.Document, HTMLDocument)

    ele = CType(document.getElementById("lst-ib"), HTMLInputElement)

    ele.value = "test"

I hope this can help someone else, as it helped me. You can see we have used early binding in the example :)

1
What are you actually trying to do with the browser? It could be that the WebBrowser Control is what you need. - Andrew Morton
Added to what @Andrew Morton said, the webbrowser control is what you need, it has a Document property which is of type of HtmlDocument. Then that type has a method called GetElementByIdwhich returns an HtmlElement. Right now none of your code will work... Also, you`re using old vb6 leftovers, this is not vb... - Trevor
Hmm.. so the code seems to work fine, and has been. Multiple published console apps seem to work really well, up until today. So for example, what you see above currently takes an element's ID, then clicks it. Works fine in all the IE browser automations thus far, could you perhaps show an example of how you would do a similar task? :) - MZawg
Use Visual Studio's Object Browser (View Menu->Object Browser) to discover which interface defines the Document property. In the Object Browser, expand the the InternetExploreClass node and then expand the "Base Types" node. Click through the various interfaces until you find Document. It is defined on the IWebBrowser2 Interface. The getElementById Method is defined on IHTMLDocument3. - TnTinMn
@TnTinMn Now that is cool, had no idea how easy all that was to access :). So it seems to say that document is type object. My navigation was slightly different than you describe. IEClass - then I am able to see document with a little wrench next to it. However, I can tell this is going to be extremely helpful. Thank you! - MZawg

1 Answers

0
votes

Late-binding is basically accessing a member of an object that the compiler cannot confirm exists at compile time. The issue there, from what I can gather, is that the InternetExplorer.Document property is type Object and the Object type has no getElementById method. The object that that property refers to at run time may well have that method, but if the compiler cannot confirm that at compile time then that is late-binding.

What you need to do is cast InternetExplorer.Document as the actual type that it will be at run time so that the compiler knows at compile time that there is a getElementById method. Note that the object itself actually implements a number of different interfaces so you would need to cast as the interface that has the member you want to access.