Ins

The Insert function inserts a value into a field, subfield, or sub-subfield of a dynamic array.

Group: Dynamic Array Extensions


Syntax: vREC = Ins(vREC, vFLD, [vSUB], [vSSUB], vSTR)

vREC    (Variant) is the dynamic array string variable name

vFLD    (Variant) is the array field number to search

vSUB    (Variant) Optional – is the array subfield number

vSSUB (Variant) Optional – is the array sub-subfield number

vSTR    (Variant) is data or variable name, which will be inserted at the dynamic array location (vFLD, vSUB, vSSUB).

Example:

Dim sNames As String

sNames = Ins(sNames, 2, 0, 0, "John")

Inserts string 'John' into dynamic array sNames. If sNames was originally null, then after the insert, field2 contains ‘John'; i.e., sNames = '&John'. Here, field1 is null.

Note: Suppressing the zeros [i.e., sNames = INS(sNames, 2, “John”)] gives the same result.

sNames = Ins(sNames, 2,"Mike")

If data already exists for field2 (John), then an additional insert would move field2 data to field3; i.e., sNames = '&Mike&John'. Here, field1 is null, field2 = 'Mike', and field3 = 'John'.

Using the subfields the following string can be created one element at a time using 9 Insert statements:

"John#31#English&Mike#34#Spanish&Albert#40#English"

sNames = Ins(sNames, 1, "John")

sNames = Ins(sNames, 1, 2, "31") ' First record, second field

sNames = Ins(sNames, 1, 3, "English") ' First record, third field

sNames = Ins(sNames, 2, "Mike")

sNames = Ins(sNames, 2, 2, "34") ' Second record, second field

sNames = Ins(sNames, 2, 3, "Spanish") 'Second record, third field

sNames = Ins(sNames, 3, "Albert")

sNames = Ins(sNames, 3, 2, "40") ' Third record, second field

sNames = Ins(sNames, 3, 3, "English") 'Third record, third field

If you used insert statements and the sub-subfield values you can get this:

"John#31#Canadian English@UnitedKingdom English&Mike"

by

sNames = Ins(sNames, 1, "John")

sNames = Ins(sNames, 1, 2, "31") ' First record, second field

sNames = Ins(sNames, 1, 3, 1, “Canadian English”) ‘ First record, third field, first sub-field

sNames = Ins(sNames, 1, 3, 2, "UnitedKingdom English") ' First record, third field, second sub-field

sNames = Ins(sNames, 2, "Mike")