How to truncate description in Print Report

If you made a template for printing or HTML export, you can offer it to the others here. You can also ask here for help about these templates
Post Reply
alecaf
Posts: 2
Joined: 2012-09-23 09:40:25

How to truncate description in Print Report

Post by alecaf »

Hi all,
I am a new use of AMC and not so expert with scripting so I hope someone will help with my problem.

I am creating a new print report (2-pass report) and since the field [Description] can contain a big text I want to truncate it just to show a preview of the trama...

In the memo field I checked the Script box and in the activated window I put:

Code: Select all

begin
des := [Description];
sht_des := copy([des],1,200)+'...';
end;
Finally in the memo box I put simply [sht_des]

Now, this code runs without errors but for each movie the report shows me just the description of the first movie selected (or the first movie of my db).
Some one can help me to work this issue out?

[/code]
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I do not know why it does not work, maybe Soulsnake will have an idea
There are many bugs in that report component.
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

I will see why this doesn't work when I will have a little time ;).
Can you try with a single pass ?
I think you can truncate automatically the description if you don't set autosize on your description rectangle (right click on rectangle).

Soulsnake.
alecaf
Posts: 2
Joined: 2012-09-23 09:40:25

Post by alecaf »

Hi soulsnake,
Yes, I previously set the field without autosize, and actually it truncated the desctiption...But I am trying understand a way to fix the number of chars and add a '...' string at the end.
It's also a way to understand scripting on AMC...

thank you for the fast reply
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

What you do should work but it doesn't.
The function 'copy' seems to not recognize variables.
I will see to solve this problem.

But for now you can do the same in other manner since AMC 4.X.
You can create a custom field of type Text ('ShortDesc' for example) and run a little script to fill it from original description.

Here is a little script to put the 200 first characters of original description (fieldDescription) into the custom field 'ShortDesc':

Code: Select all

program PutShortDescriptionInCF;
var
  value: string;
begin
  value := GetField(fieldDescription);
  if Length(value) > 200 then
    value := copy(value, 1, 200) + '...';
  SetCustomField('ShortDesc', value);
end.
When custom field 'ShortDesc' is filled, you can use it everywhere in the program: for printing, for html display, for export (csv, html, ...), for scripting, ...

Soulsnake.
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

soulsnake wrote:...You can create a custom field of type Text ('ShortDesc' for example) and run a little script to fill it from original description.
.......
Brilliant, Imaginative!
This can also solve the problem about splitting a data-base field into 2 report fields, isn't it?
:p ;)
viewtopic.php?t=4812
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

Just for information, in last version 4.1.2 beta, you can do the same directly in reports in scripting part.
You can see an example in this template 'KLUZO (FR) landscape 4.frf' in last version 4.1.2 beta.

Soulsnake.
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

:clapping:
.... later.....
which is the field splitted, please?
to see "splitting script" is it sufficient to check 'SCRIPT' on selected field?
:??:
Bunnie
Posts: 5
Joined: 2015-05-20 15:42:00

Post by Bunnie »

Alecaf's script doesn't work because of the used [ ] in the copy-statement
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

:??: that's the syntax of FreeReport's variables
Bunnie
Posts: 5
Joined: 2015-05-20 15:42:00

Post by Bunnie »

being new with these scripts I found out that statements like

field1 := [field1] + blabla

results in an error when [field1] was used in the textbox of a report

changing it to

field1 := field1 + blabla

solved the error plus the statement worked
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

For user-declared variables, indeed the [ ] are probably too much, these are for pre-defined variables if I remember well.
By the way, your e-mail account is sending replies automatically (acknowledges), so when the forum sends you a notification e-mail of a new message on a thread I get several automatic e-mails from you...
Bunnie
Posts: 5
Joined: 2015-05-20 15:42:00

Post by Bunnie »

I'm still tuning. It should have stopped already.
Post Reply