PDA

Click to See Complete Forum and Search --> : [RESOLVED] Whats wrong with this code?


callydata
Oct 12th, 2005, 03:27 PM
I feel like this code should work! I want this formula to check for the appropriate dates and return the amount associated with it. What am I doing wrong????
This code is in Crystal syntax
//FUture START WITH NO END DATES
If IsNull({ACH.Ending}) And {ACH.Starting} > CurrentDate Then
"$" + {ACH.Amount}
Else If IsNull({ACH.Ending1}) And {ACH.Starting1} > CurrentDate Then
"$" + {ACH.Amount1}
Else If IsNull({ACH.Ending2}) And {ACH.Starting2} > CurrentDate Then
"$" + {ACH.Amount2}
Else If IsNull({ACH.Ending3}) And {ACH.Starting3} > CurrentDate Then
"$" + {ACH.Amount3}
Else If IsNull({ACH.Ending4}) And {ACH.Starting4} > CurrentDate Then
"$" + {ACH.Amount4}

//CuRRENT START WITH NO END DATES
Else If IsNull({ACH.Ending}) And {ACH.Starting} < CurrentDate Then
"$" + {ACH.Amount}
Else If IsNull({ACH.Ending1}) And {ACH.Starting1} < CurrentDate Then
"$" + {ACH.Amount1}
Else If IsNull({ACH.Ending2}) And {ACH.Starting2} < CurrentDate Then
"$" + {ACH.Amount2}
Else If IsNull({ACH.Ending3}) And {ACH.Starting3} < CurrentDate Then
"$" + {ACH.Amount3}
Else If IsNull({ACH.Ending4}) And {ACH.Starting4} < CurrentDate Then
"$" + {ACH.Amount4}

//NORMAL DATES
Else If {ACH.Starting} < CurrentDate And {ACH.Ending} > CurrentDate Then
"$" + {ACH.Amount}
Else If {ACH.Starting1} < CurrentDate And {ACH.Ending1} > CurrentDate Then
"$" + {ACH.Amount1}
Else If {ACH.Starting2} < CurrentDate And {ACH.Ending2} > CurrentDate Then
"$" + {ACH.Amount2}
Else If {ACH.Starting3} < CurrentDate And {ACH.Ending3} > CurrentDate Then
"$" + {ACH.Amount3}
Else If {ACH.Starting4} < CurrentDate And {ACH.Ending4} > CurrentDate Then
"$" + {ACH.Amount4}

//FUTURE DATES
Else If {ACH.Starting} > CurrentDate And {ACH.Ending} > CurrentDate Then
"$" + {ACH.Amount}
Else If {ACH.Starting1} > CurrentDate And {ACH.Ending1} > CurrentDate Then
"$" + {ACH.Amount1}
Else If {ACH.Starting2} > CurrentDate And {ACH.Ending2} > CurrentDate Then
"$" + {ACH.Amount2}
Else If {ACH.Starting3} > CurrentDate And {ACH.Ending3} > CurrentDate Then
"$" + {ACH.Amount3}
Else If {ACH.Starting4} > CurrentDate And {ACH.Ending4} > CurrentDate Then
"$" + {ACH.Amount4}

brucevde
Oct 13th, 2005, 12:20 PM
What am I doing wrong????

What is the problem? Are you getting a coding error or processing error (ie wrong amount is returned)?

callydata
Oct 14th, 2005, 09:05 AM
Well, what happens is depending on what chunk of code is at the top, different values show up. Does the order of the code make the difference? e.g. If the "NORMAL DATES" code is at the top, then only those amounts show up, and it seems to ignore the "FUTURE START WITH NO END DATES" code chunk altogether. But the opposite happens when they are switched around. does this make sense to you?
-cally

brucevde
Oct 14th, 2005, 10:19 AM
I don't know your data or business process so can only make assumptions...

does this make sense to you?
Yes, it does. Assume

Starting, Ending, Amount - Normal Date
Starting1, Ending1, Amount1 - Normal Date
Starting2, Ending2, Amount2 - Future Start No End Dates.

Based on the code you posted Amount2 will be returned when the 3rd If statement is processed.
Now move the Normal Dates section to the top. Amount will be returned when the 1st If statement in that section is processed.