Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all
I hava a piece vb code
When I convert it to C# the converted code gives a error.
Can anybody help me?

vb code (this code works)
VB.NET
Do Until vreadyState = 4
            Application.DoEvents()
            vreadyState = Me.WebBrowser1.ReadyState
        Loop
        Dim eleminput As HtmlElementCollection
        Dim DocCol As HtmlDocument
        DocCol = WebBrowser1.Document
        eleminput = DocCol.GetElementsByTagName("input")

c# code
c#.net
for (; (vreadystate == 4); )
            {
                Application.DoEvents();
                vreadystate = Convert.ToInt32(this.webBrowser1.ReadyState);

            }
            HtmlElementCollection eleminput = default(HtmlElementCollection);
            HtmlDocument DocCol = default(HtmlDocument);
            DocCol = webBrowser1.Document;
            eleminput =DocCol.GetElementsByTagName("input");


When I run this code my program has a error in the last line
"Object reference not set to an instance of an object."

How to change this code to solve this error?
Posted
Updated 17-Apr-11 23:24pm
v2

I used this tool : http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]

C#
while (!(vreadyState == 4)) {
    Application.DoEvents();
    vreadyState = this.WebBrowser1.ReadyState;
}

HtmlElementCollection eleminput = default(HtmlElementCollection);
HtmlDocument DocCol = default(HtmlDocument);
DocCol = WebBrowser1.Document;
eleminput = DocCol.GetElementsByTagName("input");


Is this working for you?
 
Share this answer
 
webBrowser1??!

Make it WebBrowser1.
Or, let us know where exactly you get this error.
 
Share this answer
 
v2
Comments
BobJanova 18-Apr-11 7:24am    
Good catch.
Change this
HtmlElementCollection eleminput = default(HtmlElementCollection);
HtmlDocument DocCol = default(HtmlDocument);

to
HtmlElementCollection eleminput;
HtmlDocument DocCol;
 
Share this answer
 
v3
Comments
ely z 18-Apr-11 5:32am    
i change it
but i have error in my program

The type 'System.Windows.Forms.HtmlElementCollection' has no constructors defined
Toniyo Jackson 18-Apr-11 5:36am    
Check the answer now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900