On Jan 27, 2007, at 9:00 PM, Russ Jones wrote:

IMHO, code that can be read clearly by humans is a lot more valuable than correct but unclear code. The real payoff comes in the later maintenance of the code, especially if it ever gets to be maintained by others. Harrie's response is in keeping with this ethic, and should be treated with a lot more respect than some of the multi-line statements seen in this thread.

But that's just my rant.  :-)

Russ

Rant away
I'll agree that long strings of (min(min(min(min aren't exactly friendly
I've just read thousands of them in my life supporting accountants and massive Excel spreadsheets

Special values like
theMin = 999999999 // assuming your numbers will always be less than this theMax = -999999999 // assuming your numbers will always be more than this
assume fringe cases will never be encountered

Better to flag when things have been set
If you're going to process things specially for an average you should do so as well for the min and max in the event all edit fields are empty

theMinSet  =false
theMaxSet = false
theAvg = 0
numVals = 0
For i = 0 to 10
  // a good program would verify that each editfield contains a valid
  // number, and, if it is valid to leave one or more empty then only
  // process the non-empty editfields
  if efDays(i) <> "" then // ignore blank editfields
    numVals = numVals + 1
    thisVal = val(efDays(i))
    if theMinSet = false then
        theMin = thisVal
        theMinSet = true
    end if
    if theMaxSet = false then
        theMax = thisVal
        theMaxSet = true
    end if

    theAvg = theAvg + thisVal
    if thisVal < theMin then theMin = thisVal
    if thisVal > theMax then theMax = thisVal
  end if
next i

if numVals > 0 then theAvg = theAvg/numVals

if theMinSet = true then
   efMin.text = str(theMin)
end if
if theMaxSet = true then
   efMax.text = str(theMax)
end if

efAvg.text = str(theAvg)

Results.Text = "The minimum is “ + efMin.text + “ days and the maximum is “ _
    + efMax.text + “ days, with an average of " + efAvg.text + " 
days."_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to