Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting VB program on Clock Time 1

Status
Not open for further replies.

bdommer

Technical User
Jan 2, 2002
2
US
Hey Folks

Does anyone know how to start a Visual Basic program using clock time? I have a VB program I'd like to run 15 minutes before the start of each hour.

thxs
 
Use the AT (@) scheduler that come as part NT/2000.
The resource kit has a GUI for this command line tool.
Steven Fowler, Principal
steve@fowlerconsulting.com
- Development, Training, and Consulting
wpe1.gif
 
write an application that checks the clock, calculates how long until a quarter til, then sleeps for that amount of time. When the sleep is done, have it shell the application that you want to launch at quarter til, then check the time until it runs again and sleep... in a loop

while true
nCyclesTilRun = CheckTime
Sleep nCyclesTilRun
shell theDesiredApp, OtherParams, etc.
wend

Function CheckTime() As Long
Dim CurrentTime As Date
Dim NumMins As Long
Dim Duration As Long

'Quick and dirty. You can make it more exact if needed.
CurrentTime = Now()
NumMins = Minute(CurrentTime)
If NumMins < 15 Then
Duration = 15 - NumMins
Else
Duration = 75 - NumMins
End If
Duration = 1000 * Duration

CheckTime = Duration
End Function

Here's the sleep bit:
Declare Sub Sleep Lib &quot;kernel32&quot; _
(byval dwMilliseconds as Long)

And shell:
Declare Function ShellExecute& Lib &quot;shell32.dll&quot; _
alias &quot;ShellExecuteA&quot; (ByVal hwnd As Long, ByVal _ lpOperation As String, ByVal lpFile As String, ByVal _ lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long)

That should give you some ideas

scarfhead
 
scarfhead

Thanks for the program. I copied the code and recieved an error message upon saving that read, &quot;Only comments may appear after End Sub, End Function, or End Property.&quot; I think its referring to the Declare statements. What am I doing wrong.

thxs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top