Visual Basic如何检查变量是否在5分钟内更改?

时间:2015-12-24 15:56:54

标签: vb.net

  

这是一个例子:

    Dim Cchanges As Integer

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

    If 'some kind a solution here' Then
        MsgBox("there is no changes made in 5 minutes")
    End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Label1.Text = Cchanges
End Sub

并且将对任何其他解决方案进行评估。

1 个答案:

答案 0 :(得分:-1)

这应该可以满足您的需求:

Private timer As New Timer(TimerTick, Nothing, TimeSpan.Zero, New TimeSpan(0, 0, 0, 1))
Private lastMinute As Integer = 1

Private Sub TimerTick(state As Object)
    Dim minute = DateTime.Now.Minutes
    If minute <> lastMinute AndAlso minute Mod 5 = 0 Then

        Select Case (String.Compare(txtOldValue.text, txtNewValue.text)
            Case < 0
                MsgBox("Your old value is smaller than your new value or is null.")
            Case = 0
                MsgBox("The values are equal")
            Case > 0 
                MsgBox("Your new value is smaller than your old value or is null."
        End Select
        lastMinute = minute

    End If
End Sub