dcsimg
Results 1 to 16 of 16

Thread: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Resolved [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    hey,
    i am looking for a replacment of a timer to check some data every 10 seconds.
    i need this to be on my main form
    is there a way (without using the timer)
    to make an interval every 10 seconds?
    regards
    salsa

  2. #2
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,030

    Re: looking For replacment for timer and with interval of 10 seconds

    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  3. #3
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,269

    Re: looking For replacment for timer and with interval of 10 seconds

    Oh Salsa,

    Colin got you with that Link

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,471

    Re: looking For replacment for timer and with interval of 10 seconds

    Why without using a timer? This is the kind of thing a timer is for.

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Re: looking For replacment for timer and with interval of 10 seconds

    Quote Originally Posted by ChrisE View Post
    Oh Salsa,

    Colin got you with that Link

    regards
    Chris

    well i think i just used a timer

  6. #6

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    i ment i need a service to run in the backround and to check evey 10 or 15 seconds

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,471

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Quote Originally Posted by salsa31 View Post
    i ment i need a service to run in the backround and to check evey 10 or 15 seconds
    Well then you would need to create a service and that service would use a timer.

    Are you sure you need a service?
    What are you checking and what do you need to do when it checks a given way?

    Remember services have no user interface and run even when no one is logged into the system.

  8. #8
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    679

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    If you mean that it needs to check exactly each 10 seconds, a normal VB timer can't do it, because if the process is left in background (modern Windows = can be unattended, delayed, etc., gaining resources for focused app), and if the user is maintaining busy the computer with something else, the VB process can be DELAYED, I observer delays like 15 seconds or bigger, just browsing chrome, ONLY if the VB6 app is doing disk I/O, and it is a mechanical disk, permanent red light and so on.

    Now, if you want to AVERAGE 10 seconds, a simple timer is fine for you. 10 seconds is a great low frecuency clasical usage. It can skip some Ticks if the PC is so busy, because the TIMER event only triggers if the last TICK was DROPPED from messaging queue. That is the rule, and that avoids major issues.

    An alternative, to have it IN BACKGROUND and more reliable, is to set the process in HIGH PRIORITY... but it is not a miracle. And can eat resources over a video game , by example.

    another alternative is a hardware timer, that wil guarantee it exact ticking..... BUT!.... it will throttle up the PC like if a video game is running (spending more energy, easily 30, 40W more).
    Last edited by flyguille; Dec 8th, 2017 at 09:47 AM.

  9. #9
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,269

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Hi Salsa,

    here take your pick. Add the Controls to a Form.

    Code:
    Option Explicit
    
    Private NextAction As Date
    Private Interval As Long
    Private IntervalType As String
    
    Private Sub Command1_Click()
       
       Dim i As Long
       
          'next full hour
          i = Hour(Now)
          Interval = 1
          IntervalType = "h"
          NextAction = DateAdd(IntervalType, Interval, Date + CDate(i & ":00:00"))
          Timer1.Interval = 1000
          Timer1.Enabled = True
          
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
          Command4.Caption = "Stop"
    End Sub
    
    Private Sub Command2_Click()
    
       Dim i As Long
       
          'every 10sec.
          Interval = 10
          IntervalType = "s"
          NextAction = Now
          Timer1.Interval = 1000
          Timer1.Enabled = True
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
          Command4.Caption = "Stop"
    End Sub
    
    Private Sub Command3_Click()
    
       Dim i As Long
       
          'every 2min.
          Interval = 2
          IntervalType = "n"
          NextAction = Now
          Timer1.Interval = 1000
          Timer1.Enabled = True
          NextAction = DateAdd(IntervalType, Interval, Date + CDate(i & ":00:00"))
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
          Command4.Caption = "Stop"
    End Sub
    
    Private Sub Command4_Click()
    
          Timer1.Enabled = False
          Command4.Caption = "Stopped"
    End Sub
    
    Private Sub Form_Load()
    
          Command1.Caption = "every hour"
          Command2.Caption = "every 10sec."
          Command3.Caption = "every 2min."
          Command4.Caption = "Stopp"
    End Sub
    
    Private Sub Timer1_Timer()
    
       Dim s As String
       
          s = "Countdown " & Format(NextAction - Now, "hh:nn:ss")
          If NextAction > Now Then
             If Label1.Caption <> s Then
                Label1.Caption = s
             End If
             Exit Sub
          End If
          
          NextAction = DateAdd(IntervalType, Interval, Now)
          Timer1.Enabled = False
          'your action here
          
          List1.AddItem "Action " & Format(Now, "dd.mm.yy hh:nn:ss")
          Timer1.Enabled = True
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  10. #10

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Quote Originally Posted by DataMiser View Post
    Well then you would need to create a service and that service would use a timer.

    Are you sure you need a service?
    What are you checking and what do you need to do when it checks a given way?

    Remember services have no user interface and run even when no one is logged into the system.
    yes sir im sure.
    how do i create this?

  11. #11

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Quote Originally Posted by ChrisE View Post
    Hi Salsa,

    here take your pick. Add the Controls to a Form.

    Code:
    Option Explicit
    
    Private NextAction As Date
    Private Interval As Long
    Private IntervalType As String
    
    Private Sub Command1_Click()
       
       Dim i As Long
       
          'next full hour
          i = Hour(Now)
          Interval = 1
          IntervalType = "h"
          NextAction = DateAdd(IntervalType, Interval, Date + CDate(i & ":00:00"))
          Timer1.Interval = 1000
          Timer1.Enabled = True
          
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
          Command4.Caption = "Stop"
    End Sub
    
    Private Sub Command2_Click()
    
       Dim i As Long
       
          'every 10sec.
          Interval = 10
          IntervalType = "s"
          NextAction = Now
          Timer1.Interval = 1000
          Timer1.Enabled = True
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
          Command4.Caption = "Stop"
    End Sub
    
    Private Sub Command3_Click()
    
       Dim i As Long
       
          'every 2min.
          Interval = 2
          IntervalType = "n"
          NextAction = Now
          Timer1.Interval = 1000
          Timer1.Enabled = True
          NextAction = DateAdd(IntervalType, Interval, Date + CDate(i & ":00:00"))
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
          Command4.Caption = "Stop"
    End Sub
    
    Private Sub Command4_Click()
    
          Timer1.Enabled = False
          Command4.Caption = "Stopped"
    End Sub
    
    Private Sub Form_Load()
    
          Command1.Caption = "every hour"
          Command2.Caption = "every 10sec."
          Command3.Caption = "every 2min."
          Command4.Caption = "Stopp"
    End Sub
    
    Private Sub Timer1_Timer()
    
       Dim s As String
       
          s = "Countdown " & Format(NextAction - Now, "hh:nn:ss")
          If NextAction > Now Then
             If Label1.Caption <> s Then
                Label1.Caption = s
             End If
             Exit Sub
          End If
          
          NextAction = DateAdd(IntervalType, Interval, Now)
          Timer1.Enabled = False
          'your action here
          
          List1.AddItem "Action " & Format(Now, "dd.mm.yy hh:nn:ss")
          Timer1.Enabled = True
          Label2.Caption = Format(NextAction, "dd.mm.yyyy hh:nn:ss")
    End Sub
    regards
    Chris
    hey chris thats a great code
    but i dont want to user a timer
    and i need the code as a function

  12. #12
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,269

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Hi Salsa,

    I have to ask the same as DataMiser..
    What are you checking and what do you need to do when it checks a given way?
    I think you are making your Life more difficult as it need's to be.

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  13. #13

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    What are you checking and what do you need to do when it checks a given way?
    i need to check some data for the user online
    and insert it into the database

  14. #14
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,269

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    well I like to help, but I don't want to take
    part in a guessing game.

    what kind of Data, what/where in the www

    Look at the winsock control that has some Functions like ..ReciveData or Respond to incomming Data

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  15. #15

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,547

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Quote Originally Posted by ChrisE View Post
    well I like to help, but I don't want to take
    part in a guessing game.

    what kind of Data, what/where in the www

    Look at the winsock control that has some Functions like ..ReciveData or Respond to incomming Data

    regards
    Chris
    the data is not relevant right now
    what i need is the interval of the time

  16. #16
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,269

    Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds

    Hi salsa,

    still don't know why you reject using a Timer.

    here a diffrent way..

    place a Label and a Commandbutton on a Form

    Code:
    Option Explicit
    
    Private Waiting As Boolean
    
    '------------------------------------------------
    'wait x seconds
    '------------------------------------------------
    Private Sub WaitFor(Seconds As Single, Waiting As Boolean, _
                        Optional WithDoEvents As Boolean = True)
    
       Dim aTime As Single, dummy As Single
         
    
          aTime = Timer
          Waiting = True
          Do
             dummy = Timer
             dummy = dummy - aTime
              Label1.Caption = dummy
             'midnight
             If dummy < 0 Then
                dummy = dummy + 86400!
             End If
             If dummy >= Seconds Then
                Exit Do
             End If
             'DoEvents
             If WithDoEvents Then
                DoEvents
             End If
          Loop
          Waiting = False
    End Sub
    
    Private Sub Command1_Click()
          Command1.Enabled = False
          WaitFor 10, Waiting
          Command1.Enabled = True
    End Sub
    
    Private Sub Form_Activate()
    Command1.Value = True
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    
          If Waiting Then
             Cancel = -1
          End If
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width