VB help......
#1
Hi
I have a simple vb program which is used to update certain files on our main server etc. The exact times it executes is determined by the windows scheduler. It is scheduled to execute on the hour.
However, I'd prefer it if the program could run permanently in the background and determine by itself whether it was the right time to do it's stuff and run certain procedures within the program....by checking for a certain condition such as time etc...
Any suggestions greatly appreciated.
ps just to add, obviously I could use an IF clause or something that could check the time but when I have tried this, it works ok, but it uses up all of my pc's resources, causing everything to grind to a halt until when the condition is true....hope I have explained this ok?
[Edited by CC - 9/18/2002 2:27:24 PM]
I have a simple vb program which is used to update certain files on our main server etc. The exact times it executes is determined by the windows scheduler. It is scheduled to execute on the hour.
However, I'd prefer it if the program could run permanently in the background and determine by itself whether it was the right time to do it's stuff and run certain procedures within the program....by checking for a certain condition such as time etc...
Any suggestions greatly appreciated.
ps just to add, obviously I could use an IF clause or something that could check the time but when I have tried this, it works ok, but it uses up all of my pc's resources, causing everything to grind to a halt until when the condition is true....hope I have explained this ok?
[Edited by CC - 9/18/2002 2:27:24 PM]
#2
Depends what you want to do and how critical the timing is......is it vb6 or .NET?
Your best bet is to write a service application, but you can't do it in VB6 (without special component(s))second, you could get around it by writing a program that loads and uses a timer (look up settimer API - don't use the timer control). and on the timer event (every second) checks the current time, and performs a variety of functions based on the time.....
oh bollocks i'll do you a sample in vb6 - wait there...
Your best bet is to write a service application, but you can't do it in VB6 (without special component(s))second, you could get around it by writing a program that loads and uses a timer (look up settimer API - don't use the timer control). and on the timer event (every second) checks the current time, and performs a variety of functions based on the time.....
oh bollocks i'll do you a sample in vb6 - wait there...
#3
'IN A MODULE
Option Explicit
Private Enum RESULTSEnum
TASK_SUCCESS = 0
TASK_FAIL = -1
TASK_ERR = 1
End Enum
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Dim CTime As Date
CTime = Format(Now, "HH:MM:SS")
Debug.Print CTime
If DoAJob(CTime) = TASK_SUCCESS Then
'WRITE TO A LOG OR SOMETHING
ElseIf DoAJob(CTime) = TASK_FAIL Then
'TAKE APPROPRIATE ACTION ON FAILURE
ElseIf DoAJob(CTime) = TASK_ERR Then
'I KNOW YOU SHOULDN'T REF the hWnd this way
'STOP THE TIMER
KillTimer Form1.hwnd
'DO WHATEVER
End If
End Sub
Public Function DoAJob(Time As Date) As RESULTSEnum
On Error GoTo errorhandler
Select Case Time
Case Is = CDate("14:55:00")
Debug.Print "TWO FIFTY SEVEN"
DoAJob = TASK_SUCCESS
Exit Function
Case Else
DoAJob = TASK_FAIL
Exit Function
End Select
errorhandler:
DoAJob = TASK_ERR
Exit Function
End Function
'IN A FORM
Option Explicit
Private Sub Form_Load()
SetTimer Me.hwnd, 0, 1000, AddressOf TimerProc
End Sub
Private Sub Form_Unload(Cancel As Integer)
KillTimer Me.hwnd, 0
End Sub
I checked task manager on this - and it's very light on resources.
[Edited by Crispin - 9/18/2002 3:09:36 PM]
Option Explicit
Private Enum RESULTSEnum
TASK_SUCCESS = 0
TASK_FAIL = -1
TASK_ERR = 1
End Enum
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Dim CTime As Date
CTime = Format(Now, "HH:MM:SS")
Debug.Print CTime
If DoAJob(CTime) = TASK_SUCCESS Then
'WRITE TO A LOG OR SOMETHING
ElseIf DoAJob(CTime) = TASK_FAIL Then
'TAKE APPROPRIATE ACTION ON FAILURE
ElseIf DoAJob(CTime) = TASK_ERR Then
'I KNOW YOU SHOULDN'T REF the hWnd this way
'STOP THE TIMER
KillTimer Form1.hwnd
'DO WHATEVER
End If
End Sub
Public Function DoAJob(Time As Date) As RESULTSEnum
On Error GoTo errorhandler
Select Case Time
Case Is = CDate("14:55:00")
Debug.Print "TWO FIFTY SEVEN"
DoAJob = TASK_SUCCESS
Exit Function
Case Else
DoAJob = TASK_FAIL
Exit Function
End Select
errorhandler:
DoAJob = TASK_ERR
Exit Function
End Function
'IN A FORM
Option Explicit
Private Sub Form_Load()
SetTimer Me.hwnd, 0, 1000, AddressOf TimerProc
End Sub
Private Sub Form_Unload(Cancel As Integer)
KillTimer Me.hwnd, 0
End Sub
I checked task manager on this - and it's very light on resources.
[Edited by Crispin - 9/18/2002 3:09:36 PM]
Thread
Thread Starter
Forum
Replies
Last Post
AndyLyman
Wheels, Tyres & Brakes
4
19 February 2007 12:27 PM
Nathan L
Wheels, Tyres & Brakes
11
04 April 2002 10:15 PM