'********************************************************************************************************************************************************
'* Function: appendField()
'* Parameters:
'* sFilename - Name of the file that the field is being appended to
'* sEqn - The equation or default value to be placed in the field. For numeric fields this must equate to a numeric value, for characters fields
'* it must equation to a character or use "" for an empty fields, for time it must equation to a date field.
'* sFieldName - name of the new field to be created.
'* sFieldType - Integer of the type of field. You can use the IDEA defaults such as WI_VIRT_NUM for a virtual numeric field, see the IDEA
'* documentation under Field.Type for list of parameters
'* sFieldLength - Integer that contains the length of a character field, will be ignored by all over types.
'* sDecimals - Interger that contains the number of decimals for numeric fields, will be ignore by all other types.
'* Returns: Nothing but adds a field to the supplied file.
'* Purpose: Generic function to add fields to files
'********************************************************************************************************************************************************
Function appendField(sFilename As String, sEqn As String, sFieldName As String, sFieldType As Integer, sFieldLength As Integer, sDecimals As Integer)
Dim db As database
Dim task As task
Dim table As table
Dim field As field
Set db = Client.OpenDatabase(sFilename)
Set task = db.TableManagement
Set table = db.TableDef
Set field = table.NewField
field.Name = sFieldName
field.Description = ""
field.Type = sFieldType
field.Equation = sEqn
If WI_VIRT_NUM Or WI_EDIT_NUM Or WI_NUM_FIELD Then
field.Decimals = sDecimals
ElseIf WI_VIRT_CHAR Or WI_EDIT_CHAR Or WI_CHAR_FIELD Then
field.Length = sFieldLength
ElseIf WI_VIRT_DATE Or WI_EDIT_DATE Or WI_DATE_FIELD Then
field.Length = 8
ElseIf WI_BOOL Or WI_MULTISTATE Then
field.Decimals = 0
End If
task.AppendField field
task.PerformTask
Set field = Nothing
Set table = Nothing
Set task = Nothing
Set db = Nothing
End Function
Comments
tryvltkcb
Wed, 04/17/2019 - 02:59
Permalink
Could not create character field - length = 1
Hi all & author,
Please help me as I could not create new Character field with this script as it returns a new character field with the length of 1 no matter what length i have input. I call this script in another script with the formulae as follow:
Call appendField("eee.IDM", "DESCRIPTION_RAW_1", "DESC",WI_VIRT_CHAR , 240, "") or
Call appendField("eee.IDM", """abc""", "DESC",WI_VIRT_CHAR , 240, "")
For Numeric & Date field, it works without problem.
I'm eager to receive any feedback.
Thanks all