$Arr_Max

From m204wiki
Revision as of 17:35, 28 January 2011 by 198.242.244.47 (talk) (Created page with "{{DISPLAYTITLE:$Arr_Max}} <span class="pageSubtitle"><section begin="desc" />Find maximum value in array<section end="desc" /></span> <p class="warning">Most Sirius $functions h...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<section begin="desc" />Find maximum value in array<section end="desc" />

Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $Arr_Max function is to be entered.

$Arr_Max can be used to find the maximum value in an array. $Arr_Max accepts two arguments and returns a numeric code.

The first argument is an array of string, float, or fixed values. This array must be a single dimensional array and must not be an array in an image.

The second argument is the highest array element number to check. This argument can be used to limit the search to the first "N" elements in an array where N is a positive integer.

If the maximum value occurs in multiple array elements, $Arr_Max always returns the lowest array element number containing that value.

Syntax

<section begin="syntax" /> %RESULT = $Arr_Max (array, maxnum) <section end="syntax" />

$Arr_Max Function

%RESULT indicates the element number of the maximum value in the array, or indicates a -1 if array or maxnum is invalid.


In the following example

%FXARRAY IS FIXED ARRAY(5) %FXARRAY(1) = 81 %FXARRAY(2) = 49 %FXARRAY(3) = 121 %FXARRAY(4) = 25 %NUM = $Arr_Max(%FXARRAY)

%NUM is set to 3.

In the following example

%STARRAY IS STRING LEN 20 ARRAY(5) %STARRAY(1) = 'HOMER' %STARRAY(2) = 'MARGE' %STARRAY(3) = 'BART' %STARRAY(4) = 'KRUSTY' %STARRAY(5) = 'SELMA' %NUM = $Arr_Max(%STARRAY, 4)

%NUM is set to 2.