How to Use a Shared Variable in a Crystal Report

Shared variables can be extremely useful in a Crystal Report. Unlike with local and global variables, the value stored in a shared variable can be set and/or seen anywhere in a Crystal Report. For example, you might create a shared variable called Age. You can then store the value 31 to Age in one subreport and display that value in another subreport.

Business Person reading Data on paper Charts and Computer
How to Use a Shared Variable in a Crystal Report
credit: AlexBrylov/iStock/Getty Images

Step

Set the shared variable. A shared variable can be set anywhere in the main report or anywhere in any subreport. To set a shared variable called Age you would use the following code:

Step

Shared NumberVar UserAge; UserAge := {Table1.Age}; ""

Step

Display or use the shared variable. A shared variable can be processed or displayed anywhere in the main report or anywhere in any subreport. You would share your Age variable like this:

Step

Shared NumberVar UserAge; UserAge

Step

Use your shared variable in formulas or sections anywhere in your report.