Global variable in crystal reports

14,428

You're never assigning your variables any values. ":=" is the assignment operator, not "=". Also, to be on the safe side, the footer formula should have WhilePrintingRecords; at the top.

Share:
14,428

Related videos on Youtube

pluke
Author by

pluke

reformed software developer turned teacher

Updated on June 04, 2022

Comments

  • pluke
    pluke almost 2 years

    I'm trying to keep a running total of teachers, support staff and managers in crystal reports, I've decided to do this using global variables, I know it'd be possible in other ways but I want to give global variables a go.

        WhileReadingRecords;
    Global NumberVar TotalSManagement;
    Global NumberVar TotalSTeachers;
    Global NumberVar TotalSSupport;
    Global NumberVar TotalLManagement;
    Global NumberVar TotalLTeachers;
    Global NumberVar TotalLSupport;
    
    if{staff_addresses_txt.Staff category} = "MANA" and {staff_addresses_txt.Name} = "CTK:Lewisham" then
        TotalLManagement = TotalLManagement + 1
    else
    if{staff_addresses_txt.Staff category} = "TEAC" and {staff_addresses_txt.Name} = "CTK:Lewisham" then
        TotalLTeachers = TotalLTeachers + 1
    else
    if{staff_addresses_txt.Staff category} = "SUPP" and {staff_addresses_txt.Name} = "CTK:Lewisham" then
        TotalLSupport = TotalLSupport + 1
    else
    if{staff_addresses_txt.Staff category} = "MANA" and {staff_addresses_txt.Name} = "CTK:St Mary's" then
        TotalSManagement = TotalSManagement + 1
    else
    if{staff_addresses_txt.Staff category} = "TEAC" and {staff_addresses_txt.Name} = "CTK:St Mary's" then
        TotalSTeachers = TotalSTeachers + 1
    else
    if{staff_addresses_txt.Staff category} = "SUPP" and {staff_addresses_txt.Name} = "CTK:St Mary's" then
        TotalLSupport = TotalLSupport + 1;
    

    The if statements are definitely firing, but when I come to display the totals at the bottom of the page using the following code, everything is 0.00:

    Global NumberVar TotalSManagement;
    Global NumberVar TotalSTeachers;
    Global NumberVar TotalSSupport;
    Global NumberVar TotalLManagement;
    Global NumberVar TotalLTeachers;
    Global NumberVar TotalLSupport;
    
    if {staff_addresses_txt.Name} = "CTK:Lewisham" then
     "[Lewisham] Managers: " & TotalLManagement & " | Teachers: " & TotalLTeachers & " | Support: " & TotalLSupport
    else
     "[Sidcup] Managers: " & TotalSManagement & " | Teachers: " & TotalSTeachers & " | Support: " & TotalSSupport
    

    Producing this: [Lewisham] Managers: 0.00 | Teachers: 0.00 | Support: 0.00

    Am I using global variables incorrectly? I have tried initialising them with other numbers, but the response is always the same. Any ideas?

  • pluke
    pluke over 12 years
    blimey that was pretty naive. I should work through some tutorials. Thanks!