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

Eaiser way 1

Status
Not open for further replies.

Glitchen

MIS
Joined
Jun 6, 2003
Messages
48
Location
US
Is there an eaiser way to write this expression?

Every time the SvcFrequency increments by 1 the service date goes up by 7.

if
{ServiceInfo.SvcFrequency} = "W001"
then
{ServiceHistory.ServiceDate} + 7
else
if
{ServiceInfo.SvcFrequency} = "W002"
then
{ServiceHistory.ServiceDate} + 14
else
if
{ServiceInfo.SvcFrequency} = "W003"
then
{ServiceHistory.ServiceDate} + 21
else
if
{ServiceInfo.SvcFrequency} = "W004"
then
{ServiceHistory.ServiceDate} + 28
else
if
{ServiceInfo.SvcFrequency} = "W005"
then
{ServiceHistory.ServiceDate} + 35
else
if
{ServiceInfo.SvcFrequency} = "W006"
then
{ServiceHistory.ServiceDate} + 42
else
if
{ServiceInfo.SvcFrequency} = "W007"
then
{ServiceHistory.ServiceDate} + 49
else
if
{ServiceInfo.SvcFrequency} = "W008"
then
{ServiceHistory.ServiceDate} + 56
else
if
{ServiceInfo.SvcFrequency} = "W009"
then
{ServiceHistory.ServiceDate} + 63
else
if
{ServiceInfo.SvcFrequency} = "W010"
then
{ServiceHistory.ServiceDate} + 70
else
if
{ServiceInfo.SvcFrequency} = "W011"
then
{ServiceHistory.ServiceDate} + 77
else
if
{ServiceInfo.SvcFrequency} = "W012"
then
{ServiceHistory.ServiceDate} + 84
 
Try:

{ServiceHistory.ServiceDate} + 7 * val(mid({ServiceInfo.SvcFrequency},2))

-k
 
Perhaps I should have tossed in error checking:

if isnumeric(mid({ServiceInfo.SvcFrequency},2)) then
{ServiceHistory.ServiceDate} + 7 * val(mid({ServiceInfo.SvcFrequency},2))
else
0

-k
 
That works perfect, Now is there a way to look at that formula and repeat it over and over to a specified end date?
Such as
So if the last service date was 1/1/07 and the freqency is w002 (every 2 weeks) then the next service dates would be
1/15/07
1/29/07
...
...
...
To the end date.

Thanks!!!
 
A bit more complex:

whileprintingrecords;
Stringvar Out:="";
Datevar MyDate:=
{ServiceHistory.ServiceDate} + 7 * val(mid({ServiceInfo.SvcFrequency},2));
Datevar NewDate := cdate(year(MyDate),12,31);
Numbervar x;
For X:=1 to 26 do(
if MyDate < NewDate then
Out:=Out & MyDate & chr(13);
MyDate:=MyDate+14;
);
left(Out,len(Out)-1)

Make sure that you right click the field and select format field->Common->Can Grow

-k
 
Thanks for your quick response

I am getting the error a date is required here on the line
{ServiceHistory.ServiceDate} + 7 * val(mid({ServiceInfo.SvcFrequency},2));


 
Is the field a date? If not, cdate should convert it.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Yes it is a date. Actually its date/time
 
As Madawc suggests, try:

cdate({ServiceHistory.ServiceDate}) + 7 * val(mid({ServiceInfo.SvcFrequency},2));

-k
 
That works but it only show 2 dates. I am assuming because there are 2 records in the database for that custoer.
Should I be putting this in a sub report?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top