# Shared NumbVar Resets itself in sub ReportRSS

## 2 replies

Last post Mar 20, 2013 07:30 AM by Ruthless23

• Ruthless23

Member

74 Points

271 Posts

### Shared NumbVar Resets itself in sub Report

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.

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

Hours1 = 100

Hours2 = 0

Results the 2nd time through

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 ahve done.

Anyone have an anwser?

Andy

• Ajay2707

Contributor

6622 Points

1742 Posts

### Re: Shared NumbVar Resets itself in sub Report

Hi Friend,

You are right, shared variable never reset  still we are not reassing zero. its global variable or we can say static global variable.

```Shared NumberVar hours1;

If {#recordnum} =1 then Hours1:={table.hours}```

Please change Hours1 to hours1 first.

• Ruthless23

Member

74 Points

271 Posts