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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run a prg file every monday

Status
Not open for further replies.

foxuser20

Programmer
Jan 7, 2016
7
PH
hello guys..
how to do a prg file in vfp once in a monday only.
or in other words, if the program is open in monday then
the prg will be executed once.
my problem is when the user reopens the program on the same day,
the prg will again be executed.

what i want is that the prg will run only once if monday is meet.
any help will be appreciated. thankx
 
First, you need to detect that today is Monday. That's easy:

Code:
IF DOW(DATE()) = 2
  * Today is Monday
ELSE
  * It's some other day
ENDIF

Next, you need a mechanism to record the fact that the program has already been run today. There are several places where you might store that information, for example:

- In a table. If you already have some sort of settings or configuration table, you could use that. Or you could have a separate table just for that purpose.

- In a text file.

- In the Windows registry.

In each case, you only need to store the date that the program was run. If, on start-up, you determine that today is Monday and the program hasn't been run on today's date, you go ahead and run it. Otherwise, you don't.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Another option would be to use the Windows Scheduler. That will provide exactly what you want, without you having to do any additional programming. You could set it up to run a task, once only in a given day, and only on Mondays. It would also allow you to specify what time you want it to run.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Like Mike has suggested, I typically use Windows Task Scheduler.
I create a VFP application into an EXE and I then schedule the EXE to run when needed.

Now if I need certain date/time-specific functions to run within an over-all EXE then I do it with code to recognize the DOW and TIME.
The app will by-pass those functions when it is not the desired specific date/time. But if it is correct, the routine will run.
Generally those over-all apps run un-attended and are launched with Windows Task Scheduler.

my problem is when the user reopens the program on the same day, the prg will again be executed.
If this utility was handled by an un-attended EXE run with Windows Task Scheduler, then this would not likely be a problem.
Regardless, you can easily have a 'log' table that has a field set to some value when the utility is run.
Your utility would first, no matter how it was launched, check that table to see if it needed to be run or not - thereby preventing it from being run a 2nd time on the same day.

Good Luck,
JRB-Bldr


 
thanks for your replies..
still newbie in vfp, could you pls give example of it.
 
Hello,

Just from the top of my head so this may contain errors. You could compile this to an EXE then put it in Windows Task Scheduler.

Code:
LOCAL run_ok
run_ok = .F.

IF NOT FILE("c:\runchk.dbf")	&& Sample only, I suggest you place your "log" file somewhere safe
	CREATE TABLE ("c:\runchk.dbf") FREE ;
		(run_date D)
ELSE
	USE ("c:\runchk.dbf") IN 0
	SELECT runchk
ENDIF

IF UPPER(CDOW(DATE())) = "MONDAY"
	run_ok = (ISNULL(run_date) ;
		OR EMPTY(run_date) ;
		OR BLANK(run_date)) ;
		OR DATE() <> run_date
ELSE
	run_ok = .F.
ENDIF

IF run_ok && then go ahead an run the program
	*< do whatever here>*

	* And before quitting
	SELECT runchk
	IF RECCOUNT("runchk") = 0
		APPEND BLANK
	ENDIF

	REPLACE run_date WITH DATE()
ELSE
	* No need to run so just quit
ENDIF


kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
You don't need any code, if you use Task Scheduler. It is a windows feature and has nothing to do with Foxpro.

Bye, Olaf.
 
You could compile this to an EXE then put it in Windows Task Scheduler.

Why? If he is going to use the Windows Task Secheduler, he doesn't need his program to test for Monday or to record the fact that the program has already run. That's the whole point of using the Task Scheduler.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello Sirs,

I couldn't agree more. But as an added "safety net", I put the testing for Monday if in case the user decided to run the program manually and thus avoiding probable issues along the way like duplicated records or something. Just my two cents.

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
If the program was REQUIRED to be run each Monday, I'd try to eliminate the user from its operation.

I would compile the program into a stand-alone EXE (separate from any other part of the application).
Then I would configure the Windows Task Scheduler to run the EXE when needed.

Additionally I would have the program write out a date-time stamp to some simple log table when it ran.

If someone were to try to manually run the program, it would first look for the date-time stamp and 'know' that it had already been run - thereby preventing it from being run a 2nd time.

Good Luck,
JRB-Bldr
 
In addition to MikeLewis's initial comment, our former programmer had developed an application which relied on another table that had dates in - this allowed the program to run WITHIN the dates entered in the table.
You could write into the table the times which your EXE is supposed to run. Then, whenever the exe is fired by some other means (by user or shedule), the EXE won't run until the PC matches the time in the depending table.
I'm sure it would be something like:
Code:
USE dependanttable
IF time < 08:59:59 AND > 09:29:59 
THEN
DO my.prg
ENDIF
or something of the sort. Task Scheduler also gives you the ability to run things at a certain day for a certain time and also gives the option to kill the task, should it run longer than it needs to!

VibrantSeeker.

A conclusion is simply a place where you got tired of thinking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top