Link to home
Start Free TrialLog in
Avatar of bhorlings
bhorlingsFlag for United States of America

asked on

Formula with variables error. I hate semicolons!

I am using Crystal Reports XI to write a formula using variables to find the tot hours worked, regular hours worked, and overtime hours worked but I keep getting an error. I know it has to do with the placement of my semicolons but cannot figure it out. Below is the code for my formula:

WhilePrintingRecords;
//Find the hours worked that shift
numberVar hours := round({@TOut} - {@TIn}/3600,2);
//See if the employee is the same
If {PR_EMP.ID} = Previous({PR_EMP.ID}) Then
    //Find the total hrs worked
    numberVar tot_hrs  := tot_hrs + hours;
    //Find out if the total hours is greater than 40
    If tot_hrs > 40 then //If the total hours are greater than 40
        //Set the regular hours to 40
        numberVar reg_hrs := 40
        //Find out the overtime hrs (Total Hours - 40)
        numberVar ot_hrs := tot_hrs - 40;
    Else //The total hours is less than 40
        //Set the regular hours equal to total hours
        numberVar reg_hrs := tot_hrs
        //Set overtime hours = 0
        numberVar ot_hrs := 0;
Else //New Employee Record
    //Total hours equals hours worked
    numberVar tot_hrs := hours
    //Regular hours equals total hours
    numberVar reg_hrs := tot_hrs
    //Set overtime hours to 0
    numberVar ot_hrs := 0;
hours;

The error message read: The remaining text does not appear to be part of the formula.

Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WhilePrintingRecords;
numberVar tot_hrs;
numberVar reg_hrs;
numberVar ot_hrs ;
//Find the hours worked that shift
numberVar hours := round({@TOut} - {@TIn}/3600,2);
//See if the employee is the same
If {PR_EMP.ID} = Previous({PR_EMP.ID}) Then
(
 tot_hrs  := tot_hrs + hours;
    //Find out if the total hours is greater than 40
If tot_hrs > 40 then //If the total hours are greater than 40
        //Set the regular hours to 40
(       reg_hrs := 40;
        //Find out the overtime hrs (Total Hours - 40)
       ot_hrs := tot_hrs - 40)
    Else //The total hours is less than 40
        //Set the regular hours equal to total hours
       (  reg_hrs := tot_hrs;
        //Set overtime hours = 0
        numberVar ot_hrs := 0)
)
Else //New Employee Record
    //Total hours equals hours worked
 ( tot_hrs := hours;
    //Regular hours equals total hours
  reg_hrs := tot_hrs;
    //Set overtime hours to 0
    numberVar ot_hrs := 0);
hours;
half asleep....