Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to Declare a variable and how to call on it...

Status
Not open for further replies.

TekAtWork

Technical User
Oct 1, 2004
7
US
Can anybody help me in where to decalre a variable and how to call it from anywhere in the report???

Thanks!
 
It depends on how you want to retrive your data. I use SQL stored procedures to declare variables. All I do is create a stored procedure, then insert those fields on the report, using insert fields.Then insert the desired fields.
 
Variables are available anywhere in a report, you might try posting specifics.

Here's the rundown using a numeric example:

Local Numbervar:= sum({table.value})
Local designates that it's used ONLY in that formula

Global Numbervar:= sum({table.value})
Global designates that it's used anywhere in that report. This is the default.

Shared Numbervar:= sum({table.value})
Shared designates that it's used anywhere in that report or in subreports

If you do NOT designate Local, Global or Shared, then it defaults to Global, meaning that it's available anywhere within the report.

-k
 
AFK: Those aren't variables, those are data fields.

You can expose variables in a SP, and you might even return them to the report, but they will be considered data fields within the report.

-k
 
I am still confused on where do I declare the variable.

Example:
Let's say that I have 2 fields in a report, 1) Last Name 2) First Name. I want to run a formula that evaluates the Last Name and if the last name = "Smith" I want this formula to store the number 1 in a variable. At the end of the report, I want to print this Variable in the report footer.

Questions:
Where do I declare the variable? Do I use a formula field to do so or..??
How do I call the variable so I can give it a new value using a formula?
How do I call the variable to print it in the report?

Thanks in advance for all your help!!!
 
Use a formula in the detail section for this.

Your example would be:

whileprintingrecords;
numbervar Smiths;
If {table.last} = "SMith" then
Smiths:=Smiths+1

In the report footer you could use th following to display it:

whileprintingrecords;
numbervar Smiths

This is a bad example because there are much simpler ways to accomplish this, such as a Running Total, select the field, use a count as the type, and in the Evaluate Use a Formula just place {table.last} = "Smith"

Or you might use a Cross-Tab and place the Last Name in the Rows and in the summary section and select count to get all names in one simple action (place the cross-tab in the report header or report footer).

Ratehr than suggesting technologies, try posting example data and expected output just in case others might have something meaningful to contribute to the design.

-k
 
Hi,
Create a formula called IsSmith ( for instance):

If LastName = "Smith" then 1 else 0

place this in the detail section of your report ( you can suppress it so it does not display)..Summarize it as a Grand Total( if you want it in the footer)( Right-click on the formula field, insert Grand Total as Sum)

[profile]
 
I did this, and it works, but it does not retain the value. If at the 'if' evaluates to true then it stores the value, but if it evaluates to false in the following record, it resets the value to 0 even knowing that I am not stating an 'else' statement to reset to 0. I had the same problem by using the formula itself without using the variable (that was my first try).

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
numbervar WednesdayCount:= {#DayWorkedTotal};
if DayOfWeek ({table.event.date}) = 4 then
WednesdayCount := {#DayWorkedTotal}//please note that I am not trying to increment the value, just replace it.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Thanks in advance!!!
 
REFRAISING...I did not initialize the variable.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
numbervar WednesdayCount;
if DayOfWeek ({table.event.date}) = 4 then
WednesdayCount := {#DayWorkedTotal}//please note that I am not trying to increment the value, just replace it.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
If you want to display the running total as it is incrementing with the most recent value, then change the formula to:

numbervar WednesdayCount;
if DayOfWeek ({table.event.date}) = 4 then
WednesdayCount := {#DayWorkedTotal} else
WednesdayCount := WednesdayCount;

Otherwise, without making that change, you can create a formula like the following which will display the most recent increment in a group or report footer section, even if the last few records display as zero:

whileprintingrecords;
numbervar WednesdayCount;

-LB
 
TekAtWork, I suspect you've come to Crystal from Mainframe languages, as I did. It has its own design philosophy, which doesn't really include storing data in work-fields for use elsewhere. You can get the same effect using the methods described above.

Other confusing topics are null and left-outer joins. If you've not already figured them, you'd do well to use Search to look them up.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Thanks guys for all the help. This information was very helpful!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top