Dear Gal,
I have developed habits from many years of report writing. One of those habits is that if the result of my formula is the variable I assigned a value to, I call the variable. I have seen instances where simply ending with:
X := if A = B
then
sum({Table.Myfield},{Table.FieldGroupedOn})
else 0;
for example may not return as expected. However, if I call the variable I just assigned the value to, it does.
Numbervar MyValue;
MyValue := if A = B
then
sum({Table.Myfield},{Table.FieldGroupedOn})
else 0;
MyValue
You can do if statements, loops, and all kinds of things, and you can do exactly what you showed in your example.
I tend to do mine as shown in the change to your example and again, a habit ....
Read the information in the help on variables ... they have requirements:
Scope - Where can I be used.
Global. Default if not declared. Means anywhere in the report, but not in subreports.
Local. This formula only. Allows you to reuse variable names over and over again in multiple formulas in the same report.
Shared. Can be used in the main report (global +) any subreports.
Datatype - What type of value? Number, boolean, date, datetime and so on ... declared as NumberVar, BooleanVar and so on.
Assignment operator for the value it has is a := (that is a colon equals sign with no space in between).
Statement separator. Statements are ended with a semicolon.
Name - Cannot use any keywords, functions, etc. If it turns blue can't use it.
There are no public variables. You must redeclare the variable in your formula each time you want to use the variable and you cannot change datatypes of a variable from formula to formula.
Variables are great, they make formulas easier to write and read ... enjoy.
regards,
ro
Rosemary Lieberman
rosemary-at-microflo.com,
Microflo provides expert consulting on MagicTSD and Crystal Reports.
You will get answers more quickly if you read this before posting: faq149-3762