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

Counting seconds from 1 to xxx until job finish

Status
Not open for further replies.

mstrcmtr

Programmer
Nov 14, 2007
103
PK
What is the way to show seconds counting from starting from 1 to xxx until job finish with command wait e.g.

wait window 'This process has taken .... ' 1,2,3,4,.... Seconds
 
The wait window then woudl itself need to take no time by NOWAIT and you'd need a place in the running code to create a new WAIT WINDOW after each second. Better use a Timer, though that also has it's cons, it'll not need anything in the long running code, the long running code just needs to allow events to happen by calling DOEVENTS once in a while at least.

Bye, Olaf.
 
mstrmtr,
I might suggest another approach. Usually this kind of thing is to let people know how long to expect a process to run (and that it is running). I found a long time ago, it is more accurate to keep some record of the previous run, and show that. So what you might do is capture the start and end times of the process, and store that value in a table that you increment each time the process runs.
Then, when the process starts next time you can show something like "This process was last run <date, or yesterday> and took <Minutes:Seconds> to run. The start time now is <start time> Estimated time to complete based on the last run is <start time+minutes/seconds from last run>.
You can adjust that if you find that over time, the average is more accurate. But most of the time I find these processes increase in time slightly over time, if there is more data to crunch.

Another method is to check how long it takes to run a single "loop", and if you are able to tell how many records the process will run against in a batch, then you can say something like:
"There are 1,233 records to process, with an average process time of .02 seconds per record, this process should complete in approximately 25 seconds. The start time is HH:MM:SS".

This will let people know when they can expect things to be done.

These approaches may be better than just ticking the seconds off as something runs, as it gives the user a better idea of when a process will finish.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
There is nothing that will automatically "count seconds". You have to do that yourself.

The usual way is to store the start time (usually as Seconds()) and do the math each time you want to update the display, which you have to do as well. In a loop, it's usually just a matter of adding your WAIT WINDOW NOWAIT on each iteration.

On a single command (REPLACE, UPDATE, etc.), there isn't a loop but you can SET TALK WINDOW and the normal output of that command (controlled by SET ODOMETER) will be displayed in a WAIT WINDOW while it runs.

Be aware that adding this kind of instrumentation can actually make processes take longer. [glasses]
 
>Be aware that adding this kind of instrumentation can actually make processes take longer
Especially WAIT WINDOW ... NOWAIT in every iteration or other things you'd do in every iteration.

SET TALK WINDOW is perhaps, what you are looking for.

Bye, Olaf.
 
Here's how I would do this:

Code:
lnStart = SECONDS()

* Perform your main loop
DO WHILE .... or whatever

  * Do some processing in the loop
    ....
    ....

  * Now display the number of seconds
  WAIT WINDOW "This process has taken " + TRANSFORM(SECONDS() - lnStart) NOWAIT

ENDDO

But two things to keep in mind:

- As other have said, the act of displaying this message will itself slow the process down. A Wait Window adds a definite overhead in any loop.

- Are you sure you really want to do this? You are simply telling the user how long something has taken so far. It tells them nothing about how fast it is running or how long they can expect to wait for it to finish.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Here is some code of mine that addresses the job right from my point of view, that is, shows an approximate on how long time the job will take. Also it only updates every 10th record so doesn't take much extra time.
Code:
startt=DATETIME()
SCAN
	IF (MOD(RECNO(),10)=0)
		nAverage=RECNO()/(DATETIME()-startt)
		timeleft=(RECC()-RECNO())/average
		IF timeleft>59
			cTimeleft=ALLTR(STR(timeleft/60))+' min'
		ELSE
			cTimeleft=ALLTR(STR(timeleft))+' sec'
		ENDIF
		THISFORM.label5.CAPTION= 'Adding row nr '+ALLTR(STR(RECNO()))+' ( '+ALLTR(STR(nAverage))+' rows/sek - Time left: '+cTimeleft+' ) ...'
		IF (MOD(RECNO(),1000)=0)
			DOEVENTS
		ENDIF
	ENDIF
	* Adding row...
ENDSCAN
 
may be

Code:
t_MessageTime = 2  && how often to display (in seconds)
t_PreSeconds  = 0
scan
   *
   * code
   *
   
   if abs( seconds() - t_PreSeconds ) >= t_MessageTime
       wait window "Working - " + time() nowait noclear
       t_PreSeconds = seconds()
   endif

endscan

wait clear  && Clear the above message
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top