Discussion Locked

VB timed execution

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am extremely new to VB programming(a 5 day class and a handfull of books) and I have been give the task of writing a VB program that will execute another program at a specific time of day. How do you test/check current time against a pre-detdermined value and then launch an outside program??
any help/hints/tip would be much appreciated.
Thank You.

5 replies

by fgarber

I have a scheduler program I wrote. When I get to work I will email you the source code.

by richardh

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' called with
' Sleep 10000

' GetTickCount starts at 0 when windows starts up
Declare Function GetTickCount Lib "user32" () As Long
' it is about 80+ % faster than TIMERcalls if speed is of the essence
' usage:
' Dim lTimer1 as Long
' lTimer1 = GetTickCount()

' a handy "turn timer into human readable clock"
Dim strTempString As String
strTempString = sfunGetTime(Timer)

Public Function sfunGetTime(ByVal sglTime As Single) As String
' takes time (sglTime) and converts it to "user friendly"
' display of hours:minutes:seconds.milliseconds
' as hh:mm:ss.lll
'global the vars to speed the function sfunGetTime
'Global sglX As Single
'Global sglY As Single
'Global sglZ As Single
'Global sglV As Single
'Global strHrs As String
'Global strMin As String
'Global strSec As String
'Global strMSec As String

On Error GoTo sfunGetTime_Error
sglX = Int(sglTime / 3600#)
strHrs = Format$(sglX, "00")
sglY = Int(((sglTime / 3600#) - Int(sglTime / 3600#)) * 60#)
strMin = Format$(sglY, "00")
sglZ = Int(sglTime - (sglX * 3600# + sglY * 60#))
strSec = Format$(sglZ, "00")
sglV = sglTime - (sglX * 3600# + sglY * 60#) - Int(sglTime - (sglX * 3600#+ sglY * 60#))
strMSec = Format$(sglV * 100#, "00")
sfunGetTime = Mid(strHrs & ":" & strMin & ":" & strSec & "." & strMSec, 1, 11)
Exit Function

sfunGetTime_Error:
sfunGetTime = "ERROR"
' whatever you normally do in error handling
End Function
Another way would be to set up a timer control to cycle once every 1000 milliseconds,
set/increment a LONG variable and count seconds from the start time.

This discussion is closed to new replies.