Community discussion

VB Timer Control

  • 3 years ago

    Hi All,
    Can somebody help me in this coding. I want to set a timer when I activate the Multiplexer channel and wait for 5 second, after the 5 second will start take the data and the timer will disable. Thanks.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 3 years ago

    Just create a timer object, dobleclick on the object and edit the method to read the multiplexer and disable the timer afterwards.
    in the object properties the timer must be disabled and the time must be in 5000 milisecs.


    In the subroutine where the multiplexer is activated, enable the timer with timer.enable=true.

  • 3 years ago

    thanks a lot........... i already sucess to get it.

  • 3 years ago

    sorry I face problem again in the timer. I write this code in the


    public sub Cyl()
    Do Until cyclePower = 2
        'Go to Sub Cycle Power
        Call CyclePowerRoutine
        'MsgBox ("GO To Sub Cycle Power")
        cyclePower = cyclePower + 1
    Loop
    end sub


    Public Sub CyclePowerRoutine()
       'Open GPR
       MsgBox ("Open")
       frmTenData.Timer1.Interval = 1000
       frmTenData.Timer1.Enabled = True
       intCnt = 1
    End Sub


    This 2 code are in the module, and i create the time object at form and write the code like: -
    Private Sub Timer1_Timer()
       If intCnt = 2 Then
           'Close GPR
           MsgBox ("Close")
           Timer1.Enabled = False
       Else
           intCnt = intCnt + 1
       End If
    End Sub


    My timer only activate when the cyclePower = 2 but I want the timer activate when I call the "CyclePowerRoutine" and disable when cyclepower = 2. What mistake I make? Can help in coding? Thanks.

  • 3 years ago

    "My timer only activate when the cyclePower = 2 but I want the timer activate when I call the "CyclePowerRoutine" and disable when cyclepower = 2. What mistake I make?"


    It's an easy one, you believe that "only activate when the cyclePower = 2" but the reality is that the loop continued from cyclePower =1 to 2, too fast, so you didn't saw the cyclePower=1, the processing is parallel so the other routines run "almost at the same time".



    In your case it's better to stop processing with a flag assigned at the right moment (and being the flag a global variable).


    public sub Cyl()
    Do Until cyclePower = 2
       'Go to Sub Cycle Power
      'Open GPR
       MsgBox ("Open")
       Timer1.Interval = 2000
       Timer1.Enabled = True


       do
         doevents
       loop until not(Timer1.Enabled)
       cyclePower = cyclePower + 1
    Loop
    end sub


    Private Sub Timer1_Timer()
          'Close GPR
          MsgBox ("Close")
          Timer1.Enabled = False
    End Sub


    So the is syncronized (but why you started with 5 seconds and now are 2?).

Post a reply

Enter your message below

Sign in or Join us (it's free).