-
Sep 17th, 2014, 07:30 AM
#1
Thread Starter
Banned
Error in code need help please
Hi everyone, I wondered if it would be possible to help me out with an error I'm having. Ive only been learning Visual Basic a cpl of months and don't know where to start when I receive errors like this. I've included a screenshot and will include the code . It may not be very good as I'm still trying to get my head round it all. If someone could have a look please and explain to me where I have gone wrong that would be very appreciated.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call navigatesite()
End Sub
Private Sub navigatesite()
Try
WebBrowser1.Navigate("http://afreesms.com/freesms/", False)
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Call getcaptcha()
Catch ex As Exception
MsgBox(ex.StackTrace)
End Try
End Sub
Private Sub getcaptcha()
Dim doc As mshtml.IHTMLDocument2 = WebBrowser1.Document.DomDocument
Dim imgRange As mshtml.IHTMLControlRange = CType(doc.body, mshtml.HTMLBody).createControlRange
For Each img As mshtml.IHTMLImgElement In doc.images
If img.GetAttribute("src").ToString.Contains("http://afreesms.com/image.php") Then
imgRange.add(img)
imgRange.execCommand("copy", False, Nothing)
PictureBox1.Image = Clipboard.GetDataObject.GetData(DataFormats.Bitmap)
Exit For
End If
Next
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
WebBrowser1.Document.GetElementById("imgcode").SetAttribute("value", TextBox1.Text)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
WebBrowser1.Document.GetElementById("countrycode").SetAttribute("value", "GB")
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
WebBrowser1.Document.GetElementById("smsto").SetAttribute("value", TextBox3.Text)
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
WebBrowser1.Document.GetElementById("message").SetAttribute("value", TextBox4.Text)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
Larger Image
Code:
http://s9.postimg.org/xrdwsrcq7/ERROR.png
After Browsing the forum I appear to have posted in the wrong section apologies for that.
Last edited by Warlock72; Sep 17th, 2014 at 08:16 AM.
-
Sep 24th, 2014, 05:27 AM
#2
Re: Error in code need help please
No problem. I'm moving your post to the .Net forum which should be the best fit. If you accidentally post in the wrong forum again just click the report button at the bottom of the post (the triangle with the exclamation mark) and we'll move it for you.
Welcome to the forum.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Sep 26th, 2014, 03:13 AM
#3
Thread Starter
Banned
Re: Error in code need help please
Thanks FunkyDexter. Sorry about that
-
Sep 26th, 2014, 03:50 AM
#4
Re: Error in code need help please
When you get an error message saying that an error occurred creating the form, it pretty much always means that one of the property values that you set in the designer has caused an event to be raised and you have written that event handler assuming that some state exists that doesn't when the form is being created. For instance, if you set the Text of a TextBox in the designer then the TextChanged event of that TextBox will be raised during creation of the form. If you have handled the TextChanged event and, for instance, assumed that the user has made a selection in a ComboBox that they haven't even seen yet, an exception will be thrown.
So, that error dialogue has a link on it that says View Detail for a reason. You can click that and view the details of the exception. It will tell you exactly where it occurred and you can then go to that location in the code and determine what you've done wrong. If you still aren't sure, put a breakpoint on the first line of the event handler (F9) and then step through the code line by line (F10) when it breaks. You can then see the values of all variables during execution and see what is not what you expect it to be. Once you know the cause, then you can modify the code to ensure the exception is not thrown, e.g. check for Nothing first.
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
|