Continuous Check

quddusaliquddus

Active member
Joined
Nov 20, 2007
Messages
25
Programming Experience
Beginner
Hi all :),
I wanted to know how I can continuously check for condition (to see when it is satisfied) and then execute a statement when the condition is true.

More specifically I wanted to continuously check the time to see how much time has elapsed and then execute a statement based on how much time had lapsed.

Could someone please explain how i can do both these things - im new to VB.Net.

Any help is much appreciated. Thanks :D

Regards
Q
 
Last edited:
try this

VB.NET:
Dim timeCounter As New Stopwatch
Dim notified As Boolean = False

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     If notified = False Then
         If timeCounter.Elapsed.TotalSeconds > 5 And timeCounter.Elapsed.TotalSeconds < 6 Then
             notified = True
             MsgBox("5 seconds")
         End If
     End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.interval = 250     
    timeCounter.Start()
End Sub
 
Hi all,
I adapted the code and came up with the following:

VB.NET:
Public Class Form1
    Dim timeCounter As New Stopwatch
    Dim notified As Boolean = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 250
        timeCounter.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If notified = False Then
            If timeCounter.Elapsed.TotalSeconds > 5 And timeCounter.Elapsed.TotalSeconds < 6 Then
                notified = True
                MsgBox("5 seconds")
            End If
        End If
    End Sub
End Class

But nothing seems to happen! Can someone help please?

Q
 
Problem with VB.Net 2008 Express not found in VB.Net 2005 Express

Hi all :),

I ran the following code in VB.Net Express 2005 edition and it ran without a problem.

VB.NET:
Public Class Form1
    Dim timeCounter As New Stopwatch
    Dim Notified As Boolean = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ShockPet.Stop()
        Timer1.Interval = 250
        timeCounter.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MsgBox("Hello")
        If Notified = False Then
            If timeCounter.Elapsed.TotalSeconds > 5 And timeCounter.Elapsed.TotalSeconds < 6 Then
                Notified = True
                ShockPet.GotoFrame(2)
            End If
        End If
    End Sub
End Class

But now that Im trying it in VB.Net 2008 the following statements dont seem to execute:

VB.NET:
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MsgBox("Hello")
        If Notified = False Then
            If timeCounter.Elapsed.TotalSeconds > 5 And timeCounter.Elapsed.TotalSeconds < 6 Then
                Notified = True
                ShockPet.GotoFrame(2)
            End If
        End If
    End Sub

What am i doing wrong? Thanks for the help :D
 
Back
Top