• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

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.
0
bhorlings
Asked:
bhorlings
  • 2
1 Solution
 
mlmccCommented:
Actually it is more complex than that.  Crystal uses the ; to end a statement and if you need to execute more than 1 statement in a block like the THEN clause you use ( )

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
(                                                                 //If executes 2 statements
    //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;            //Semicolon to end the statement
        //Find out the overtime hrs (Total Hours - 40)
        numberVar ot_hrs := tot_hrs - 40;
   )                                                        //No semicolon because that would end the IF
    Else //The total hours is less than 40
    (                                                                  //Else executes several statements
        //Set the regular hours equal to total hours
        numberVar reg_hrs := tot_hrs;              //Semicolon
        //Set overtime hours = 0
        numberVar ot_hrs := 0;
    )
)
Else //New Employee Record
(
    //Total hours equals hours worked
    numberVar tot_hrs := hours;                    //Semicolon
    //Regular hours equals total hours
    numberVar reg_hrs := tot_hrs;                    //Semicolon
    //Set overtime hours to 0
    numberVar ot_hrs := 0;
);                                                                     //Semicolon
hours                                                          //Semicolon not required there is no statement after this

I hope the explanation helps.  If you have other questions just ask.

mlmcc
0
 
peter57rCommented:
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;
0
 
peter57rCommented:
half asleep....
0

Featured Post

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now