Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi, I'm making a program that continueally refreshes the current website when you click a button. Here is the 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.

Edited by decrypt
  • Moderators
Posted

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)

Visit...Bassic Software
  • 2 weeks later...
Posted

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

Posted

I think you are confused on the use of the timer. You have the right idea, but your missing slightly.

 

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.

 

Timer1.Enabled = True 'Start the timer

 

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

 

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:

Private m_iCounter as integer = 0 'Counter variable.

 

Sub #1

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

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...