Searching an Array for a Value

Other discussions about CSPro
Post Reply
Gregory Martin
Posts: 1852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Searching an Array for a Value

Post by Gregory Martin »

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;
Post Reply