1

I am making an application using VB6 in which a WebBrowser window is launched using this code:

     Private Sub Form_Load()
     WebBrowser1.Navigate ("http://google.com")
     End Sub

How can I make the window refresh the same url every let's say 3 minutes ? I know it should be something well known but i am still searching my way through VB programming

Deanna
  • 23,876
  • 7
  • 71
  • 156
Nizar Bark
  • 17
  • 7
  • You shouldn't have brackets around the URL unless you're using `Call` or using the return value of `.Navigate`. – Deanna Apr 01 '13 at 14:41

2 Answers2

3

You don't need 2 timers. just have a global variable globalTimer As Date that keeps the last time you navigated You can set Timer1 to run every second or minute. To be more accurate, I recommend every second.

Dim globalTimer As Date
...
Private Sub Timer1_Timer()
    If Now >= DateAdd("n", 3, globalTimer) Then    ' its been at least 3 minutes since last Navigation
        WebBrowser1.Navigate ("http://google.com") ' Navigate
        globalTimer = Now                          ' store the new navigation time
    End If
End Sub
George
  • 2,165
  • 2
  • 22
  • 34
  • I've tried the code, it refreshes the browser every 3 seconds, but it does not open the website google as it used to be with the previous code, any help please ! – Nizar Bark Mar 27 '13 at 20:06
  • WOOOPS! Big time mistake on my part... `If globalTimer >= DateAdd("n", 3, Now) Then` should be `If Now >= DateAdd("n", 3, globalTimer) Then` – George Mar 27 '13 at 21:48
1

You can use a timer to run code at a regular interval. As the VB6 timer has a maximum interval of ~65s, you can set it to a 60,000ms interval, and keep a separate counter and when it gets to 3, reset it back to 0 and perform a refresh.

Private Sub Timer_Timer
  'Increment minute count
  FireCount = FireCount + 1

  If FireCount = 3 then
    'Reset to 0 for next time
    FireCount = 0

    'Refresh web browser
  End If
End Sub
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • can you please tell where i can find resources / tutorials on how to make this since i am null at VB6 – Nizar Bark Mar 27 '13 at 17:12
  • @NizarBark It's a simple timer, an increment and if statement, there is nothing to tutor. – Deanna Mar 28 '13 at 09:18
  • I have put the following code `code`Private Sub Form_Load() WebBrowser1.Navigate ("http://www.google.com") End Sub Private Sub T_Timer() 'Increment minute count FireCount = FireCount + 1 If FireCount = 3 Then 'Reset to 0 for next time FireCount = 0 WebBrowser1.Refresh ("http://www.google.com") 'Refresh web browser End If End Sub`code` but it give me an alert saying compile error : wrong number or argument or invalid property assignment – Nizar Bark Mar 31 '13 at 18:37
  • @NizarBark Well, where did you get the `WebBrowser1.Refresh ("google.com")` line from? that's not the code you had in your question. As the compiler error said, `.Refresh` doesn't have that many parameters. – Deanna Apr 01 '13 at 14:43