Page 1 of 1 1
Topic Options
#80643 - 2002-01-23 04:56 PM MAX and MIN
AutourduPC Offline
Fresh Scripter

Registered: 2001-12-04
Posts: 24
Loc: France - Lyon (69)
Dear sir,

May be it would be usefull to have MAX and MIN function to return the max or min value between 2 variables :

eg. $var=MAX(value1,value2)

and why not for more parameters

eg. $var=MAX(value1,value2,value3,...)


Regards


Laurent BONNIN (http://www.autourdupc.com)

_________________________
www.autourdupc.com L'expérience partagée...

Top
#80644 - 2002-01-23 05:26 PM Re: MAX and MIN
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here's a quick UDF to do the max thing for you...

code:
Function udfIntMax($vArray)
Dim $iSubscript
$udfIntMax=Val($vArray[0])
For $iSubscript=1 To UBound($vArray)
If Val($vArray[$iSubscript]) > $udfIntMax $udfIntMax=Val($vArray[$iSubscript]) EndIf
Next
Return
EndFunction

Just call it like this:

code:
$iNumber=99
$iMaxNo=udfIntMax(split("9 6 $iNumber 23")) ?
"Largest number is " $iMaxNo ?

You can do the min() thing by reversing the ">" test.

Top
#80645 - 2002-01-23 05:44 PM Re: MAX and MIN
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
... or if you wanted the syntax to be a little cleaner ...
code:
Function udfIntMax($vString)
Dim $iSubscript
Dim $vArray $vArray=Split($vString,",")
$udfIntMax=Val($vArray[0])
For $iSubscript=1 To UBound($vArray)
If Val($vArray[$iSubscript]) > $udfIntMax $udfIntMax=Val($vArray[$iSubscript]) EndIf
Next
Return
EndFunction


And call it like this:
code:
$iNumber=99
$iMaxNo=udfIntMax("1,2,3,4,$iNumber,4,3,2,1")
"Largest number is " $iMaxNo ?

[ 23 January 2002: Message edited by: Richard Howarth ]

Top
#80646 - 2002-01-23 06:33 PM Re: MAX and MIN
AutourduPC Offline
Fresh Scripter

Registered: 2001-12-04
Posts: 24
Loc: France - Lyon (69)
Thanks !

I have created my own UDF for that but I though it would be usefull to include the function in the language itself (sorry for my poor english) !


Regards to all


Laurent

_________________________
www.autourdupc.com L'expérience partagée...

Top
#80647 - 2002-01-25 01:06 AM Re: MAX and MIN
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Such suggestions are very interesting. Mostly it starts as UDF and sometimes
it will be implementated in KiXtart.
Nice examples are
- the introduction of function TRIM which can replace the calls RTRIM and LTRIM.
- the new macro @crlf which replaces the CHR(13)+CHR(11) calls.

We think Ruud are looking for ideas which aren't doing one task
for one window version and which aligned with other kixtart command, func-
tion and macro structures.

Publishing UDF's can also give Ruud inspiration.
greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.065 seconds in which 0.035 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org