- I typically zero pad on the way in, something like:

;long line follows -- just a random line so variables aren't useful

^!InsertText

^$StrFill("0";^$Calc(^%numberlength%-^$StrSize("^%place%")$)$)$^%place%.

of course we aren't inserting test this time, we are changing the length

of variables

where numberlength is the length of your longest number in the set and

place is the current number

and then ...

^!Set %numbers%=003;008;329;001;001.25;007;010.34;004;009;006;002;005;011

^!SetArray %numbers_ordered%=^$StrReplace(";";"^P";"^%numbers%";0;0)$

^!SetArray %numbers_ordered%=^$StrSort("^%numbers_ordered%";0;1;0)$

^!SetArray

%numbers_ordered%=^$StrReplace("^P";";";"^%numbers_ordered%";0;0)$

;long line follows

^!InsertText The lowest number in this set: ^%numbers%^%NL%is

^%numbers_ordered1%^%NL%and sorted list: ^%numbers_ordered%

flo.gehrke wrote:> Hi all,

>

> What's the best way to find the minimum value in an array of numbers?

>

> For example, in: 3,8,329,1,1.25,7,10.34,4,9,6,2,5,11.

>

> To do it with commands like 'If A > B' etc seems to be a complicated undertaking. Also the MIN or MAX operators to be used with ^$Calc$ are not very useful. As far as I can see, they compare two numbers only:

>

> ^!Info ^$Calc(MIN(3;6))$

>

> outputs '3' but 'MIN(3;6;9)' returns an "error in expression" message.

>

> I found a small utility called EVAL.EXE that you can download from

>

> http://tp.lc.ehu.es/jma/msdos.html

>

> for free. It's from Juan M. Aguirregabiria, teaching Theoretical Physics at Euskal Herriko Unibertsitatea, Bilbao. I copied the EVAL.EXE and EVAL.HLP to C:\Windows, and it seemes to work fine.

>

> For example...

>

> ^!Set %Array%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11

> ^!Info ^$GetDosOutput(EVAL MIN(^%Array%))$

>

> correctly outputs '1'.

>

> The only problem I've seen so far: It seems to return a CRNL with the output. So we get into trouble when using the result in a command like ^!IfDiff. So...

>

>

> ^!Set %Array%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11

> ^!Set %Min%=^$GetDosOutput(EVAL MIN(^%Array%))$

> ^!IfDiff "^%Min%" "1" Next Else Skip_2

> ^!Info Different!

> ^!Goto End

> ^!Info Not different!

>

>

> provides a wrong result. But when removing the CRNL, the result will be correct:

>

>

> ^!Set %Array%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11

> ^!Set %Min%=^$GetDosOutput(EVAL MIN(^%Array%))$

> ^!Set %Min%=^$StrReplace("^P";"";^%Min%;0;0)$

> ^!IfDiff "^%Min%" "1" Next Else Skip_2

> ^!Info Different!

> ^!Goto End

> ^!Info Not different!

>

>

> Please let me know if there are more problems with this utility or if there is any better solution. Thanks!

>

> Flo

>

>

> P.S. I created a little "Sorting Machine" for a more intensive testing of Eval:

>

>

> ^!SetListDelimiter ,

> ^!SetArray %Dig%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11

> ^!Set %Nr%=1; %From%=1; %Final%=^%Dig0%

>

> :Loop

> ^!Set %Val%=^%Dig^%Nr%%

> ^!Append %SubArray%=^%Val%,

> ^!Inc %Nr%

> ^!If ^%Nr% > ^%Final% Check

> ^!Goto Loop

>

> :Check

> ; Remove last comma in SubArray

> ^!Set %SubArray%=^$StrDeleteRight(^%SubArray%;1)$

> ; Use EVAL.EXE to find minimum value in SubArray

> ^!Set %Min%=^$GetDosOutput(EVAL MIN(^%SubArray%))$

> ; Remove CRNL produced by EVAL

> ^!Set %Min%=^$StrReplace("^P";"";"^%Min%";0;0)$

> ^!ClearVariable %SubArray%

> ^!Set %ANr%=1

>

> :ANrLoop

> ; Find number of minimum value in array

> ^!IfDiff "^%Min%" "^%Dig^%ANr%%" Next Else Reorder

> ^!Inc %ANr%

> ^!Goto ANrLoop

>

> :Reorder

> ^!Set %Park%=^%Dig^%ANr%%

> ^!Set %Dig^%ANr%%=^%Dig^%From%%

> ^!Set %Dig^%From%%=^%Park%

> ^!Inc %From%

> ^!If ^%From%=^%Final% End

> ^!Set %Nr%=^%From%

> ^!Goto Loop

>

> :End

> ^!Info Sorted: ^%Dig%

> ^!ClearVariable %SubArray%

>

>

> (Please note: No duplicate numbers allowed)

>

>

>

> ------------------------------------

>

> Fookes Software: http://www.fookes.com/

> NoteTab website: http://www.notetab.com/

> NoteTab Discussion Lists: http://www.notetab.com/groups.php

>

> ***

> Yahoo! Groups Links

>

>

>

> - I agree that NoteTab needs a numeric sort period, not just in the clip

functions but in the editor itself. Under the assumption that the clip sort

is a mirror of the editor sort you can easily see the results (and

fallacies), of all the arrays in this thread. Even zero padding is not an

answer:

Copy Hugo's last array to NTB, change all the commas to ^P and sort:

^!SetArray %Array%=03,8,329,1,1.25,7,10.34,4,9,6,

2,5,11,0.25,0.1,10000,20,0.0119,10,0.012

Notice the "03" is less than "1", "11" is less than 2", and so on.

And while we're at it, NoteTab also sorely needs a major/minor column sort.

Jody's clip has never worked for me so I am left with going to Ultra Edit

for anything other than trivial column one sorts. The lack of column sorts

is a PITA and an unnecessary waste of time.

BTW, UE not only does the numeric sorts but preserved the leading zero

padding characters while correctly sorting the numeric values.

Art

At 02-11-2009 12:29, you wrote:>--- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com, "Don

----------

>- HtmlFixIt.com" <don@...> wrote:

> >

> > I am pretty sure you are just picking lucky numbers to use and thus

> > getting lucky :-)

>

>Don,

>

> > 329 comes out on top in the above examples because 3 is the

> > lowest number.

>

>Yes, Don, you are absolutely right. Now it was "getting rusty inside" for

>me ;-)

>

>I should have known better since I already said: "Nevertheless, it's still

>a normal ANSI sorting of digits and no numeric sorting."

>

>So a better numeric sorting remains on the wish list. Something like...

>

>^$StrSort("Str";Numeric;Ascending;RemoveDuplicates)$

>

>(as you had in mind before). I hope Eric Fookes will read this...

>

>Regards,

>Flo

No virus found in this outgoing message.

Checked by AVG - www.avg.com

Version: 8.5.424 / Virus Database: 270.14.47/2478 - Release Date: 11/03/09 07:36:00

[Non-text portions of this message have been removed]