FoxPro/total hours

Advertisement


Question
Good day sir!

Say I have time records such as:

DATE     Completed Hours
10/25    8:00
10/26    8:00
10/27    8:00
10/28    7:30
10/29    8:00

I want to get the "sum/total" of the Completed Hours.
The result must be 39:30
Can you give me example formula for this?
(using vfp9.0)

Many thanks!

Answer
Hi AJ,

  In the following code, the completed hours field is CompHrs.  It assumes that the open table has the field and is properly filtered for your data needs.  When the program is complete, the sum of all records in in the memory variable "TOTAL"

hh = 0
mm = 0
GO top
DO WHILE NOT EOF()
  hh = hh + VAL(LEFT(length,2))
  mm = mm + VAL(RIGHT(length,2))
  SKIP
ENDDO

hr = hh + INT(mm/60)
mn = MOD(mm,60)

TOTAL = PADL(ALLTRIM(STR(hr)),2,"0")+":"+PADL(ALLTRIM(STR(mn)),2,"0")

FoxPro

All Answers


Answers by Expert:


Ask Experts

Volunteer


Fred Frase

Expertise

Questions about development only. No installation or hardware specific questions, please. Your first step in requesting assistance should be to identify the version of FoxPro you are using. I can write short functions but, PLEASE do not ask me to write programs for you.

Experience

Nearly 30 years professional programming experience using FoxPro (FoxBase through VFP 9) or other xbase language, primarily in Windows environments.

Education/Credentials
Completed a 1,000 hour diploma course in programming at International Academy of Ohio (subsequently merged with Southern Ohio College).

©2016 About.com. All rights reserved.