Solved

Timer to run a program

Posted on 2000-03-14
8
194 Views
Last Modified: 2012-05-04
I have a program which I need to continuously loop by using a timer or whatever I need to make this happen. I have a program that monitors an error log and move that file to a different folder. I need for the program to keep monitoring even though there is no more error log file. The error log file folder will keep updating itself every 30 minutes. Is there a way for me to keep my program running to monitor my log file?
0
Comment
Question by:gabedc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:mflam
ID: 2617626
There's a timer object in VB.
You set the interval, and turn it on/off by setting it's "enabled" true or false.
You add it to your form.
Double click it, and write what you want should happen when the "timer event" is "fired".
Here you can put code that checks if the file exists, moves it to another folder (creates the new folder) opens the logfile and appends to it, or does anything else you wish the program to do.

HTH, Moshe
0
 

Author Comment

by:gabedc
ID: 2617660
Could you please give me a sample of how I should write the Timer program. I know it should look like this:
Private Sub Timer1_Timer()
what should I write here to make sure the loop doesn't end.

End Sub
0
 

Expert Comment

by:kpcapel
ID: 2617734
You don't need to write code to make sure the loop doesn't end, its built in.
Set the interval property of the timer control to the number of milliseconds you'd like between calls to the timer event.  Just insert the code which checks your log file into the timer event.  It will execute at the interval you set as long as the form which contains the timer is loaded and the enabled property is true.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
kpcapel earned 50 total points
ID: 2617749
Simple code...

'Set the Enabled property to True and the Interval property to the interval you want
'You could do this directly through the property page for the control rather than in the Form_Load event
Private Sub Form_Load()
  Timer1.Enabled = True
  Timer1.Interval = 10000  '10 seconds
End Sub
'Insert your code into the Timer event
Private Sub Timer1_Timer()
  'Code for checking your logfile goes here
End Sub

You can turn off the loop by setting "Timer1.Enabled = False" at any time, or by unloading the form which contains the Timer control.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2617752
Option Explicit

Private Sub Form_Load()
    Timer1.Interval = 60000 '1 minute
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    'This code will execute every minute
    Dim sFile As String
    sFile = "c:\test.log"
    On Error Resume Next
    If Dir(sFile, vbNormal) <> "" Then
        Name sFile As "d:\back.log"
    End If
End Sub
0
 
LVL 2

Expert Comment

by:johnny6
ID: 2618008
Option Explicit
Dim iElapsedMin As Integer
Const cMax_Min As Integer = 30 'Set the maximum number of minutes for the interval here.

Private Sub Form_Load()
Timer1.Enable = True
iElapsedMin = 1
End Sub

Private Sub Timer1_Timer()
lblText.Visible = (iElapsedMin = cMax_Min)
Timer1.Enabled = (iElasedMin < CMax_Min)
iElapsedMin = iElapsedMin + 1
End Sub



Here is another solution which involves using the static variable:


Sub Timer1_Timer()
  Static TimerTimes As Integer
  TimerTimes = TimerTimes + 1
  If TimerTimes = 30 Then 'Number of minutes for interval.
    TimerTimes = 0  'reset counter
    'Add your once an hour code here.
  Else
    Exit Sub
  End If
End Sub


Make sure you set the Interval property of the timer to 30000 in whichever example you use.

John
0
 
LVL 28

Expert Comment

by:Ark
ID: 2618263
Hi
You need not to make loop - Windows do it itself. You only need to receive change notification. Take a look at http://www.mvps.org/vbnet/code/fileapi/watchedfolder.htm
Cheers
0
 
LVL 28

Expert Comment

by:Ark
ID: 2618276
Hi
This sample is better for your purpose
http://www.mvps.org/vbnet/code/shell/shchangenotify.htm
Cheers
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question