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

If...Else statement in a formula

Status
Not open for further replies.

oshlonger

IS-IT--Management
Oct 31, 2002
76
US
I have a formula that determines the number of business hours between 2 dates (excluding holidays).

Depending on the callcenter, the business hours are different. I can get the formula to work for 1 call center at a time, but I can't put it all together for each call center.

This is my formula as I have it now. Only business hours for the Europe callcenter are being displayed, even for the US callcenter...any suggestions?

IF {tbl.callcenter} = "North America" then

dateTimeVar Start:= {@US_DateCreated};
dateTimeVar End:= {@US_FirstContact};

timeVar defaultstarttime:= time(08,00,00);
timeVar defaultendtime:= time(20,00,00);

//path to the text file containing the US holidays to exclude
wdaysClass1wdLoadFile ("C:\US_holidays.txt");


IF {tbl.callcenter} = "EMEA" then

dateTimeVar Start:= {@Europe_DateCreated};
dateTimeVar End:= {@Europe_FirstContact};

timeVar defaultstarttime:= time(08,30,00);
timeVar defaultendtime:= time(18,00,00);

//path to the text file containing the EMEA holidays to exclude
wdaysClass1wdLoadFile ("C:\Europe_holidays.txt");


///rest of formula continues on....

stringVar workingdays:= "-23456-";
 
You have to add brackets to set off the if-then block...also...and perhaps this is more style but your declarations should be at the start of the formula

WhilePrintingPrecords;
dateTimeVar Start;
dateTimeVar End;
timeVar defaultstarttime;
timeVar defaultendtime;
stringVar workingdays;

IF {tbl.callcenter} = "North America" then
(
Start:= {@US_DateCreated};
End:= {@US_FirstContact};
defaultstarttime:= time(08,00,00);
defaultendtime:= time(20,00,00);

//path to the text file containing the US holidays to
// exclude
//**********
//I have never done this so I assume this is OK to use
//**********

wdaysClass1wdLoadFile ("C:\US_holidays.txt");
);

IF {tbl.callcenter} = "EMEA" then
(
Start:= {@Europe_DateCreated};
End:= {@Europe_FirstContact};
defaultstarttime:= time(08,30,00);
defaultendtime:= time(18,00,00);

//path to the text file containing the EMEA holidays
//to exclude
//**********
//I have never done this so I assume this is OK to use
//**********

wdaysClass1wdLoadFile ("C:\Europe_holidays.txt");
);


///rest of formula continues on....

// I have no clue how the following fits into the formula
workingdays:= "-23456-";

Hope this helps...



Jim Broadbent
 
Thanks for your response. I probably didn't provide you with all the information but I was able to take your suggestions and apply them to my formula. I've been testing it this morning and everything is running fine.

Thanks again!
 
Jim,
I'm having some more problems with bracket placement in my if...else statement. Could you take a look?

The if..else for the country is not being read correctly and the else values are being used even when country = Japan.

IF {tbl.callcenter} = "Asia" then
(
Start:= {@Asia_DateCreated};
End:= {@Asia_FirstContact};

if {country} = "Japan" then
(
//business hours for Japan
defaultstarttime:= time(08, 00, 00);
defaultendtime:= time(16, 00, 00);
)
else
(
//business hours for rest of Asia
defaultstarttime:= time(09,00,00);
defaultendtime:= time(17,00,00);
);

workingdays:= "-23456-";
);

 
Jim,
Please disregard my last statement, I believe everything is running smoothly now.

 
Glad that it is worling for you....Crystal "if-then-else" structures can be confusing but once you understand them they are ok...

I'll give you another tip on their use...ALWAYS end each block with the same data type

This is a tough bug to find in a complicated structure.

For example THIS WORKS

NumberVar a;
NumberVar b;
StringVar y;
StringVar Z;

If {table.value} = value then
(
a := {table.number};
y := {table.string};
)
else
(
b := {table.number};
z := {table.string};
);

THIS **DOESN'T** WORK

NumberVar a;
NumberVar b;
StringVar y;
StringVar Z;

If {table.value} = value then
(
a := {table.number};
y := {table.string};
)
else
(
z := {table.string};
b := {table.number};
);

Sneaky, eh!!!



Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top