|
-
Jul 20th, 2010, 08:38 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Object reference not set to an instance of an object.[Help]
Ok guys. Im trying to grab a HTML element style with my program, the problem is that when the page is loaded there is no style to that element, then if I click on that element and it has a style.
I have this
vb.net Code:
With WebBrowser1
If .Document.GetElementById("idSUOther9").Style is Nothing Then
.Document.GetElementById("i1668").InvokeMember("click")
End If
If .Document.GetElementById("idSUOther9").Style Is "display: none;" Then
.Document.GetElementById("i0116")
.Document.GetElementById("i0118")
End If
tLogin.Stop()
MessageBox.Show(.Document.GetElementById("idSUOther9").Style)
Return
then my program crashes here
vb.net Code:
If .Document.GetElementById("idSUOther9").Style is Nothing Then
.Document.GetElementById("i1668").InvokeMember("click")
End If
since idSUOther9 there is no style it cant grab its data. How can I check is "idSUOther9" has a style without crashing my program?
Thank you
Last edited by simon66; Jul 20th, 2010 at 01:01 PM.
-
Jul 20th, 2010, 08:46 AM
#2
Re: Object reference not set to an instance of an object.[Help]
I haven't played much with the WebBrowser control and HTML elements so I don't know the best practices with these but one way to solve your issue would be to handle the exception with a try/catch block. If the exception is caught then you know there is no style for "idSUOther9".
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jul 20th, 2010, 08:50 AM
#3
Re: Object reference not set to an instance of an object.[Help]
Does .Document.GetElementById("idSUOther9") return an object? If IT is producing Nothing, then the InvokeMember line will fail as well.
Basically, an "Object Reference not set to an instance of an object" is a pretty generic error. It's basically saying you're trying to do something to an object that doesn't exist; or use a method or function of an object that doesn't exist.
-
Jul 20th, 2010, 09:13 AM
#4
Thread Starter
Hyperactive Member
Re: Object reference not set to an instance of an object.[Help]
 Originally Posted by Jenner
Does .Document.GetElementById("idSUOther9") return an object? If IT is producing Nothing, then the InvokeMember line will fail as well.
Basically, an "Object Reference not set to an instance of an object" is a pretty generic error. It's basically saying you're trying to do something to an object that doesn't exist; or use a method or function of an object that doesn't exist.
Yes. It suppose to return a value. but it crashes since idSUOther9 has to style yet.
-
Jul 20th, 2010, 09:26 AM
#5
Re: Object reference not set to an instance of an object.[Help]
What line crashes?
"It suppose to return a value." -- does that mean you don't know for sure that it does? That should be the first thing you should be checking. Try debugging... when it crashes, check the values of your objects... make sure they are what you expect them to be.
-tg
-
Jul 20th, 2010, 09:48 AM
#6
Thread Starter
Hyperactive Member
Re: Object reference not set to an instance of an object.[Help]
 Originally Posted by techgnome
What line crashes?
"It suppose to return a value." -- does that mean you don't know for sure that it does? That should be the first thing you should be checking. Try debugging... when it crashes, check the values of your objects... make sure they are what you expect them to be.
-tg
It crashes here
vb.net Code:
If .Document.GetElementById("idSUOther9").Style is Nothing Then
because "idSUOther9" in this case doesn't have a style, so it cant grab its data.
-
Jul 20th, 2010, 10:09 AM
#7
Re: Object reference not set to an instance of an object.[Help]
so when you check: .Document.GetElementById("idSUOther9") .... you get "something"?
-tg
-
Jul 20th, 2010, 12:25 PM
#8
Re: Object reference not set to an instance of an object.[Help]
Yea, try:
Code:
If .Document.GetElementById("idSUOther9") IsNot Nothing AndAlso .Document.GetElementById("idSUOther9").Style is Nothing Then
...
-
Jul 20th, 2010, 01:01 PM
#9
Thread Starter
Hyperactive Member
Re: Object reference not set to an instance of an object.[Help]
 Originally Posted by Jenner
Yea, try:
Code:
If .Document.GetElementById("idSUOther9") IsNot Nothing AndAlso .Document.GetElementById("idSUOther9").Style is Nothing Then
...
It works!
Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|