How to Use a Shared Variable in a Crystal Report

By Techwalla Contributor

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.

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:Shared NumberVar UserAge;UserAge := {Table1.Age};""

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:Shared NumberVar UserAge;UserAge

Step 3

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