1 (edited by samtorn 2024-04-01 09:36:25)

Topic: Report items change

Dears
I get the days of the week as numbers in a table, can I change them in the report designer to the names of the days and how ?"


Thanks again

Post's attachments

Attachment icon Lao.zip 336.06 kb, 22 downloads since 2024-04-01 

Re: Report items change

Allega il progetto per poterti aiutare meglio!

Domebil

3 (edited by samtorn 2024-04-01 09:35:41)

Re: Report items change

Here is the example: there are (days of  week ) represented as numbers, and I want to display them as the names of the days in the report

Post's attachments

Attachment icon Lao.zip 336.06 kb, 25 downloads since 2024-04-01 

4 (edited by sparrow 2024-04-01 11:48:24)

Re: Report items change

You can use a calculated field like

CASE <FIELD Name> 
WHEN 0 THEN 'Sunday' 
WHEN 1 THEN 'Monday' 
WHEN 2 THEN 'Tuesday' 
WHEN 3 THEN 'Wednesday' 
WHEN 4 THEN 'Thursday' 
WHEN 5 THEN 'Friday'
WHEN 6 THEN 'Saturday' END

or in the FastReport script like

begin
   case <variable name> of
      1: Form1.Edit1.Text := 'Sunday';
      2: Form1.Edit1.Text := 'Monday';
      3: Form1.Edit1.Text := 'Tuesday';
      4: Form1.Edit1.Text := 'Wednesday';
      5: Form1.Edit1.Text := 'Thursday';
      6: Form1.Edit1.Text := 'Friday';
      7: Form1.Edit1.Text := 'Saturday';
   end;
end;

In addition, Pascal and SQLite have their own functions for determining the day of the week (day number) by date.
DayOfWeek()
And
strftime('%w', ...).

5 (edited by samtorn 2024-04-02 09:29:30)

Re: Report items change

thanks

but the numbers in the table already

the Fast report code never worked with me , can someone explain how to me ???? or modify the sample that I have add  pleaseeeee ?

i want to know why it never worked for my

Re: Report items change

Hi Samtom, Hi Sparrow,
Personally, I would probably use a calculated field as suggested by Sparrow.
However, if you are not yet familiar with how to create a calculated field, another option is to hold the days of the week in a look-up table (see attached).
You also need to be careful viewing and creating records on the same form (Form1);  it is very easy to inadvertently create duplicate records if you have not added a bit of 'script' to prevent this.
Derek.

Post's attachments

Attachment icon Lastooo 1.zip 337.55 kb, 37 downloads since 2024-04-02 

7 (edited by samtorn 2024-04-02 14:15:44)

Re: Report items change

Thank you very much, dear Derek. You are always our savior



I have another question: Do you have an example of changing data in FastReport? I've tried this many times but always encounter errors. I want to understand the mechanism, and if you also have an example of a calculated field, that would be great. smile))) 

Re: Report items change

To use a calculated field:
1  create a new field in your table with a field type of 'calculated field'
2. add the code (exactly as already detailed by Sparrow)
3. display the calculated field in the tablegrid (optional)
4. add the calculated field to the field selections in the 'report' action.
5. the calculated field can be referenced in 'FastReport' like any other field type.
Have a look at the attachment and the included screen shot.
Derek.

Post's attachments

Attachment icon Lastooo 2.zip 377.53 kb, 25 downloads since 2024-04-03 

Re: Report items change

To add the 'day of the week' as text in FastReport directly, you could
1.  add a memo field and place it on the report layout  (see the screenshot in the attachment).
2.  create a 'before print' event for the Master Data band (see the screenshot in the attachment)
3.  insert the code that Sparrow gave you in a previous post or use the code already there (see attachment).
There may be other (better) ways to do this - I don't use FastReport very much so I'm probably not the best person to ask.
Derek.

Post's attachments

Attachment icon Lastooo 3.zip 391.41 kb, 25 downloads since 2024-04-03 

10 (edited by sparrow 2024-04-03 20:50:16)

Re: Report items change

Hi Derek,
Thank you.


samtorn, for self-study.
Option for FastReport. Directly for the Memo field on the form.
Create Memo2 next to Memo1 in Derek's example and place the code below.
It looks scary but it's simple.

[IIF(<Report."Employer_Hours.dayofweek">=1,'Mon',
IIF(<Report."Employer_Hours.dayofweek">=2,'Tue',
IIF(<Report."Employer_Hours.dayofweek">=3,'Wed',
IIF(<Report."Employer_Hours.dayofweek">=4,'Thu',
IIF(<Report."Employer_Hours.dayofweek">=5,'Fri',
IIF(<Report."Employer_Hours.dayofweek">=6,'Sat',
'Sun'))))))]

OR

[SQLExecute('SELECT CASE '''+<Report."Employer_Hours.dayofweek">+'''*1 WHEN 1 THEN ''Monday'' END ')]

And a link to the manual to make it work: https://www.fast-report.com/public_down … ual-en.pdf