Search code examples
crystal-reports

use of local variable and global variable in crystal reports


Hello all I am new to crystal reports. I just want to know what is a local and a global variable. Please suggest what is the difference between local and global variables.


Solution

  • local variable: as the name says it is local to the formula created... it can't be used outside the formula declared.

    Use: if you want to use the same name for a variable across many formulas then it should be used.

    Global Variable: it can be used out side the scope of the formula created.

    use: during calculations there will be use to reset the variable value to 0 anywhere in the report then this should be used.

    Along with this there is one more variable that is `Shared` it also acts as a global variable
    
    use: it is also used in resetting the value and also pass values between main report and sub report and viceversa
    

    Edit:*******************

    E.g;

    creating formula count

    Global numbervar a;
    a:=a+1;
    a
    

    Now I want to reset the value to 0 on change of every group then I use the below formula in group header as below.

    Global Numbervar a;
    a:=0