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

IF-THEN-ELSE error "A number is required"

Status
Not open for further replies.

hjohnson919

Programmer
May 25, 2005
9
US
I'm converting a formula from Basic to Crystal syntax. I'm using CR 10 against an Avatar (AKA NetSmart) hospital information system. The routine is supposed to calculate the number of days the person has been certified. The error message I'm getting is "A number is required here" and everything from the "ELSE //error here" down is highlighted. Lots of lines of code commented out in order to try to find the error. Is it punctuation?

WhilePrintingRecords;
Global DateVar CertBegin;
Global DateVar CertEnd;
Global DateVar CertSave;
Global NumberVar CertDays;
Global NumberVar FAdultCertDays;
Global NumberVar FAdolCertDays;
Global NumberVar TotalCertDays;
Global BooleanVar FirstRecordFlag;
// ?EndDate is a date
//
IF FirstRecordFlag THEN
(
FirstRecordFlag := FALSE;

CertBegin := {view_episode_summary_admit.preadmit_admission_date};

// Decide what value to use as the end of the certification period
// If there is no decertification date and no discharge, use the parameter date
// If there is no decertification date but there is a discharge, use the discharge date
// If there is a decertification date use it
IF ISNULL({certification.decertified_date}) THEN
(
IF ISNULL({view_episode_summary_admit.date_of_discharge}) THEN
(
CertEnd := {?EndDate}
)
ELSE
(
CertEnd := {view_episode_summary_admit.date_of_discharge}
)
)
ELSE
(
CertEnd := {certification.decertified_date} //decertified_date is not null
);

//Once you have a date for the end of certification, compare it to the beginning of certification
//If they were certified and decertified on the same day, it still counts as 1 day
CertDays := DATEDIFF("d", CertBegin, CertEnd);

IF CertDays = 0 THEN
(
CertDays := 1
)
)
ELSE //error here
//FirstRecordFlag is false so it is a second record
//(
// IF ISNULL({certification.decertified_date})
// THEN
// (
// IF NEXT({view_episode_summary_admit.PATID})={view_episode_summary_admit.PATID}
// AND NEXT({view_episode_summary_admit.EPISODE_NUMBER}) = {view_episode_summary_admit.EPISODE_NUMBER}
// THEN CertSave := {certification.recertified_date}
// ELSE CertBegin := {certification.recertified_date};
//Next record is for a different person or a different episode for this person

// IF ISNULL({view_episode_summary_admit.date_of_discharge})
// THEN CertEnd := {?EndDate}
// ELSE CertEnd := {view_episode_summary_admit.date_of_discharge};

// IF CertBegin = CertEnd
// THEN CertDays := CertDays + 1
//if the person was recertified on the day they were discharged,
//add that one day to the count
// ELSE CertDays := CertDays + DATEDIFF("d", CertBegin, CertEnd);
// )
// ELSE //there is a decert date
// (
CertBegin := CertSave;
// CertEnd := {certification.decertified_date};
// CertDays := CertDays + DATEDIFF("d", CertBegin, CertEnd)
//I'm not sure what to do if a person
//is recertified and decertified on the same day - I'm counting the day as NOT certified here.
//)
//;
IF {view_episode_summary_discharge.disc_unit_code} = "APSF" AND {@AdmitAge} >=18.0
THEN FAdultCertDays := CertDays;

IF {view_episode_summary_discharge.disc_unit_code} = "APSF" AND {@AdmitAge} <18.0
THEN FAdolCertDays := CertDays;
 
Between the IF and ELSE you have one open-brackets and two close,
Code:
IF CertDays = 0 THEN 
  (
    CertDays := 1
  )
[b])[/b]
ELSE //error here

I'd also suggest you break up the logic into a number of formula fields. e.g
Code:
IF ISNULL ({view_episode_summary_admit.date_of_discharge}) 
 THEN  {?EndDate}
ELSE {view_episode_summary_admit.date_of_discharge}
Should be much simpler once you are used to it.


[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
If the if then else statement is declaring a number type is required you may need to ensure that the outputs are of the same type. For example:

If {table.field} = 1 then {table.stringfield} else {table.numberfield}

would not work. However:

If {table.field} = 1 then val({table.stringfield}) else {table.numberfield}
//(If the string is a number)
or
If {table.field} = 1 then {table.stringfield} else totext({table.numberfield})
//(If both are to be strings

Would work.

If you later call on this field as a numerical value you may need to then convert back to a number using tonumber() or val() for the sake of summaries / calculations.

'J
 
Thanks, guys. The problem was in the mind set of the programmer. Being an old Fortran, Pascal, etc. programmer, I'm used to putting just about anything I like in an IF-THEN-ELSE statement. The idea that the THEN has to end in the same type of variable as the ELSE because it is "returning" a value was a completely new concept to me. I will, from now on, simple put a 0 as the last line of each THEN and ELSE section. Thanks again. - HJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top