Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: tshumak on December 10, 2013, 09:42:47 am

Title: Scripts
Post by: tshumak on December 10, 2013, 09:42:47 am
I'm trying to get this script to run, but LazReport is not creating the variables.  I saw in a prior post that running a script in a masterdata band will create variables however only the first variable is created. I tried shifting the statements around, but again only the first is created.

Am I missing something. not doing something right?  What is the correct way I can make this script create all the variables?

Code: [Select]
BMONTH:=MONTHOF([SysParm."UPDATE_DATE"]);
BILLYEAR:=STR(YEAROF([SysParm."UPDATE_DATE"]))+'-'+STR(BMONTH);

DLQ :=0.0;
CDUE:=0.0;
PMT:=0.0;

LATE_FEE:=0;

NONMEMBER:=Pos('N',[Lot_ID."Flags"]);
GOLDEN:=Pos('G',[Lot_ID."Flags"]);
LIENED:=Pos('L',[Lot_ID."Flags"]);

AD1:=[Names."LNAME_CO"]+', '+[Names."FNAME"];
if [LENGTH([Names."CARE_OF"])]>0 then
Begin
  AD2:=[Names."CARE_OF"]
  AD3:=[Addr."ADDRESS"];
  AD4:=[Addr."CITY"]+', '+ [Addr."STATE"]+' '+ [Addr."ZIP"]];
  if not  [COMPARESTR([Addr."COUNTRY"], ['USA'])=0] then
  begin
    AD5:=[Addr."COUNTRY"]
  end
  else
  begin
    AD5:='';
  end;
end else begin
  AD2:=[Addr."ADDRESS"];
  AD3:=[Addr."CITY"]+', '+ [Addr."STATE"]+' '+ [Addr."ZIP"]];
  if not  [COMPARESTR([Addr."COUNTRY"], ['USA'])=0] then
  begin
    AD4:=[Addr."COUNTRY"]
  end
  else
  begin
    AD4:='';
  end;
  AD5:='';
end;


