R – Crystal Reports 8, shared variables and formulas

crystal-reports

Yes, still the same report as in this question and this other question.
Yes, I know, I'm a CR noob 🙂 Anyway, I've browsed Google attentively and lots of tutorials about how to use shared variables popped up, yet I seem unable to grasp its workings because I can't achieve what I need.

These are my formulas:
(ActiveAttSaldo, created in positive assets subreport)
whileprintingrecords;
global numbervar att_saldo;
att_saldo := Sum ({@ImportoEuroConto}, {SP_EstrattoConto.TipoConto})

(PassSaldo, created in negative assets subreport)
whileprintingrecords;
global numbervar pass_saldo := 0;
pass_saldo := Sum ({@ImportoEuroConto}, {SP_EstrattoConto.TipoConto})

(UtileSaldo, created in main report)
whileprintingrecords;
shared numbervar ut2_saldo;
ut2_saldo := {@AttSaldoShared}-{@PassSaldoShared};

if ut2_saldo > 0 then
'UTILE: '+ToText(ut2_saldo)
else if ut2_saldo = 0 then
'Pareggio'
else
'PERDITA: '+ToText(ut2_saldo)

(PassSaldoShared, created in main report)
whileprintingrecords;
global numbervar pass_saldo;
pass_saldo;

(AttSaldoShared, created in main report)
whileprintingrecords;
global numbervar att_saldo;
att_saldo;

The idea is to have a "final balance" but the variables are always 0, so I always see "Pareggio" instead of the correct values. All the formulas are correctly placed:

  • ActiveAttSaldo is placed in group footer 1(active assets subrep) – grouped by "TipoConto"
  • PassSaldo is placed in group footer 1(passive assets subrep) – grouped by TypoConto
  • UtileSaldo, AttSaldoShared and PassSaldoShared are all declared in the same section, which is a group footer 1b(in group footer 1a both subreports are present) grouped by CodiceSocieta(CompanyCode, in English).

To my knowledge, this is supposed to be the correct way to do things(but I may be wrong, that is… :D) and I can't pinpoint the problem.
May you please help me?

Best Regards,

Andrew

Best Answer

Ok, I managed to do it by using 6(SIX) formulas, two on the report's top to declare and initialize variables to 0(zero) two for each sub report to compute the sums and finally two in the main report to actually display the values :-)

Anyway we reworked the report(thanks to one of our SQLServer masters) and now almost all the complexities(sub reps, shared variables) are gone! woooooooo hooooooooooo! :-)

I am, however, flabberghasted at the fact I received no answers whatsoever to any of my questions, some of which remain - however - opened, because I still can't understand for example why, oh why!?!, Crystal would crash or simply vanish without leaving any hint at what may have happened. There's no error log I'm aware of and no apparent sign in the event viewer, nothing that would explain such weirdos.

Thank you all the same for your time,

Andrew

Related Topic