Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

VB help......

Thread Tools
 
Search this Thread
 
Old 18 September 2002, 02:25 PM
  #1  
CC
Scooby Regular
Thread Starter
 
CC's Avatar
 
Join Date: Aug 2000
Posts: 909
Likes: 0
Received 0 Likes on 0 Posts
Question

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]
Old 18 September 2002, 02:52 PM
  #2  
Crispin
Scooby Regular
 
Crispin's Avatar
 
Join Date: Jan 2001
Posts: 534
Likes: 0
Received 0 Likes on 0 Posts
Post

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...
Old 18 September 2002, 03:02 PM
  #3  
Crispin
Scooby Regular
 
Crispin's Avatar
 
Join Date: Jan 2001
Posts: 534
Likes: 0
Received 0 Likes on 0 Posts
Post

'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]
Old 18 September 2002, 04:03 PM
  #4  
CC
Scooby Regular
Thread Starter
 
CC's Avatar
 
Join Date: Aug 2000
Posts: 909
Likes: 0
Received 0 Likes on 0 Posts
Thumbs up

wow, thanks! will try it and let you know how i get on....

many thanks!
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
AndyLyman
Wheels, Tyres & Brakes
4
19 February 2007 12:27 PM
AndyLyman
ScoobyNet General
1
16 February 2007 07:41 PM
Scratch
General Technical
6
15 September 2005 09:10 PM
Avi
Computer & Technology Related
8
19 July 2002 08:12 AM
Nathan L
Wheels, Tyres & Brakes
11
04 April 2002 10:15 PM



Quick Reply: VB help......



All times are GMT +1. The time now is 09:33 PM.