MSG1:='.                              Highway Lot - NO PAYMENT REQUIRED';
MSG2:='Your Property has been Liened because of non-payment of Fees';
MSG3:='.           Fee Required to File the Lien Release - $'+FORMATFLOAT([#0.00], [SysParam."Lien_R_Fee"]);
MSG4:='.                Your Balance is Zero - NO PAYMENT RTEQUIRED';
MSG5:='.                         ***  Your Account is Past Due  ***';

MSGL1:='***  A 12% Late Fee will be charged if not paid by the due date  ***';
MSGL2:='***  A 12% Late Fee has been added to the DUE amount above  ***';

Thanks.
Title: Re: Scripts
Post by: tshumak on December 11, 2013, 08:30:32 am
60 views and no reply's yet? 

Maybe they don't understand my post.  What I would like to do is to create variables inside of Lazreport like this thread suggests. http://forum.lazarus.freepascal.org/index.php/topic,17190.msg94901.html#msg94901 (http://forum.lazarus.freepascal.org/index.php/topic,17190.msg94901.html#msg94901)  Here it runs a small script inside the MasterData band.  Click Preview.  then check the variables list and there supposed to be created.  With my script, only the first variable is created.  when I shuffle the statements around, still only the first statement that assigns a value to a variable, only that variable is created.  No other variables are created. 

I would like to have the script create all the variables.  Is this a limitation to LazReport?  Does it only create one variable per script? Or am I doing something wrong?

Thanks for the views and reply's.
Title: Re: Scripts
Post by: BigChimp on December 11, 2013, 09:22:21 am
Maybe you didn't give enough information to let people help you easily. Laz version, FPC version, operating system, compilable sample project...

See first link in my signature...

I'm not a Lazreport user, but your problem description was very clear to me though ;)
Title: Re: Scripts
Post by: tshumak on December 11, 2013, 09:36:13 am
Sorry, I dont mean to be sarcastic here, I was just commenting on the number of views and no posts.  Perhaps they dont know which is why their here looking for answers themselves such as I.

 Anyway, I tried to clarify things with my second post.  Sample code in in my first.  Lazarus version 1.1, FPC 2.7.1, Win7-64.  Big Chimp, This is the version you suggested to me in another post.  If this is not current, I could update.  Any way do you have any suggestions for my coding?

Thanks again.
Title: Re: Scripts
Post by: BigChimp on December 11, 2013, 12:28:46 pm
No problem with any sarcasm - you did explain your problems quite well and that's the main thing ;)

Sample code in in my first. 
Sorry to be pedantic: yes there is sample code in the first post. No, there is no project you can run that includes sample data, report definition etc. However, it's of course your choice how much effort you want to invest into posting questions. I myself tend to favour ready made example projects in order to exclude as much uncertainty as possible (and if needed, serve as possible bug report test cases) but a lot of questions have less and do get answered.

Lazarus version 1.1, FPC 2.7.1, Win7-64.  Big Chimp, This is the version you suggested to me in another post. 
If this is not current, I could update. 
Could be depending on what you wrote in that other post. Normally I'd probably recommend using stable FPC with either latest SVN/dev Lazarus or latest stable Lazarus.
IIRC, 1.1 is an SVN version, right? Meanwhile Laz svn is at 1.3; you could try updating your Laz version..

Any way do you have any suggestions for my coding?
No, sorry, haven't used Lazreport in anger, really. I'd make sure you have the latest Laz+Lazreport as Lazreport does get quite some fixes.
Title: Re: Scripts
Post by: ttomas on December 11, 2013, 03:28:26 pm
Put your script in begin end; block

Code: [Select]
begin
  // Your script code here
end;
Title: Re: Scripts
Post by: tshumak on December 12, 2013, 08:18:28 am
I dont remember the thead as to why i went with The svn.  I think it might have been something about installing.  You know your probably right.  In my line of work, I'm always one to push for updates,  update windows, office, java, flash, etc. I don't think it will help but that svn had a lot of new cool stuff.  I'll try the latest svn and see what happens.

Ttomas-  I'll try the begin - end statements and write back.  Thanks.
Title: Re: Scripts
Post by: tshumak on December 12, 2013, 08:55:33 am
Hey TTomas -

You the one!  That seems to have worked.  Thanks again.
Title: Re: Scripts
Post by: tshumak on December 13, 2013, 07:38:57 am
Well for the most part it worked.  Up until the if block.  Too bad there's no way to step through the code.
Title: Re: Scripts
Post by: tshumak on December 29, 2013, 09:23:32 pm
I've worked with this for a while now and I'm finding that the interpreter seems to want semi-colons after 'each' line and does not like nested IF statements.

For example:
Code: [Select]
if [[PAY]>0] then begin
if[[LATE_FEE]=1] then Text:=[MSGL2];
else Text:= [MSGL1];
end;

Does not compile.  However if I remove the outer if statement:

Code: [Select]
if[[LATE_FEE]=1] then Text:=[MSGL2];
else Text:= [MSGL1];

Does run.
Title: Re: Scripts
Post by: BigChimp on December 30, 2013, 11:24:29 am
@tshumak: thanks a lot for your digging. Would you mind checking my takeway from this post
http://wiki.lazarus.freepascal.org/LazReport_Documentation#Script

Of course, additions and corrections in other parts welcome, too ;)
Title: Re: Scripts
Post by: tshumak on December 31, 2013, 09:05:32 am
Thanks for the reply.  tried the link but it does not open.  Were having some heavy rain and lightning storms over here, might be related.  I'll try checking again later.
Title: Re: Scripts
Post by: BigChimp on December 31, 2013, 09:49:03 am
Don't think the problem is at your end, I have the same... and:
http://www.downforeveryoneorjustme.com/www.http://wiki.lazarus.freepascal.org/
shows it's down
Title: Re: Scripts
Post by: adilsonpazzini on July 26, 2018, 10:58:45 pm
LazReport Script...

Is it possible to concatenate the result of the Text property?


IF [VEIM11NEF.QRel."VR_AVISTA"]>0 THEN
 TEXT:= ' V_V';

IF [VEIM11NEF.QRel."VR_USADO"] = 0 THEN
 TEXT := TEXT + ' S_U'
ELSE
 TEXT := TEXT + ' C_U';
Title: Re: Scripts
Post by: adilsonpazzini on July 26, 2018, 11:08:15 pm
BEGIN
X:='';
IF [VEIM11NEF.QRel."VR_AVISTA"]>0 THEN
I managed using Variavel.

thank

 X:= ' V_V';

IF [VEIM11NEF.QRel."VR_USADO"] = 0 THEN
 X := X + ' S_U'+ [VEIM11NEF.QRel."VR_USADO"]
ELSE
 X := X + ' C_U'+ [VEIM11NEF.QRel."VR_USADO"];

TEXT := X;

END;
                                                 
Title: Re: Scripts
Post by: adilsonpazzini on August 09, 2018, 04:09:00 pm
Reading the link http://wiki.freepascal.org/LazReport_Documentation#Script  in part Logical/boolean functions

IF(<X>, <Y>, <Z>)
    Returns < Y > if expression < X > is true. If false, returns < Z >.

I need to do something like this IF(["TABLE".FIELDVALUE1>0,"TABLE".FIELDVALUE,0]) .

Has anyone ever had to do something like this?

Thanks in advance .

Adilson
Title: Re: Scripts
Post by: korba812 on August 09, 2018, 04:39:59 pm
You should use parentheses:
IF([["TABLE".FIELDVALUE1]>0,["TABLE".FIELDVALUE],0])
(my mistake)

IF(["TABLE".FIELDVALUE1]>0,["TABLE".FIELDVALUE],0)
Title: Re: Scripts
Post by: adilsonpazzini on August 09, 2018, 06:47:59 pm
I tried even harder not to. Am I doing something wrong?

Thanks for the feedback .
Title: Re: Scripts
Post by: korba812 on August 09, 2018, 08:39:53 pm
whole statement also must be in parentheses:
[IF(["TABLE".FIELDVALUE1]>0,["TABLE".FIELDVALUE],0)]
Title: Re: Scripts
Post by: adilsonpazzini on August 09, 2018, 08:57:14 pm
worked thank you very much

Adilson Pazzini
Title: Re: Scripts
Post by: lainz on December 28, 2020, 04:19:10 pm
Hi, I know this is an old thread, but is linked in the Wiki, and the Wiki code seems that doesn't work anymore.

https://wiki.freepascal.org/LazReport_Documentation#Script

This script:

Code: Pascal  [Select][+][-]
  1. if[[LATE_FEE]=1] then Text:=[MSGL2];
  2. else Text:= [MSGL1];

Doesn't works.

But this works:

Code: Pascal  [Select][+][-]
  1. if[[LATE_FEE]=1] then Text:=[MSGL2]
  2. else Text:= [MSGL1];

The first line semicolon was removed in order to work, at least in recent trunk.

I know I can edit the wiki, but I'm asking if someone else can reproduce what I did to see if it works like that on a current release of Lazarus, since I'm using only trunk.

Thanks.
Title: Re: Scripts
Post by: Thaddy on December 28, 2020, 04:33:40 pm
If you are using only trunk please also give the revision you are using, because trunk is a moving target.
Such things can be caused at any given moment and also can disappear at any given moment.
If it is in the latest trunk I suggest a bug report, but people often have "a version of trunk" and you can only sanely report against the latest.
Title: Re: Scripts
Post by: MarkMLl on December 28, 2020, 04:35:13 pm
If you are using only trunk please also give the revision you are using, because trunk is a moving target.
Such things can be caused at any given moment and also can disappear at any given moment.

Noting post #9 but I think the variant with the semicolon before the else is a typo and the wiki should be corrected.

MarkMLl
Title: Re: Scripts
Post by: Thaddy on December 28, 2020, 04:36:15 pm
I think the same, now I looked at the wiki.
TinyPortal © 2005-2018