How to Use a Shared Variable in a Crystal Report

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
How to Use a Shared Variable in a Crystal Report
Image Credit: AlexBrylov/iStock/Getty Images

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.

Advertisement

Step 1

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:

Video of the Day

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

Advertisement

Step 2

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:

Advertisement

Shared NumberVar UserAge; UserAge

Step 3

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

Video of the Day

Advertisement

Advertisement

references