Question timer tick problem

jamesvick

Active member
Joined
Jul 19, 2010
Messages
34
Programming Experience
1-3
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?
 
Are you sure the i variable is being set to 3, 4, 5? I don't see where you incrementing it.
 
if you look carefully in the middle code, i manually change the value of i whenever an action is performed. like when first form is filled i becomes 2 and then the page is reloaded. so when document completed is called again the if loop for i=2 is executed.
 
My oversight, was looking for i += 1, so you have debugged line for line to see what is happening?
I would guess you need to change timer.Start to timer.Enabled = true.
 
Last edited:
got it working, actually we need to add timer1.enabled=false after timer1.stop and then re-enable it before starting. The problem with timer is that on start-stop, it doesn't restart, so the interval causes problems. With above statement it restarts, so no problems. It is now working with 8 if loops. thanks...
 

Latest posts

Back
Top