Loading ...
Sorry, an error occurred while loading the content.

19846Re: [Clip] Finding Minimum Value in Array

Expand Messages
  • Don - HtmlFixIt.com
    Nov 2, 2009
    • 0 Attachment
      I am pretty sure you are just picking lucky numbers to use and thus
      getting lucky :-)

      I agree that you need the line breaks as delimiter because we are
      sorting lines, not data elements. But it will not do what you wanted,
      give the minimum unless you zero pad. You can however add zero padding,
      sort, strip and output if you wish.

      I mistakenly did not include the correct numbers in my prior example.

      :Mine
      ^!SetListDelimiter ,
      ^!SetArray %Array%=8,329,7,4,9,6,5
      ^!SetListDelimiter ^%NL%
      ^!SetArray
      %Array%=^$StrSort("^$StrReplace(",";"^%NL%";"^%Array%";0;0)$";False;True;False)$
      ^!Info ^%Array1% ^%NL% ^%Array%


      :Flo
      ^!SetListDelimiter ^%NL%
      ^!SetArray %Array%=8^%NL%329^%NL%7^%NL%4^%NL%9^%NL%6^%NL%5
      ^!Info Array unsorted:^P^%Array%
      ^!SetArray %Array%=^$StrSort("^%Array%";0;1;0)$
      ^!Info Array correctly sorted:^P^%Array%
      ^!Info Minimum value: ^%Array1%

      Notice I also used NL in my example because we figured that one out many
      years ago -- look up my username and zero padding ....

      329 comes out on top in the above examples because 3 is the lowest
      number. Hugo and I have done the zero padding bit many times over the
      years as I use his method for it.

      flo.gehrke wrote:
      > --- In ntb-clips@yahoogroups.com, Hugo Paulissen <hugopaulissen@...> wrote:
      >> OK Don, Sorry Flo,
      >>
      >> Forget my last post; I see what you mean... Now I *do* remember the padding zero issue! It's getting rusty inside...
      >>
      >> Hugo
      >
      > Hugo, Don,
      >
      > I don't think that Hugo was wrong. There has always been some confusion about this issue (cf message #19038 ff).
      >
      > The trick is the ^%NL% as delimiter. With the semicolon as the default delimiter the array won't get sorted:
    • Show all 15 messages in this topic