on 01-13-2010 6:00 PM
Hi!
I am new to development in Crystal. What method do you recommend to verify my formulas are doing what I expect? For example, in other environments I would print or prompt the result.
What is the best approach in Crystal?
Any help you can provide will be appreciated.
I just tried Carl's suggestion of using the debug statement but must be doing something wrong because I am just getting a "division by zero" prompt as a result, no values.
Any ideas what I forgot to do?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm sorry, I should have mentioned to put this at the BOTTOM of the formula, not at the top. The values displayed are what they are at the point of the divide by zero error. If the division is first thing in the formula, none of the other calculations have been performed yet... (Actually, you want to put it at the exact point where you want the breakpoint. That can be in the middle of the formula.)
HTH,
Carl
Never mind, Carl. I realize now I wasn't looking in the left pane. Your suggestion works.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carl,
I must still be doing something wrong as it still isn't working for me. Can I use your suggestion within a custom function?
Below is my code:
Function cdQSIPeriod () As String
dim debug as number
dim YY as number
dim MM as number
YY = Year(CurrentDate)
MM = Month(CurrentDate)
If MM = 1 then
MM = 12
YY = YY - 1
else
MM = MM - 1
End If
cdQSIPeriod = MM&YY
debug = debug / debug
End Function
Any help you can provide will be appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It really depends on what you're trying to achieve. If it's simply seeing if the calculation is right, just drop the field in the appropriate format and have it printed (or add a new format for this purpose that you can suppress or display).
If a formula comes up with a value and you can't figure out why, my approach has been to add the following code to the formula in question (basic syntax):
dim debug as number
debug = debug / debug
This will cause a divide by zero error, which will then cause Crystal to pull up the formula. On the left of the window, all fields and variables used in the formula are displayed with their current value. (You need to use the "debug" variable because Crystal Designer will give a syntatical divide by zero error if you code "formula = 1 / 0"...)
As written, the breakpoint will hit on the first iteration of the formula. You can cause the "breakpoint" to happen on later iterations by using something like:
global dbgcnt as number
dim debug as number
dbgcnt = dbgcnt + 1
if dbgcnt = 5 then
debug = debug / debug
end if
where the "5" is the iteration number that you want it to break on.
If anyone has a better way to "set a breakpoint", I'd love to hear it! (Ah ha! A great idea for the Suggestions thread. Going there now!)
HTH,
Carl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is no single or best method. I will sometimes comment out portions of a formula to check results at a certain stage. If you are working with a variable shared across formulas or sub-reports, you might create a display formula to show the current value. I have also created copies of a formula enabling one piece of an expression at a time to make sure it evaluates as I expect it should.
Fuskie
Who thinks the best method is to have validated results to compare the report against...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.