Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on 

Problem using variables in Crystal Report 10???

I am trying to use variables in Crystal Reports. I've never done this before...so I'm not exactly sure where to declare them. I have a field on a report in which I wish to create a formula for. The value(s) this field can contain are either "No", "Yes", or "Skip". These values are based on values of other fields in the report. So, how exaclty would I set up a field/formula for this field?

Thanks,
Blake
Visual Basic.NET

Avatar of undefined
Last Comment
Mike McCracken
Avatar of Mike McCracken
Mike McCracken

Build  formula and place it on the report where you want the field.

The formula will be something like

If (Conditions for NO) then
  "No"
else if (conditions for YES) then
  "Yes"
else
  "Skip"

I don't see any need to use variables.  Variables are used when you need to retain a value for use later in the report.

mlmcc
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Well, what I'm doing is trying to declare global boolean variables. I have 3 other formulas in which I check certain report field values. If the values aren't what they should be....I'll set a boolean variable to False else True. I'll do that for each formula. Then in another field (which is just a textbox heading), I'll create another formula that will check these boolean variables and then set the value of "No", "Yes", or "Skip" accordingly.
In the report header add a formula
Name - DeclVars
Formula
WhilePrintingRecords;
Global BooleanVar Test1 := True;
Global BooleanVar Test2 := True;
Global BooleanVar Test3 := True;

In formulas where you want to use one of them say Test1
Add these lines
WhilePrintingRecords;
Global BooleanVar Test1;

mlmcc
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

I don't understand how this will work. It looks like your declaring the same boolean variable twice which would cancel any set values for that variable. Also, are you calling the Formula: "WhilePrintingRecords"?
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Also, how do I add a formula to a Report Heading Section?
>>how do I add a formula to a Report Heading Section
Create the formula and drag it to the report header section.

You are correct it appears that you are declaring them twice but Crystal doesn't look at it that way.  By declaring it global Crystal first looks to see if a variable exists that is also global then uses that one.

WhilePrintingRecords; is used to tell Crystal when to execute the formula.  Crystal builds the report in 4 passes with the printing pass beingthe last pass.  If you don't include that then the formula may execute early and you won't see the correct results for the data.  You end up getting the last value set for all the records in the report rather than the one you wanted.

mlmcc
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Now the formula isn't working. The following code should take the Else branch and  {tblBatchDetail.prodCode} does have a value in it but it's not showing on the report.

WhilePrintingRecords;

Global BooleanVar blnProductXref;

if {tblProducts.AdventProductCD} > "" then
    (
        blnProductXref := true;
        {tblBatchDetail.prodCode} & "/(" & {tblProducts.AdventProductCD} & ")"
    )
else
    (
        blnProductXref := false;
        {tblBatchDetail.prodCode} & "/(Unk)"
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Sorry, the above post does have the very last parenthesis.

WhilePrintingRecords;

Global BooleanVar blnProductXref;

if {tblProducts.AdventProductCD} > "" then
    (
        blnProductXref := true;
        {tblBatchDetail.prodCode} & "/(" & {tblProducts.AdventProductCD} & ")"
    )
else
    (
        blnProductXref := false;
        {tblBatchDetail.prodCode} & "/(Unk)"
    )
What is displaying on the report?

mlmcc
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Nothing is displaying on the report for this Formula. The very least that should be displaying is

        {tblBatchDetail.prodCode} & "/(Unk)"

Because tblBatchDetail.prodCode has data in it.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo