JavaScript Editor js editor     Web development 



Main Page

Inserts an element into a one-dimensional array, or a row or column into a two-dimensional array.

AINS(ArrayName, nElementNumber [, 2])

Parameters

ArrayName


Specifies the name of the array into which the element is inserted.
nElementNumber


Specifies where the new element, row, or column is inserted into the array. To insert an element into a one-dimensional array, include ArrayName and the element nElementNumber where the insertion occurs. The new element is inserted just before element nElementNumber. To insert a row into a two-dimensional array, include ArrayName and the number of the row nElementNumber where the insertion occurs. The new row is inserted just before row nElementNumber. For more information on referencing an array element by its subscripts, see DIMENSION Command.
2


Inserts a column into a two-dimensional array. The new column is inserted just before the column specified with nElementNumber.

Return Value

Numeric

Remarks

Inserting an element, row, or column into an array does not change the size of the array. The trailing elements, rows, or columns are shifted toward the end of the array and the last element, row, or column in the array is dropped from it. The newly inserted element, row, or column is initialized to false (.F.).

AINS(В ) returns 1 if the element, row, or column is successfully inserted.

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.

В Copy Code
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

See Also



JavaScript Editor js editor     Web development