Insert Method for LCFieldlist

This method inserts a new field into an existing fieldlist at a specified index position.

Defined In

LCFieldlist

Syntax

Set fieldNew = fldLstRecord. Insert (index, fieldName, dataType)

Parameters

Parameter

Description

index

Long, in the range 1 to (fldLst.FieldCount+1). Index number of the field before which the new field is inserted. An index number equal to the number of fields currently in the fieldlist (plus one) is equivalent to using LCFieldlist.Append.

fieldName

String. Name of the new field.

dataType

Long. Data type of the new field. One of the following:

LCTYPE_INT

LCTYPE_FLOAT

LCTYPE_CURRENCY

LCTYPE_NUMERIC

LCTYPE_DATETIME

LCTYPE_TEXT

LCTYPE_BINARY

LCTYPE_FIELDLIST

LCTYPE_CONNECTION

Example

Option Public
Option Explicit
Uselsx "*lsxlc" 
Sub Initialize
  Dim fldLstRecord As New LCFieldList
  Dim fld As New LCField (LCTYPE_TEXT)
  Dim ref As LCField
  Dim text As String
  ' There are a number of ways to build a fieldlist
  ' Append will add a field to a list given a type
  Set ref = FldLstRecord.Append ("ACCOUNTMANAGER", LCTYPE_INT)
  Set ref = FldLstRecord.Append ("COMPANYID", LCTYPE_INT)
  ' Insert is like Append but the position
  ' within the fieldlist must be specified
  Set ref = FldLstRecord.Insert (1, "COMPANYADDRESS", LCTYPE_TEXT)
  ' CopyField will add a field to a list
  ' using an existing field as a template
  fld.Flags = LCFIELDF_KEY
  Set ref = FldLstRecord.CopyField (1, fld, "CONTACTNAME")
  ' IncludeField will add an existing field to a list,
  ' making it part of the list. in this case, 'fld'
  ' becomes a reference into the fieldlist
  fld.Flags = 0
  Call FldLstRecord.IncludeField (3, fld, "COMPANYCITY")
  text = ""
  Forall fieldname In FldLstRecord.Names
    If Text = "" Then text = fieldname Else text = text + ", " + fieldname
  End Forall
  Print "The field list is: " & text
End Sub

Example Output

The field list is: 
CONTACTNAME, COMPANYADDRESS, COMPANYCITY, ACCOUNTMANAGER, COMPANYID