I was helping a friend with a sub report. He was having a problem with a shared NumberVar resetting itself to zero after the first record in a detail section.

Here basically what he had: (sample data only )

Formula in Main Report header to initialize the variables.
WhilePrintingRecords:
Shared NumberVar hours1:=0;
Shared NumberVar hours2:=0;
Shared NumberVar hours3:=0;

{#recordnum} is a running total in the sub report to find the record the detail section is on at any given time

first Formula In Sub Report Detail Section
WhilePrintingRecords:
Shared NumberVar hours1;
If {#recordnum} =1 then hours1:={table.hours}

Second Formula In Sub Report Detail Section
WhilePrintingRecords:
Shared NumberVar hours2;
If {#recordnum} =2 then hours2:={table.hours}

Record 1 has a value of 100
Record 2 has a value of 134
Results the first time through the detail section

Hours1 = 100
Hours2 = 0

Results the 2nd time through through the detail section
Hours1 = 0
Hours2 = 134

Why did Hours1 get reset to 0???

The work around was:
Shared NumberVar hours1;
If {#recordnum} =1 then hours1:={table.hours} Else hours1:=hours1

This makes no sense to me

Once a shared var has a value it should not be set back to 0 unless it has a condition to do so

AND

Why would the Shared NumVar on the right of the formula have a value to set itself back to if the variable

on the left was now zero

If {#recordnum} =1 then hours1:={table.hours} Else hours1:=hours1

I have never seen this before ever in the 10+ years of Crystal Report work I have done.

Anyone have an answer?

Andy