Some Help with the If Statement

TastyTeo

Member
Joined
May 31, 2011
Messages
15
Programming Experience
1-3
Hello this is my code
VB.NET:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If WebBrowser1.Document.Url.AbsoluteUri.ToString.EndsWith("profile") Then MsgBox("it looks you are already logged in, starting bot...") and Timer2.Enabled = True
        WebBrowser1.Document.GetElementById("user").SetAttribute("value", TextBox2.Text)
        WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox3.Text)
        WebBrowser1.Document.Forms(0).InvokeMember("submit")

    End Sub

The problem is that, when it checks that the AbsoluteUri ends with profile it should skip the other 3 commands and make another command (To enable the timer2 at the same time) Is this possible to make this? if yes how?
 
Alright, it works, thank you very much,

This is how it looks like now (Correct me if i am wrong, i think i am not)
VB.NET:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If WebBrowser1.Document.Url.AbsoluteUri.ToString.EndsWith("profile") Then
            MsgBox("it looks you are already logged in, starting bot...")
        ElseIf WebBrowser1.Document.Url.AbsoluteUri.ToString.EndsWith("profile") Then
            Timer2.Enabled = True
        Else
            WebBrowser1.Document.GetElementById("user").SetAttribute("value", TextBox2.Text)
            WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox3.Text)
            WebBrowser1.Document.Forms(0).InvokeMember("submit")
        End If

    End Sub
 
Your first two conditions are the same, so you only need If-Else, ie no ElseIf. The ElseIf would never be hit in that code, at most one branch of an If statement is ever executed.
 
Your first two conditions are the same, so you only need If-Else, ie no ElseIf. The ElseIf would never be hit in that code, at most one branch of an If statement is ever executed.

This seems to work perfectly
VB.NET:
        If WebBrowser1.Document.Url.AbsoluteUri.ToString.EndsWith("profile") Then
            MsgBox("it looks you are already logged in, starting bot...")
            Timer1.Enabled = True
        Else
            WebBrowser1.Document.GetElementById("user").SetAttribute("value", TextBox2.Text)
            WebBrowser1.Document.GetElementById("pass").SetAttribute("value", TextBox3.Text)
            WebBrowser1.Document.Forms(0).InvokeMember("submit")
        End If
 
Back
Top