SolvedLoop Only Runs In MessageBox

Posts 1–5 of 5 · Page 1 of 1
Loop Only Runs In MessageBox
Guys, I have the most retarded problem ever...the thing is, I have this loop, and it runs just fine(except for the boringness) if I use Msgbox("whatever") after some of its lines, but it won't run otherwise...I guess it has to do with the time my local server takes to awnser, but I tried System.Threading.Thread.Sleep() up to 10000 and nothing worked...even tough it did on msgbox's which I went trough faster than those.


Also, how can I clean Webbrowser1 cookie's?


Here is the code, if you guys can help.
Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim FILE_NAME As String = "C:\Users\Myname\Desktop\list.txt"
        Dim TextLine As String
        Me.Visible = True
        Dim ia As Integer
        ia = 0
        Dim lol As String

        If System****.File.Exists(FILE_NAME) = True Then

            Dim objReader As New System****.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1

                WebBrowser1.Navigate("http://localhost/bf/login.php")
                MsgBox("as")
                WebBrowser1.Document.GetElementById("user").SetAttribute("value", "bacon")
                ia += 1
                TextLine = objReader.ReadLine() & vbNewLine
                TextBox1.Text = TextLine
                WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox1.Text)
                MsgBox("as")
                WebBrowser1.Document.GetElementById("subm").Focus()
                MsgBox("as")
                WebBrowser1.Document.GetElementById("subm").InvokeMember("click")
                MsgBox("as")
                lol = WebBrowser1.Url.ToString
                If lol = "http://localhost/bf/done.php" Then
                    MsgBox("Done at try number " & ia & " Password is: " & TextBox1.Text)
                    Exit Do
                Else
                End If
            Loop

        Else

            MsgBox("File Does Not Exist")

        End If


    End Sub
End Class
Thanks in advance.
I am stuck in the program because of this...therefore I am bumping.

I also apology for bumping.
That's not the way to handle a WebBrowser.
The reason it's not working is because the WebBrowser hasn't actually finished loading the page before you start trying to manipulate the DOM elements on the page.

Easiest way is just to use HttpWebRequests to send and manipulate the data in this instance.
I just solved it, I understood the problem after someone explained me somtheing along the lines of what you said and tackled it this way, in case you are curious...


Code:
Public Class Form1
    Dim FILE_NAME As String = "C:\Users\Manel\Desktop\list.txt"
    Dim TextLine As String
    Dim lol As String
    Dim ia As Integer
    Dim objReader As New System****.StreamReader(FILE_NAME)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://localhost/bf/login.php")



    End Sub


    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If System****.File.Exists(FILE_NAME) = True Then
            If objReader.Peek() <> -1 Then
                WebBrowser1.Document.GetElementById("user").SetAttribute("value", "bacon")
                ia += 1
                TextLine = objReader.ReadLine() & vbNewLine
                TextBox1.Text = TextLine
                WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox1.Text)
                WebBrowser1.Document.GetElementById("subm").Focus()
                WebBrowser1.Document.GetElementById("subm").InvokeMember("click")
                lol = WebBrowser1.Url.ToString
                If lol = "http://localhost/bf/done.php" Then
                    MsgBox("Done at try number " & ia & " Password is: " & TextBox1.Text)
                    Exit Sub
                Else
                End If
            End If
            Timer1.Enabled = False
            WebBrowser1.Navigate("http://localhost/bf/login.php")
        Else
            MsgBox("File does not exist!")
        End If
    End Sub
End Class
Thank you.Thread can now be closed/deleted at will.
Marked Solved. No more posting.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us