Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

timer tick not working properly

jamesvickjamesvick Posts: 1Member
i was trying to make a free microsoft word plugin in vb.net. It automatically fills a web form. The main problem with the plugin is that it uses web browser control and once it has filled a form it will need to navigate another form. The form can only be filled once it has completely been loaded.

so my approach is
1. navigate to first site when form loads

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://google.com")
End Sub

2. use an integer i and use if statements to check which form to fill :

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If (i = 1) Then
WebBrowser1.Document.GetElementById("username").SetAttribute("value", "elvin")
WebBrowser1.Document.GetElementById("password").SetAttribute("value", "1111111")
WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
i = 2
ElseIf (i = 2) Then
WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
WebBrowser1.Document.GetElementById("content").SetAttribute("value", "111111")
WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fgddferre")
WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
i = 3
Timer1.Start()
ElseIf (i = 3) Then
Timer1.Stop()
WebBrowser1.Document.GetElementById("loginTextBlock_uname").SetAttribute("value", "elvin")
WebBrowser1.Document.GetElementById("loginTextBlock").SetAttribute("value", "11111")
WebBrowser1.Document.GetElementById("nowwhat").InvokeMember("click")
i = 4
ElseIf (i = 4) Then
WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
WebBrowser1.Document.GetElementById("content").SetAttribute("value", "11111")
WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fghfghfgh")
WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
i = 5
Timer1.Start()
ElseIf (i = 5) Then
WebBrowser1.Document.GetElementById("user").SetAttribute("value", "rfgjhfhj")
WebBrowser1.Document.GetElementById("pass").SetAttribute("value", "566788989")
WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
i = 6
End If
End Sub



3. this is the main step. you see when main form loads, i=1 so browser goes to google.com (first form), when form is completely loaded, itchecks for value of i. Since i=1, it fills google. After filling and continuing i=2 and browser goes to my personal account page. This means browser again loads the document. Now i=2, so it fills my personal detalis. Now the timer starts. Since i=3, browser navigates to second site and fills the details.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If (i = 3) Then
WebBrowser1.Navigate("http://blogger.com")
ElseIf (i = 5) Then
WebBrowser1.Navigate("http://www.yahoo.com/")
End If
End Sub

now the problem arises. The browser does not go to the third site. Once the timer has been stopped and started, the following code does not goto the elseif part (i.e. i=5) why is that so?

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Question: Why are you using a Timer instead of:

    [code]
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    If (i = 1) Then
    WebBrowser1.Document.GetElementById("username").SetAttribute("value", "elvin")
    WebBrowser1.Document.GetElementById("password").SetAttribute("value", "1111111")
    WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
    i = 2
    ElseIf (i = 2) Then
    WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
    WebBrowser1.Document.GetElementById("content").SetAttribute("value", "111111")
    WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fgddferre")
    WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
    i = 3
    WebBrowser1.Navigate("http://blogger.com")
    ElseIf (i = 3) Then
    Timer1.Stop()
    WebBrowser1.Document.GetElementById("loginTextBlock_uname").SetAttribute("value", "elvin")
    WebBrowser1.Document.GetElementById("loginTextBlock").SetAttribute("value", "11111")
    WebBrowser1.Document.GetElementById("nowwhat").InvokeMember("click")
    i = 4
    ElseIf (i = 4) Then
    WebBrowser1.Document.GetElementById("title").SetAttribute("value", "elvin")
    WebBrowser1.Document.GetElementById("content").SetAttribute("value", "11111")
    WebBrowser1.Document.GetElementById("tags").SetAttribute("value", "fghfghfgh")
    WebBrowser1.Document.GetElementById("publish").InvokeMember("click")
    i = 5
    WebBrowser1.Navigate("http://www.yahoo.com/")
    ElseIf (i = 5) Then
    WebBrowser1.Document.GetElementById("user").SetAttribute("value", "rfgjhfhj")
    WebBrowser1.Document.GetElementById("pass").SetAttribute("value", "566788989")
    WebBrowser1.Document.GetElementById("wpt").InvokeMember("click")
    i = 6
    End If
    End Sub
    [/code]

    My guess is that this has something to do with the Interval of the timer? In the amount of time it takes to load yahoo.com and have it complete the Timer ticks again and calls "WebBrowser1.Navigate" again, and runs in a continuous loop (basically never letting it finish loading).

    Whats your Timer1.Interval set to
    Is Timer1.Enabled EqualTo True after you call .Stop() ? (I don't know what .Start() and .Stop() do on timers to be honest).
    Did you throw a breakline inside of the Timer Tick event to see if that event was firing at all?
    If TimerTick is getting called, what exactly is i set to when it's being called?

    I avoid Timers like I avoid the plague... I really don't see a purpose for using one here, but I might be missing part of the big picture.

    -Sean C - Forum Mod
Sign In or Register to comment.