VB6 application : WebBrowser.Navigate refresh every 3 minutes

回眸只為那壹抹淺笑 提交于 2020-01-16 04:59:25

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/15664916/vb6-application-webbrowser-navigate-refresh-every-3-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!