From a solution posted in another recent thread, instead of the
?(A=0,0,1)
construction to sum up the denominator, maybe
Min(1,A) would work and be a little faster.
(A +B+C+D)/(Min(1,A)+Min(1,B)+Min(1,C)+Min(1,D))
I believe the ?(Compare,True,False) construction processes both the True and the False action first, then evaluates the Compare, and hands over the True or the False depending upon the Compare result - at least back in Pan6 days.
I don’t know how “busy” the Min() funcition is.
You could do a CatchError, but it seems to me, more direct and clearer (6 months down the road) if you just check the sum of A+B+C+D first, to make sure it is not zero. You have to add them up anyway.
T’were it me, I’d probably do something like:
Local varsum, varavg,vardenom
varavg = 0
varsum = A+B+C+D
If varesum <> 0
vardenom = (Min(1,A)+Min(1,B)+Min(1,C)+Min(1,D))
varavg = varsum/vardenom
Else
//Your bailout goes here
EndIF
Yes, varsum and vardenom can be replaced by their defining equations, but things always change, though the calculation for the average is constant. I’d “spend” some extra temporary variables so if there’s a change, I just change the summing and not the average calculation. It also gives you a single variable to look at when debugging.
I used to have to fix code in a place were a programmer would pass complicated functions as parameters to subroutines. It worked when it worked. But when it didn’t work, it took a bit of time to break out where, in the series of actions, the problem occurred.
Setting varavg to zero may also be unnecessary, but I like to initialize all my variables.