hjohnson919
Programmer
I'm trying to use a formula like a subroutine using Global variables to pass values back and forth. Does that work? Here is what I have:
REM @R&B
REM assumes everyone is discharged
WhilePrintingRecords
Global TestDate AS date
Global Fee AS number
Global Index AS number
Global LeftDif AS number
Global RightDif AS number
Global RangeDif AS number
Global Sdate AS date
Local KeepIndex AS number
Local KeepFee AS number
Local KeepRightDif AS number
Local SubtotalCharge AS number
Local Dummy AS number
Local NumDays AS number
Local i AS number
SubtotalCharge = 0
REM Find the row where the admission date falls between the start date and the end date
TestDate = {view_episode_summary_discharge.preadmit_admission_date}
Dummy = {@FindFee}
If Index = 0 _
Then
formula = -1
Else
KeepIndex = Index
KeepFee = Fee
KeepRightDif = RightDif
REM Check to see if the discharge date also falls between the start date and end date of that row
TestDate = {view_episode_summary_discharge.date_of_discharge}
Dummy = {@FindFee}
Select Case Index
Case 0
formula = -1
Case KeepIndex
NumDays = DateDiff("d", {view_episode_summary_discharge.preadmit_admission_date}, _
{view_episode_summary_discharge.date_of_discharge})
formula = NumDays * KeepFee
Case IS > KeepIndex
i = Index - KeepIndex - 1
REM calculate the subtotal of the charge from the admission date to the end of the first Fee
NumDays = KeepRightDif +1
SubtotalCharge = SubtotalCharge + (NumDays * KeepFee)
REM increment the subtotal by the amount from the start of the final Fee to the discharge date
NumDays = LeftDif
SubtotalCharge = SubtotalCharge + (NumDays * Fee)
REM work backward through the Fee changes as many times as needed
Do While i > 0
TestDate = CDate(DateAdd("d", -1, Sdate))
Dummy = {@FindFee}
NumDays = RangeDif
SubtotalCharge = SubtotalCharge + (NumDays * Fee)
i = i - 1
Loop
formula = SubtotalCharge
Case Else
formula = -1
End Select
End If
REM @FindFee
WhilePrintingRecords
Global TestDate AS date
Global Fee AS number
Global Index AS number
Global LeftDif AS number
Global RightDif AS number
Global RangeDif AS number
Dim Sdate AS date
Dim Edate AS date
If {view_episode_summary_discharge.program_code} = "APS" _
Then
Select Case TestDate
Case CDate(#9/1/2001#) To CDate(#11/30/2002#)
Fee = 589.00
Index = 18
Sdate =CDate(#9/1/2001#)
Edate =CDate(#11/30/2002#)
Case CDate(#12/1/2002#) To CDate(#7/31/2004#)
Fee = 647.00
Index = 19
Sdate =CDate(#12/1/2002#)
Edate =CDate(#7/31/2004#)
Case CDate(#8/1/2004#) To CDate(#1/1/2010#)
Fee = 756.00
Index = 20
Sdate =CDate(#8/1/2004#)
Edate =CDate(#1/1/2010#)
Case Else
Fee = 0
Index = 0
End Select
End If
If Index = 0 _
Then
LeftDif = 0
RightDif = 0
RangeDif = 0
Else
LeftDif = DateDiff ("d", Sdate, TestDate)
RightDif = DateDiff("d", TestDate, Edate)
RangeDif = DateDiff("d", Sdate, Edate)
End if
formula = Index
The very first time through, the TestDate is 11/20/2002 in the "calling" routine but null (or blank or something that doesn't print) in the "subroutine". The second, third, etc times if appears that the date is "passed" correctly but the returned answer is wrong.
My question is: am I on the right track? Will @FindFee be executed when the reference to it is found in @R&B? And will it be executed again when it is encountered a second and third time (the third time is actually in a loop)? Is my problem due to this technique or some other logic error?
REM @R&B
REM assumes everyone is discharged
WhilePrintingRecords
Global TestDate AS date
Global Fee AS number
Global Index AS number
Global LeftDif AS number
Global RightDif AS number
Global RangeDif AS number
Global Sdate AS date
Local KeepIndex AS number
Local KeepFee AS number
Local KeepRightDif AS number
Local SubtotalCharge AS number
Local Dummy AS number
Local NumDays AS number
Local i AS number
SubtotalCharge = 0
REM Find the row where the admission date falls between the start date and the end date
TestDate = {view_episode_summary_discharge.preadmit_admission_date}
Dummy = {@FindFee}
If Index = 0 _
Then
formula = -1
Else
KeepIndex = Index
KeepFee = Fee
KeepRightDif = RightDif
REM Check to see if the discharge date also falls between the start date and end date of that row
TestDate = {view_episode_summary_discharge.date_of_discharge}
Dummy = {@FindFee}
Select Case Index
Case 0
formula = -1
Case KeepIndex
NumDays = DateDiff("d", {view_episode_summary_discharge.preadmit_admission_date}, _
{view_episode_summary_discharge.date_of_discharge})
formula = NumDays * KeepFee
Case IS > KeepIndex
i = Index - KeepIndex - 1
REM calculate the subtotal of the charge from the admission date to the end of the first Fee
NumDays = KeepRightDif +1
SubtotalCharge = SubtotalCharge + (NumDays * KeepFee)
REM increment the subtotal by the amount from the start of the final Fee to the discharge date
NumDays = LeftDif
SubtotalCharge = SubtotalCharge + (NumDays * Fee)
REM work backward through the Fee changes as many times as needed
Do While i > 0
TestDate = CDate(DateAdd("d", -1, Sdate))
Dummy = {@FindFee}
NumDays = RangeDif
SubtotalCharge = SubtotalCharge + (NumDays * Fee)
i = i - 1
Loop
formula = SubtotalCharge
Case Else
formula = -1
End Select
End If
REM @FindFee
WhilePrintingRecords
Global TestDate AS date
Global Fee AS number
Global Index AS number
Global LeftDif AS number
Global RightDif AS number
Global RangeDif AS number
Dim Sdate AS date
Dim Edate AS date
If {view_episode_summary_discharge.program_code} = "APS" _
Then
Select Case TestDate
Case CDate(#9/1/2001#) To CDate(#11/30/2002#)
Fee = 589.00
Index = 18
Sdate =CDate(#9/1/2001#)
Edate =CDate(#11/30/2002#)
Case CDate(#12/1/2002#) To CDate(#7/31/2004#)
Fee = 647.00
Index = 19
Sdate =CDate(#12/1/2002#)
Edate =CDate(#7/31/2004#)
Case CDate(#8/1/2004#) To CDate(#1/1/2010#)
Fee = 756.00
Index = 20
Sdate =CDate(#8/1/2004#)
Edate =CDate(#1/1/2010#)
Case Else
Fee = 0
Index = 0
End Select
End If
If Index = 0 _
Then
LeftDif = 0
RightDif = 0
RangeDif = 0
Else
LeftDif = DateDiff ("d", Sdate, TestDate)
RightDif = DateDiff("d", TestDate, Edate)
RangeDif = DateDiff("d", Sdate, Edate)
End if
formula = Index
The very first time through, the TestDate is 11/20/2002 in the "calling" routine but null (or blank or something that doesn't print) in the "subroutine". The second, third, etc times if appears that the date is "passed" correctly but the returned answer is wrong.
My question is: am I on the right track? Will @FindFee be executed when the reference to it is found in @R&B? And will it be executed again when it is encountered a second and third time (the third time is actually in a loop)? Is my problem due to this technique or some other logic error?