# LGF_SearchMinMax (FC / 3.0.1)

Overview

Author: Siemens Digital Industries

## Short description

This function searches, in an array of the data type DInt, for the maximum and minimum value and the respective index in the array.

The following data types of the array elements are supported:
Int, DInt, UInt, UDInt, USInt, SInt, and Real.

### Block Interface

| LGF_SearchMinMax (FC) |
--- | --- | ---
Variant |  |  | variableArray |  | Ret_Val |  |  | Void
|  |  |  |  | minValue |  |  | Variant
|  |  |  |  | minValueIndex |  |  | DInt
|  |  |  |  | maxValue |  |  | Variant
|  |  |  |  | maxValueIndex |  |  | DInt
|  |  |  |  | error |  |  | Bool
|  |  |  |  | status |  |  | Word
|  |  |  |  | subfunctionStatus |  |  | Word

### Input parameter

Identifier | Data type | Description
--- | --- | ---
variableArray | Variant | Array in whose fields the maximum and minimum are searched

### Output parameter

Identifier | Data type | Description
--- | --- | ---
Ret_Val | Void | Void - Function has no return value
minValue | Variant | Minimum value found in the array
minValueIndex | DInt | Index of the minimum found value in the array. The start index of the array plus `minValueIndex` results in the array index of the smallest value. The index starts with 0.
maxValue | Variant | Maximum value found in the array
maxValueIndex | DInt | Index of the maximum found value in the array. The start index of the array plus `maxValueIndex` results in the array index of the smallest value. The index starts with 0.
error | Bool | FALSE: No error TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB 16#8000-16#FFFF: Error identification (see following Table)
subfunctionStatus | Word | Status or return value of called FB's, FC's and system blocks

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_NO_ERROR Execution finished without errors
16#8200 | ERR_NO_ARRAY Error: At input `variableArray` the actual parameter is not an array
16#8201 | ERR_WRONG_TYPE Error: The data type of the elements in the array is not supported. Only the data types Int, UInt, DInt, UDInt, USInt, SInt and Real are supported.
16#8202 | ERR_NOT_EQUAL_TYPES Error: The elements of the array do not have the same data type as the outputs `minValue` and `maxValue`
16#8203 | ERR_MOVE_BLK_VARIANT Error: Subfunction `MOVE_BLK_VARIANT` executed with and error - check `subFunctionStatus` code

## Functional description

NOTE
  The status of called commands is output in `subFunctionStatus`. In this case, the output value in `status` indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

An array of any size is connected via the `variableArray` input. After a data type query in the block, the elements are copied one after the other into a variable of the appropriate type and compared. The smallest and largest values, as well as their corresponding index are output to the array.

Note
  The following data types of the array elements are supported:
  Int, DInt, UInt, UDInt, USInt, SInt, and Real.

Note
  If there are several identical min. or max. values, the index of the first min. or max. value is output.

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 19.08.2015 | First released version
| 1.0.1 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA Portal V14 Update 1
| 1.0.2 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 1.0.3 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 1.1.0 | Siemens Industry Presales Support
| 08.11.2019 | Code refactoring, regions and more comments added
| 3.0.0 | Siemens Industry Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 09.02.2021 | Rework constants and comments Insert documentation