Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

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# THEN

       AMT+=RECORD; DIVBY+=1
    END
 NEXT FLDCNT

END

IF DIVBY#0 THEN ……

Hope this makes sense to you. Email me if you have any queries.

Regards

Ray

[email protected]

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/1c44bdd7728a2f0285256796001b4a2c.txt
  • Last modified: 2024/01/04 21:00
  • by 127.0.0.1