Hi, I need to get the following VB6 code to work in .NET:
'/////
Dim doc As MSHTML.HTMLDocument
...
doc.getElementsByName("username").Item(0).Value = sn
doc.getElementsByName("password").Item(0).Value = pass
doc.getElementsByName("savepwd").Item(0).Checked = "yes"
'\\\\\
I got as far as the Item(0) part using C# and Microsoft.mshtml:
//////////////////////
HTMLDocumentClass doc = browser.Document as HTMLDocumentClass
HTMLElementCollectionClass elem =
doc.getElementsByName("username") as HTMLElementCollectionClass
object item = elem.item(0, 0);
// according to the MS documentation, item is now an IDispatch, but that
// interface exists in System.Windows.Forms.UnsafeNativeMethods, which
// is an internal class in mscorlib - not available for us to use.
//////////////////////
I'm not sure how I should proceed. Could I write a wrapper in C++ that
could use the IDispatch interface described in mshtml.h? If so, I haven't
the sleightest idea how, and google can't find anyone else who's tried this
(and succeeded).
Any help is appreciated.
Chris
Charles Law - 18 Jun 2004 15:25 GMT
Hi Chris
What exactly is the problem? You say that you got as far as the Item(0)
part, but don't say what stopped you going further.
getElementsByName returns an IHtmlElementCollection. You can define
something like
<code>
Dim ihec As IHtmlElementCollection
ihec = DirectCast(doc.getElementsByName("username"), IHtmlElementCollection)
ihec.Item(...) etc
</code>
If username is an input element then you can add
<code>
Dim ihie As IHtmlInputElement
ihie = DirectCast(ihec.Item("username"), IHtmlInputElement)
x = ihie.Value
</code>
HTH
Charles
> Hi, I need to get the following VB6 code to work in .NET:
> '/////
[quoted text clipped - 24 lines]
>
> Chris
Nick Malik - 19 Jun 2004 04:49 GMT
It isn't clear what you are trying to do. This code looks like you are
trying to use MSHTML to get a web page.
Instead of using a COM component, us a native .NET class. (e.g. rewrite
it). If you tell me what you are trying to do, I may be able to help you
find the correct .NET class to use in place of this.
--- Nick
> Hi, I need to get the following VB6 code to work in .NET:
> '/////
[quoted text clipped - 24 lines]
>
> Chris