Divide A Total By The Number Of Fields NE '' (AREV Specific)
At 20 JUN 1999 12:58:04AM Donna wrote:
I'm in need of an idea please. I have seven individual fields that may or may NOT contain a number. My object is to total the seven fields and then divide the total by the number of fields that are not blank.
The divisor number could be anywhere between 1 and 7 depending on how many fields have a number in them.
How in the heck can I come up with the number to divide by?
TIA
At 20 JUN 1999 03:16AM Steve Smith wrote:
* there are a few ways, but this should suffice
function addstuff * assume your fields to total are 5 7 9 12 13 divisor=0 total=0 if @record "" then divisor += 1 total=total + @record end if @record "" then divisor += 1 total=total + @record end if @record "" then divisor += 1 total=total + @record end if @record "" then divisor += 1 total=total + @record end if @record "" then divisor += 1 total=total + @record end if divisor then result=total / divisor end else result=0 end return result
At 23 JUN 1999 09:25AM Raymond S Blackwell wrote:
Donna, an efficient way to perform the function you need is to set up a control item with the relevant fields that you want to process and then use this as your controlling item. The added advantages are that you can add or subtract fields from the control record and the process will still work without having to change the code. A sample routine would be:
CONTROL RECORD CONTAINS 'X' ATTRIBUTES WITH FIELD NUMBERS
RECORD CONTAINS RELEVANT FIELDS
READ CONTROL FROM ….. OR XLATE(…….
AMT=0; DIVBY=0
IF CONTROL#
THEN FLDCNT=COUNT(CONTROL,@FM)+1 FOR LP=1 TO FLDCNT ATTR=CONTROL IF RECORD#
THENAMT+=RECORD; DIVBY+=1ENDNEXT FLDCNTEND
IF DIVBY#0 THEN ……
Hope this makes sense to you. Email me if you have any queries.
Regards
Ray