-
Dec 7th, 2017, 12:54 PM
#1
Thread Starter
Enjoy the moment
[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
-
Dec 7th, 2017, 01:21 PM
#2
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
-
Dec 7th, 2017, 01:40 PM
#3
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.
-
Dec 7th, 2017, 04:23 PM
#4
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.
-
Dec 7th, 2017, 06:59 PM
#5
Thread Starter
Enjoy the moment
Re: looking For replacment for timer and with interval of 10 seconds
Originally Posted by ChrisE
Oh Salsa,
Colin got you with that Link
regards
Chris
well i think i just used a timer
-
Dec 8th, 2017, 06:33 AM
#6
Thread Starter
Enjoy the moment
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
-
Dec 8th, 2017, 08:01 AM
#7
Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds
Originally Posted by salsa31
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.
-
Dec 8th, 2017, 09:44 AM
#8
Fanatic Member
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.
-
Dec 9th, 2017, 08:37 AM
#9
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.
-
Dec 10th, 2017, 12:31 AM
#10
Thread Starter
Enjoy the moment
Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds
Originally Posted by DataMiser
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?
-
Dec 10th, 2017, 12:33 AM
#11
Thread Starter
Enjoy the moment
Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds
Originally Posted by ChrisE
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
-
Dec 10th, 2017, 05:18 AM
#12
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.
-
Dec 10th, 2017, 05:24 AM
#13
Thread Starter
Enjoy the moment
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
-
Dec 10th, 2017, 05:40 AM
#14
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.
-
Dec 10th, 2017, 09:35 AM
#15
Thread Starter
Enjoy the moment
Re: [RESOLVED] looking For replacment for timer and with interval of 10 seconds
Originally Posted by ChrisE
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
-
Dec 11th, 2017, 01:27 PM
#16
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|