andyswarbs Posted February 9, 2006 Share Posted February 9, 2006 (edited) I have taken Jeremy Landes' _Max & _Min and improved them to compare up to 20 numbers Test code Local $nmax =_Max2(5,5,7,9,3,17,-1,3) ConsoleWrite('@@ Debug(1) : $nmax = ' & $nmax & @LF);### Debug Console Local $nmin =_Min2(5,5,7,9,3,17,-1,3) ConsoleWrite('@@ Debug(1) : $nmax = ' & $nmin & @LF);### Debug Console And the code itself... expandcollapse popup; _Max2 Extends _Max to work with up to 20 numbers Func _Max2($n01,$n02,$n03='',$n04='',$n05='',$n06='',$n07='',$n08='',$n09='',$n012='',$n013='',$n014='',$n015='',$n016='',$n017='',$n018='',$n019='',$n020='') If (Not IsNumber($n01)) Then SetError(1) Return (0) EndIf If (Not IsNumber($n02)) Then SetError(2) Return (0) EndIf ; Local $Res=$n01 Local $idx Local $Val Local $Num Local $Nam ; For $idx=2 To 20 If $idx<9 Then $Nam='n0'&$idx Else $Nam='n'&$idx EndIf $Num=Eval($Nam) If IsNumber($Num) Then If $Num>$Res Then $Res=$Num Else ExitLoop EndIf Next Return $Res EndFunc ;==>_Max2 ; _Min2 Extends _Min to work with up to 20 numbers Func _Min2($n01,$n02,$n03='',$n04='',$n05='',$n06='',$n07='',$n08='',$n09='',$n012='',$n013='',$n014='',$n015='',$n016='',$n017='',$n018='',$n019='',$n020='') If (Not IsNumber($n01)) Then SetError(1) Return (0) EndIf If (Not IsNumber($n02)) Then SetError(2) Return (0) EndIf ; Local $Res=$n01 Local $idx Local $Val Local $Num Local $Nam ; For $idx=2 To 20 If $idx<9 Then $Nam='n0'&$idx Else $Nam='n'&$idx EndIf $Num=Eval($Nam) If IsNumber($Num) Then If $Num<$Res Then $Res=$Num Else ExitLoop EndIf Next Return $Res EndFunc ;==>_Min2 Edited February 9, 2006 by andyswarbs Licensing.au3Extended _Max & _Min_MsgBoxExitVarious extensions to _GuiCtrl...Run Dos programs output into an array etc (Updated 19-Feb-06)Extensions to Array library, primarily in two dimensions (updated 20-Feb-06)Version dependency calculator, _IsVer1GEVer2User Management, answering some domain questions (updated 19-Feb-06, various bugfixes and new functions added)Extensions to registry manipulation, including a recursive search & replaceDelimited string library (updated 19-Feb-03, added _DelimListSort)String library extensionsTerminal Server supportFile libraryCommand line parser (added 18-Feb-06)(UDF homepage) (Scit4Au3 UserCallTips added 21-Feb-06) Link to comment Share on other sites More sharing options...
GaryFrost Posted February 9, 2006 Share Posted February 9, 2006 Thought you might find this usefull also returns the Min or Max number from 1 or 2 arrays Test expandcollapse popupLocal $Array1[5] = [3, 2, 8, 5, 10] Local $Array2[5] = ["3", "02", "8", "1", "20"] Local $Array3[5] = ["3", "02", "8", "-1", "11"] Local $Max, $Min $Max = _MinMaxa($Array1, 1) If Not @error Then ConsoleWrite('@@ Debug(1) :$Max = ' & $Max & @LF) Else ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF) EndIf $Max = _MinMaxa($Array2, 1) If Not @error Then ConsoleWrite('@@ Debug(1) :$Max = ' & $Max & @LF) Else ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF) EndIf $Max = _MinMaxa($Array1, 1, $Array3) If Not @error Then ConsoleWrite('@@ Debug(1) :$Max = ' & $Max & @LF) Else ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF) EndIf $Min = _MinMaxa($Array1) If Not @error Then ConsoleWrite('@@ Debug(1) :$Min = ' & $Min & @LF) Else ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF) EndIf $Min = _MinMaxa($Array2) If Not @error Then ConsoleWrite('@@ Debug(1) :$Min = ' & $Min & @LF) Else ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF) EndIf $Min = _MinMaxa($Array1, 0, $Array3) If Not @error Then ConsoleWrite('@@ Debug(1) :$Min = ' & $Min & @LF) Else ConsoleWrite('@@ Debug(1) :Error = ' & @error & @LF) EndIf expandcollapse popup#include <Array.au3> ; return min or max number from 1 or 2 arrays Func _MinMaxa($a_nums01, $MaxFlag = 0, $a_nums02 = 0) If Not IsArray($a_nums01) Then SetError(1) Return (0) EndIf If @NumParams = 3 Then If Not IsArray($a_nums02) Then SetError(3) Return (0) EndIf EndIf ; Local $idx ; For $idx = 0 To UBound($a_nums01) - 1 If StringIsFloat($a_nums01[$idx]) Or StringIsInt($a_nums01[$idx]) Then $a_nums01[$idx] = Number($a_nums01[$idx]) Else SetError(2) Return (0) EndIf Next _ArraySort($a_nums01, $MaxFlag) If @NumParams = 3 Then For $idx = 0 To UBound($a_nums02) - 1 If StringIsFloat($a_nums02[$idx]) Or StringIsInt($a_nums02[$idx]) Then $a_nums02[$idx] = Number($a_nums02[$idx]) Else SetError(4) Return (0) EndIf Next _ArraySort($a_nums02, $MaxFlag) If $MaxFlag Then If Number($a_nums01[0]) > Number($a_nums02[0]) Then Return $a_nums01[0] Else Return $a_nums02[0] EndIf Else If Number($a_nums01[0]) < Number($a_nums02[0]) Then Return $a_nums01[0] Else Return $a_nums02[0] EndIf EndIf EndIf Return $a_nums01[0] EndFunc ;==>_MinMaxa SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now