none
VB2008如何统计Timer触发的次数? RRS feed

  • 问题

  • 我的写法一:
    Public i As Integer
    Public strCount As Integer '用户指定的触发次数【strCount = Trim(TextBox4.Text)】
    ...
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            i = 0
            i = i + 1
            If i = CInt(strCount) Then
                Timer1.Enabled = False
                Timer1.Dispose()           
                Exit Sub
            End If
            Label7.Text = "已触发" & i & "次"
        End Sub

    写法二:
    Public i As Integer
    Public strCount As Integer '用户指定的触发次数【strCount = Trim(TextBox4.Text)】
    ...
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            For i = 0 To CInt(strCount)
                Label7.Text = "已触发" & i & "次"
            Next

    End Sub

    这样的两种写法都没用,应该怎么修改?请指教!

    2013年9月8日 6:39

答案

  • Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
           Static i As Integer = 0
            i = i + 1
    
            If i >= CInt(strCount) Then
                Timer1.Enabled = False
                Timer1.Dispose()            
                Exit Sub
            End If
            Label7.Text = "已触发" & i & "次"
        End Sub

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月8日 6:52
    版主
  • 根据您的提示,问题已解决,非常感谢!代码如下:

    Public i As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            Dim a As String, b() As Byte

            a = Nothing

            b = Nothing

            WebBrowser1.Navigate(strUrl, a, b, "REFERER:" & strUrlFrom)

            i = i + 1

            Me.Label7.Text = "本次已刷" & i & "次" 

        End Sub

    2013年9月8日 9:47

全部回复

  • Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
           Static i As Integer = 0
            i = i + 1
    
            If i >= CInt(strCount) Then
                Timer1.Enabled = False
                Timer1.Dispose()            
                Exit Sub
            End If
            Label7.Text = "已触发" & i & "次"
        End Sub

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月8日 6:52
    版主
  • 根据您的提示,问题已解决,非常感谢!代码如下:

    Public i As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            Dim a As String, b() As Byte

            a = Nothing

            b = Nothing

            WebBrowser1.Navigate(strUrl, a, b, "REFERER:" & strUrlFrom)

            i = i + 1

            Me.Label7.Text = "本次已刷" & i & "次" 

        End Sub

    2013年9月8日 9:47
  • 方便的话,顺便一起测试我的代码,然后标记你认为对的答案,谢谢。

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月8日 9:48
    版主