Looping refresher

decrypt

Junior Contributor
Joined
Oct 6, 2003
Messages
216
Hi, I'm 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]

What's wrong with it? It only refreshes once, and then it doesn't do anything.
 
Last edited:
Maybe I'm missing something here but it probably is looping the number of times you expect but it happens so fast that you don't see it.
I think that you need to move the Refresh into your Timer Event, so that it refreshes on each Interval.

Also, wouldn't 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 doesn't 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.

Visual Basic:
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.

Visual Basic:
Timer1.Enabled = True 'Start the timer

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

Visual Basic:
AxWebBrowser1.Refresh() 'Refresh the page

This causes the refresh, but it's 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:
Visual Basic:
Private m_iCounter as integer = 0 'Counter variable.

Sub #1
Visual Basic:
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
Visual Basic:
Private Sub Timer1_EVENTNAME() 
'Replace "EVENTNAME" with the real event trigger name which I can't 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