Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Problem with global variables Post Reply Post New Topic
Page  of 2 Next >>
Author Message
majki
Newbie
Newbie
Avatar

Joined: 22 Dec 2009
Location: Poland
Online Status: Offline
Posts: 13
Quote majki Replybullet Topic: Problem with global variables
     Posted: 22 Dec 2009 at 4:27am
Hi,

I have following problem. If I use any statement using database fields, global variables don't seem to work properly.

For example - when I have two formulas in report:
Formula a (within Formula field A):

global stringvar a:="Nothing special ";
local stringvar d:="";
a:=a+"x";

Formula b (within Formula field B):

global stringvar a;
a;

As a result of it, when I display Formula field 'B' on a report, everything is ok, I get 'Nothing special x' text, however if I would add in first formula anything with database field, it doesn't work anymore.
For example - if I would modify above Formula a like this:
Formula a (within Formula field A):

global stringvar a:="Nothing special ";
local stringvar d:="";
if({Command.field_1}<>"") then d:="nothing important for example";
a:=a+"x";

then Formula field B shows... nothing.. This is crazy. The only difference is that I put if statement, comparing data from db with a string, and please notice, that it has also nothing to do with global variable a!

I don't get it ;/

Any help be appreciated.

Mikolaj

I use Crystal Reports XI


Edited by majki - 22 Dec 2009 at 4:28am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 22 Dec 2009 at 6:24am
what if Command.field_1 is null?  DBlank is constantly reminding us of this issue. If the field is null, the CR will exit the formula, basically with an error message, but it doesn't display it.
 
you might try:
if (not isnull(Command.field_1) or Command.field_1<>"") then d:="xx";
 
Also, as a reminder, again from DBlank experience, check for the null value first, reversing the arguments in the OR statement will probably get you back to where you are now.
 
I used formulas with data fields ALL the time, so I would expect that this is a data issue.
 
HTH
IP IP Logged
majki
Newbie
Newbie
Avatar

Joined: 22 Dec 2009
Location: Poland
Online Status: Offline
Posts: 13
Quote majki Replybullet Posted: 22 Dec 2009 at 6:46am
I tried both - checking if this field is null and also just to use Command.field_1 as argument for 'is null' funcion and also using the column {Command.id} which is by default not null (as a key in db). Still nothing.

What is also weird - it worked fine for few tries (even before i made any change! I just came back to Crystal reports), after that it asked me to re-connect to db - after that - it's again lost.

I'm confused.
IP IP Logged
majki
Newbie
Newbie
Avatar

Joined: 22 Dec 2009
Location: Poland
Online Status: Offline
Posts: 13
Quote majki Replybullet Posted: 22 Dec 2009 at 7:55am
It looks like this right now. Two formula fields:

akt:
stringvar gA:= "";

local stringvar lB:="";

if not(isnull({Command.d_id})) then gA:="tr";
gA;

zzz:
stringvar gA;

gA:=gA;
gA;


on report @akt is displaying 'tr', @zzz is not displaying anything.

Even changing '@akt' like this:
akt:
stringvar gA:="tr";

local stringvar lB:="";

if not(isnull({Command.d_id})) then lB:="t";
gA;

gives the same result (i put gA; at the end of this formula on purpose, to show that formula doesn't end on 'if' line).

Deleting '   if not(isnull({Command.d_id})) then lB:="t";  ' make it works properly.

Help..... :)

Edit: Additionally - field Command.d_id is never empty (it contains primary key of this table)



Edited by majki - 22 Dec 2009 at 7:58am
IP IP Logged
majki
Newbie
Newbie
Avatar

Joined: 22 Dec 2009
Location: Poland
Online Status: Offline
Posts: 13
Quote majki Replybullet Posted: 04 Jan 2010 at 12:22am
Anyone? Problem still exists :(
IP IP Logged
majki
Newbie
Newbie
Avatar

Joined: 22 Dec 2009
Location: Poland
Online Status: Offline
Posts: 13
Quote majki Replybullet Posted: 06 Jan 2010 at 1:08am
I've solved the problem. Maybe not solved, but I would say that I found workaround that works.

Instead of:
zzz:
stringvar gA;

gA;

I put:
zzz:
stringvar gA;
if not(isnull({Command.d_id})) then 1=1; //doesn't do anything
gA;

and you know what? It works... It just needed a statement with field from DB - no idea why.

IP IP Logged
majki
Newbie
Newbie
Avatar

Joined: 22 Dec 2009
Location: Poland
Online Status: Offline
Posts: 13
Quote majki Replybullet Posted: 01 Feb 2010 at 6:32am
Update - Now i know why it needed this line - it's about the time when it's being calculated.

Instead of what i've written, we can write (and actually it is much more obvious) like this:

zzz:
EvaluateAfter({@akt});
stringvar gA;
gA;



Probably when i put a line with 'command.d_id' field from db, it had to wait till records were read. Here, we just tell CR to run this formula AFTER the one in which global variable gets proper value.


For new guys in Crystal Reports (as I am) reading this - read some information about EvaluateAfter(), WhilePrintingRecords, WhileReadingRecords and BeforeReadingRecords.

All of them accessible in standard CR help (F1) under 'Evaluation Time'.
This is core and knowing this will help you a lot.

Best regards,
Mikolaj
IP IP Logged
charlese
Newbie
Newbie


Joined: 21 Apr 2011
Online Status: Offline
Posts: 33
Quote charlese Replybullet Posted: 03 Jun 2011 at 1:44am
Hi everybody,

I have got a formula, a1, which I have put in my group footer which basically read a value from the table and put it into a shared variable, as shown below

Shared StringVar SC_CkNum := "" ;
SC_CkNum := {SuperCheck.CkNum}

What I need to do is to pass the value of this variable to to the page footer. So in my page footer I have created another formula @Reada1, which reads

Shared StringVar SC_CkNum ;
SC_CkNum;

The problem I am having is if the value of SC_CkNum in the group footer is 41234, the @Reada1 formula in the page footer is reading correctly 41234. However if its next value is blank, the @Reada1 formula is still holding on to the old value i.e 41234 and not displaying blank.

Can someone please help me
[IMG]smileys/smiley19.gif" align="middle" />

Edited by charlese - 03 Jun 2011 at 1:50am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 03 Jun 2011 at 3:12am
reset your a1 to 0 in the group header...If the record is blank, there is no value to update a1, so it stays the same.
 
HTH
IP IP Logged
charlese
Newbie
Newbie


Joined: 21 Apr 2011
Online Status: Offline
Posts: 33
Quote charlese Replybullet Posted: 03 Jun 2011 at 3:55am
I have got a subreport in my group header, do I need to do the reset inside the subreport ?
IP IP Logged
Page  of 2 Next >>
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum