AINS( ) Function Example

The following example creates and fills an array with company names and scans the array for a specific company name. If the company name isn't found, it inserts the missing company name into the array.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer     && Open customer table
SELECT company FROM customer ;
   WHERE country = 'Germany' ;
   INTO ARRAY gaCompanies

gnCount = _TALLY
gcName = 'Seven Seas Imports'
CLEAR
DISPLAY MEMORY LIKE gaCompanies

IF ASCAN(gaCompanies, gcName) = 0  && Search for company
*** Company not found-add it ***
   DIMENSION gaCompanies[gnCount+1,1]
   = AINS(gaCompanies, gnCount-1)
   gaCompanies[gnCount-1] = gcName
ENDIF
DISPLAY MEMORY LIKE gaCompanies