11 - 372 11 - 372
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
SEARCH
Function
SEARCH
• Searches for the specified value among the elements of the selected array variable and
returns the position of the element.
SEARCH (<array variable name>,<value to be searched for>[,<start element
position>][,<step value>] )
Syntax
array variable name
• • • •
Specify the array variable to be searched through
(one-dimensional integer array variables only).
value to be searched for
• • • •
Specify the integer value to be searched for in the
array.
start element position
• • • •
Specify from which element to start the search.
step value
• • • •
Specify the increment of the elements to be
searched through.
Examples
A=SEARCH(B%,5,0,3)
• • • •
Finds the number 5 in the array B%, start searching
from B%(0) in increments of 3.
B%(0)
B%(1)
B%(2)
B%(3)
B%(4)
B%(5)
B%(6)
• • • • • •
"5"
Searches from B%(0)
in increments of 3.
Returns the element
number 6 of the array
where "5" was found.
Description
• The SEARCH function searches for the value specified in <value to be searched for> in the
array variable specified in <array variable name> and returns the number of the array
element where the value is found for the first time.
The target of the search is from the element specified in <start element position> to the
last element of the applicable array variable.
If the specified value is not found in the array variable, -1 is returned.
• If the specified array variable is not a one-dimensional integer array variable, an "Illegal
function call" error occurs.
• The array variable specified in <array variable name> must be defined using the DIM
instruction before executing the SEARCH function.
• If <value to be searched for> is specified as a real number, it is first converted to an integer
and then the function is executed.
• If <start element position> is omitted, the search is started from the first element.
• If <step value> is omitted, it is assumed that "1" is specified and all the elements are
searched through.