Max and Min Functions

Purpose

These functions return the highest or lowest value among their parameters.

Syntax

int = iMax | MaxI(i1,i2 [,i3,..., in])

int = iMin | MinI(i1,i2 [,i3,..., in])

double = Max(x1,x2 [,x3,..., xn])

$ = Min(x1$,x2$ [,x3$,..., xn$])

$ = Max(x1$,x2$ [,x3$,..., xn$])

double = Min(x1,x2 [,x3,..., xn])

currency = MaxCur(c1,c2 [,c3,..., cn])

currency = MinCur(c1,c2 [,c3,..., cn])

int64 = MaxLarge(i1,i2 [,i3,..., in])

int64 = MinLarge(i1,i2 [,i3,..., in])

c1,c2,...:currency value
i1,i2,...:integer (32- or 64-bit) value
x1,x2,...:numerical expression
x1$,x2$,...:numerical expression

Description

Max() return the highest and Min() the lowest in a series of numbers or string values given as parameters.

iMax() and iMin() do the same but with 32-bit integers (MaxLarge and MinLarge for 64-bit integers) and are therefore faster; MaxI and MinI are synonymous with iMax and iMIn respectively.

Finally, MaxCur and MinCur return the highest and lowest values from a list of currencies; integers, single and double values can also be used but Variants and Strings will cause errors.

Example

Local a% = 5, b# = 5.4

Debug.Show

Trace Max(1, a%, b#, 0.9)

Trace Min(1, a%, b#, 0.9)

Trace iMax(1, a%, b#, 0.9)

Trace iMin(1, a%, b#, 0.9) // 0.9 is rounded up to 1

An example with Currency values:

Debug.Show

Local a# = 7.45, a@ = 7.45, b@ = 2.45

Trace MaxCur(3.50, a#, b@)

Trace MaxCur(3.50, CCur(a#), b@)

Trace MinCur(3.50, a@, b@)

And an example with String values:

Debug.Show

Trace Max("ABC", "BBC", "ABX", "BD")

Trace Min("ABC", "BBC", "ABX", "BD")

Remarks

The integer functions (iMax, etc) round non-integer parameters using CInt() which rounds them to the nearest whole number EXCEPT with decimals of n.5 which it rounds to the nearest even number: therefore, both 3.5 and 4.5 will be rounded to 4, as shown by the example below:

For fastest performance it is advisable to adhere strictly to the variable type particular to the function. Variants and Strings should only be used with Max and Min.

Debug.Show

Trace iMin(3.5, 4.5)

Trace MinI(3.5, 4.5)

Trace iMax(3.5, 4.5)

Trace MaxI(3.5, 4.5)

See Also

{Created by Sjouke Hamstra; Last updated: 10/10/2014 by James Gaite}