Looping refresher

decrypt

Well-known member
Joined
Oct 6, 2003
Messages
216
Hi, Im making a program that continueally refreshes the current website when you click a button. Here is the code:
Code:
  [COLOR=blue]Private Sub[/COLOR] Button2_Click([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] System.Object, [COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.EventArgs) [COLOR=blue]Handles[/COLOR] Button2.Click
        [COLOR=blue]Dim[/COLOR] i [COLOR=blue]As Integer[/COLOR]
        [COLOR=blue]For[/COLOR] i = 1 [COLOR=blue]To[/COLOR] TextBox2.Text [COLOR=green]Loop[/COLOR]
            AxWebBrowser1.Refresh() [COLOR=green]Refresh the page[/COLOR] 
            Timer1.Interval = TextBox3.Text [COLOR=green]Time inbetween refreshing (time for page to load)[/COLOR]            
            Timer1.Enabled = [COLOR=blue]True[/COLOR] [COLOR=green]Start the timer[/COLOR] 
        [COLOR=blue]Next[/COLOR]
    [COLOR=blue]End Sub[/COLOR]

Whats wrong with it? It only refreshes once, and then it doesnt do anything.
 
Last edited by a moderator:
Maybe Im missing something here but it probably is looping the number of times you expect but it happens so fast that you dont see it.
I think that you need to move the Refresh into your Timer Event, so that it refreshes on each Interval.

Also, wouldnt Net.WebClient() do what you need (instead of the ActiveX)
 
Timer1.Interval = TextBox3.Text Time inbetween refreshing (time for page to load)

As you see there textbox3.text sets the time inbetween refreshing. (I normally do around 2000 milliseconds and it still doesnt refresh)

How do you set it in the timer event?

And Also how do you use the Net.WebClient() :P
 
I think you are confused on the use of the timer. You have the right idea, but your missing slightly.

Code:
Timer1.Interval = TextBox3.Text Time inbetween refreshing (time for page to load)

In the code above you have set the timer to raise an event at the specified interval once it is enabled. So far so good.

Code:
Timer1.Enabled = True Start the timer

Now you have enbled the timer to raise its event at each interval. Still doing good.

Code:
AxWebBrowser1.Refresh() Refresh the page

This causes the refresh, but its in the wrong place. You need to have it in a seperate sub that is triggered by the Timer1 event.

For example:

In the declarations section:
Code:
Private m_iCounter as integer = 0 Counter variable.

Sub #1
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Set timer properties and start running.
        Timer1.Interval = TextBox3.Text Time inbetween refreshing (time for page to load)            
        Timer1.Enabled = True Start the timer 
End Sub

Sub #2
Code:
Private Sub Timer1_EVENTNAME() 
Replace "EVENTNAME" with the real event trigger name which I cant remember.
runs this code whenever timer fires
     If m_intCounter <= CInt(Textbox2.Text) Then If counter less than textbox...
          AxWebBrowser1.Refresh() ...Refresh the page...
          m_intCounter + 1 ...and add to counter...
     Else
          Timer1.enabled = False ...Otherwise, Stop timer...
          m_intCounter = 0 ...and reset counter.
     End If
End Sub

This is just example code and is untested. Hope this helps. Good luck.
 
Back
Top