Searching an Array for a Value
Posted: October 12th, 2011, 7:57 pm
Here's a simple user-defined function that will search an array for a specified value. If found, it will return the index of the value; otherwise it returns 0.
function searchArray(array arrayName,findValue)
numeric foundPos,itr;
do itr = 1 while itr <= tblrow(arrayName) and not foundPos
if arrayName(itr) = findValue then
foundPos = itr;
endif;
enddo;
searchArray = foundPos;
end;
numeric foundPos,itr;
do itr = 1 while itr <= tblrow(arrayName) and not foundPos
if arrayName(itr) = findValue then
foundPos = itr;
endif;
enddo;
searchArray = foundPos;
end;