User Guide > Scripting > Script Objects > DJField Object Type
Was this helpful?
DJField Object Type
The DJField object type is used to access field level properties for a record layout. It is typically used in conjunction with objects of type DJRecord Object Type. It is impossible to create an independent DJField object, since there is no New operator defined for the type. However, it is possible create new DJField objects for DJRecord objects using the NewField method.
See Also
Properties
 
Property
Type
Access
Description
Length Property
Integer
RW
Get or set the field length.
Name Property
String
RW
Get or set the field name.
Self Property
DJField
RO
Return a reference to the object itself.
TypeName Property
String
RO
Get the field type name.
Value Property
Variant
RW
Get the field value (default property).
ValueSize Property
Integer
RO
Get the number of values a field contains. Use with arrayed fields in connectors.
MaxOccurs Property
Integer
RW
Get or set the maximum number of values a field can contain. Use with arrayed fields in connectors.
Length Property
Use the Length property to get or set the field length. This table outlines the available parameters.
Syntax
fld.Length
'OR
fld.Length = size
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField that is the subject of the property or method invocation.
Integer
Yes
Integer expression representing the size to assign to the DJField object.
The Length property is not meaningful for all field types. Fields using some of the numeric data types have predetermined lengths. Attempts to change these are ignored. The default length for new text fields is 16 characters.
Example
'This example shows how to change the field length for a new DJField object.
'The DJField object is created in the default record layout for a DJExport object called myexport using the NewField method.
Dim fld As DJField
fld = myexport.NewField
'Change the length of the field to 64 characters
fld.Length = 64
Name Property
Use the Name property to get or set the name of a DJField object. This table outlines the available parameters.
Syntax
fld.Name
'OR
fld.Name = name
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField that is the subject of the property or method invocation.
String
Yes
String expression representing the name to assign to the DJField object.
Example
'The following example shows how to create and name a new DJField object. The DJField object is created in the default record layout for a DJExport object called myexport using the NewField method.
Dim fld As DJField
fld = myexport.NewField
fld.Name = "Amount"
Self Property
Use the Self property to get a reference to an object through a variable. The property is useful when there is ambiguity between the use of the variable name as the object reference and the use of the variable name as a reference to the default property for the object.
Syntax
fld.Self
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField, which is the subject of the property or method invocation.
Example
'The following example shows how to use the Self property to pass a reference to the object as an argument to a function that expects a DJField reference as input.

Function RefTest(f As DJField)
  LogMessage("Info","The field name is " & f.Name)
End Function

Dim fld As DJField
fld = myexport.NewField
fld.Name = "Amount"
RefTest(f.Self)
TypeName Property
Use the TypeName property to get the field type name for a DJField object. This table outlines the available parameter.
Syntax
fld.TypeName
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField, which is the subject of the property or method invocation.
Example
'The following example writes the field type name to the log.
LogMessage("Info",fld.TypeName)
Value Property
Use the Value property to get or set the field data value. When assigning a value to a DJField object, the value is coerced to a type that is compatible with the field type. For example, if you assign a Date value to a Text field the Date value is formatted as a string and the string value is assigned to the field. The Value property is the default property for the DJField interface.
Syntax
fld.Value
'OR
fld.Value = value
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField, which is the subject of the property or method invocation.
Variant
Yes
Expression that evaluates to the value to assign to the DJField object.
Example
'The following example shows how to assign a value to a DJField object.
'A value of 10019 is assigned to a field called Account, which is a member of the default record layout for the DJExport object myexport.

myexport.FieldAt("/SOURCE/R1/Account").Value = 10019

'Here is an example using the DJField and DJExport objects. This block sets the two objects, the connector name, and describes the field properties: separator and delimiter:

Dim MyExport As DJExport
Dim MyField As DJField
Set MyExport = New DJExport "ConnectorName"
MyExport.Properties("FieldSeparator") = ","
MyExport.Properties("FieldStartDelimiter") = Chr(34)
MyExport.Properties("FieldEndDelimiter") = Chr(34)

'The next three blocks assign field names, set field sizes, and the full path of the target connect string:
Set MyField = MyExport.NewField
MyField.Name = "Amount"
MyField.Length = 64
Set MyField = MyExport.NewField
MyField.Name = "Field2"
MyField.Length = 255
MyExport.ConnectString="File=C:\path\filename.txt"

'This block populates "Amount" and "Field2", and includes an alternate method (see line three).
'The last line in this block writes to values to the target:

MyExport.FieldAt("/SOURCE/R1/Amount") = FieldAt("/SOURCE/R1/Field1")
MyExport.FieldAt(/SOURCE/R1/Field2) = FieldAt("/SOURCE/R1/Total")
'The above could also be MyExport.FieldAt("/SOURCE/R1/2") = FieldAt("/SOURCE/R1/Total")
MyExport.PutRecord

'It is important to clear the object once it is no longer needed. Clearing the object releases the memory location it occupies. Setting the objects to "Nothing", a reserved word, clears the object and releases the memory location.

Set MyField = Nothing
Set MyExport = Nothing
ValueCount Property
The ValueCount property is helpful when you have a connector that has more than one value per field. It allows you to use an index to get the number of values a field can contain.
Syntax
fld.ValueCount
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField, which is the subject of the property or method invocation.
Example
'This example shows how to retrieve the number of values the field can contain:
DJRecord rec = new DJRecord
DJField field = rec.NewField()
field.ValueCount
MaxOccurs Property
The MaxOccurs property supports the use of hierarchical connectors. The property allows you to use an index to set the maximum number of values a field can contain.
Syntax
fld.MaxOccurs = number
'OR
a = fld.MaxOccurs
Parameters
 
Type
Required
Description
DJField
Yes
Reference to the DJField, which is the subject of the property or method invocation.
Example
'When setting the array values of a field, make sure to set MaxOccurs to a number equal or greater than the number of fields you are trying to set. This example sets the field to allow up to 10 values:

DJRecord rec = new DJRecord
DJField field = rec.NewField()
rec.field.MaxOccurs = 10
For i = 1 To 10
  rec.field.Value(i) = 100 + i
Next i
Last modified date: 06/13/2022