EDIFACTTranslator Control

Properties   Methods   Events   Config Settings   Errors  

The EDIFACTTranslator control converts EDIFACT data to XML and back, streamlining translation between formats.

Syntax

EDIFACTTranslator

Remarks

The control will convert a document from the format specified by InputFormat to the format specified by OutputFormat. This allows for converting to XML from EDI and vice versa.

Before translating from EDI to XML it is recommended to load a schema using the LoadSchema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML will include types and descriptions as element attributes which are useful for interpreting the data.

After calling Translate the resulting output will contain the EDI or XML data as defined by OutputFormat.

Input and Output Properties

The control will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:
  • OutputFile
  • OutputData: The output data is written to this property if no other destination is specified.

Property List


The following is the full list of the properties of the control with short descriptions. Click on the links for further details.

DelimiterComponentThe character used to separate the controls in a composite element.
DelimiterDecimalThe character used to separate the integer portion of a numeric value from the fractional portion.
DelimiterElementThe delimiter used to separate elements within a segment.
DelimiterReleaseThe character used to escape other characters within a property.
DelimiterRepetitionThe character used to indicate a repeating element or control.
DelimiterSegmentThe character used to terminate a segment.
FileWriteModeDetermines how the output file is opened for writing.
InputDataThe EDI message, specified as a string.
InputFileThe file containing the EDI message.
InputFormatThe format of the input data.
OutputDataThe translated EDI data.
OutputFileThe name of the file to write the translated EDI data to.
OutputFormatThe format of the output data.
SegmentSuffixThe suffix that is appended to the end of a segment.

Method List


The following is the full list of the methods of the control with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting.
LoadSchemaLoads schema information from a file or string data.
ResetResets all properties to their default values.
TranslateTranslates the specified data.

Event List


The following is the full list of the events fired by the control with short descriptions. Click on the links for further details.

ErrorFires when an error occurs during message processing. Normally, the control fails with an error.
ResolveSchemaFires whenever a new EDIFACT message is encountered and no schema is found for it.
ValidateWarningFires to warn about validation errors.

Config Settings


The following is a list of config settings for the control with short descriptions. Click on the links for further details.

CloseStreamAfterTranslateWhether to close the output stream after translation.
EncodingThe character encoding to use for the output EDIFACT document.
UseDescriptionsWhether descriptions will be included in the output XML.

DelimiterComponent Property (EDIFACTTranslator Control)

The character used to separate the controls in a composite element.

Syntax

edifacttranslatorcontrol.DelimiterComponent[=string]

Default Value

":"

Remarks

The character used to separate the components in a composite element.

This property is not available at design time.

Data Type

String

DelimiterDecimal Property (EDIFACTTranslator Control)

The character used to separate the integer portion of a numeric value from the fractional portion.

Syntax

edifacttranslatorcontrol.DelimiterDecimal[=string]

Default Value

"."

Remarks

The character used to separate the integer portion of a numeric value from the fractional portion.

This property is not available at design time.

Data Type

String

DelimiterElement Property (EDIFACTTranslator Control)

The delimiter used to separate elements within a segment.

Syntax

edifacttranslatorcontrol.DelimiterElement[=string]

Default Value

"+"

Remarks

The delimiter used to separate elements within a segment.

This property is not available at design time.

Data Type

String

DelimiterRelease Property (EDIFACTTranslator Control)

The character used to escape other characters within a property.

Syntax

edifacttranslatorcontrol.DelimiterRelease[=string]

Default Value

"?"

Remarks

The character used to escape other characters within a field. For example, with the default EDIFACT delimiters, "?+" should be considered "+" character that appears within a field, not an element separator.

This property is not available at design time.

Data Type

String

DelimiterRepetition Property (EDIFACTTranslator Control)

The character used to indicate a repeating element or control.

Syntax

edifacttranslatorcontrol.DelimiterRepetition[=string]

Default Value

"*(syntax 4) or empty(syntax 3)"

Remarks

The character used to indicate a repeating element or component.

This property is not available at design time.

Data Type

String

DelimiterSegment Property (EDIFACTTranslator Control)

The character used to terminate a segment.

Syntax

edifacttranslatorcontrol.DelimiterSegment[=string]

Default Value

"'"

Remarks

The character used to terminate a segment.

This property is not available at design time.

Data Type

String

FileWriteMode Property (EDIFACTTranslator Control)

Determines how the output file is opened for writing.

Syntax

edifacttranslatorcontrol.FileWriteMode[=integer]

Possible Values

fwmCreate(0), 
fwmOverwrite(1), 
fwmAppend(2)

Default Value

0

Remarks

When OutputFile is set, this property determines how the file will be opened.

fwmCreate (Default)Creates a new file. If the file already exists, the translation will fail.
fwmOverwriteOpens an existing file and overwrites its contents. If the file does not exist, a new file will be created.
fwmAppendOpens an existing file and appends data to the end of the file. If the file does not exist, a new file will be created.

This property is not available at design time.

Data Type

Integer

InputData Property (EDIFACTTranslator Control)

The EDI message, specified as a string.

Syntax

edifacttranslatorcontrol.InputData[=string]

Default Value

""

Remarks

Set this property to specify the input EDI message as a string. The message can then be parsed with Parse.

This property is not available at design time.

Data Type

String

InputFile Property (EDIFACTTranslator Control)

The file containing the EDI message.

Syntax

edifacttranslatorcontrol.InputFile[=string]

Default Value

""

Remarks

Set this property to specify a file to read the input EDI message from. The message can then be parsed with Parse.

This property is not available at design time.

Data Type

String

InputFormat Property (EDIFACTTranslator Control)

The format of the input data.

Syntax

edifacttranslatorcontrol.InputFormat[=integer]

Possible Values

ifEDI(0), 
ifXML(1)

Default Value

0

Remarks

The value set here, along with OutputFormat, determines how the data is converted when Translate is called.

Possible values are:

  • 0 (ifEDI)
  • 1 (ifXML)

This property is not available at design time.

Data Type

Integer

OutputData Property (EDIFACTTranslator Control)

The translated EDI data.

Syntax

edifacttranslatorcontrol.OutputData[=string]

Default Value

""

Remarks

This property will be populated with the translated data after calling Translate if OutputFile and SetOutputStream are not set.

This property is not available at design time.

Data Type

String

OutputFile Property (EDIFACTTranslator Control)

The name of the file to write the translated EDI data to.

Syntax

edifacttranslatorcontrol.OutputFile[=string]

Default Value

""

Remarks

This file specified by this property will be populated with the output after calling Translate if SetOutputStream is not set.

If a file with the specified name already exists Translate will fail unless FileWriteMode is set to "fwmOverwrite" or "fwmAppend".

This property is not available at design time.

Data Type

String

OutputFormat Property (EDIFACTTranslator Control)

The format of the output data.

Syntax

edifacttranslatorcontrol.OutputFormat[=integer]

Possible Values

ofEDI(0), 
ofXML(1)

Default Value

0

Remarks

The value set here, along with InputFormat, determines how the data is converted when Translate is called.

Possible values are:

  • 0 (ofEDI)
  • 1 (ofXML)

This property is not available at design time.

Data Type

Integer

SegmentSuffix Property (EDIFACTTranslator Control)

The suffix that is appended to the end of a segment.

Syntax

edifacttranslatorcontrol.SegmentSuffix[=integer]

Possible Values

ssNone(0), 
ssCR(1), 
ssLF(2), 
ssCRLF(3)

Default Value

3

Remarks

This property determines the suffix that is appended to the end of a segment.

Possible values are:

ssNone (0)No suffix is appended to the segment.
ssCR (1)A carriage return (ASCII 13) is appended to the segment.
ssLF (2)A line feed (ASCII 10) is appended to the segment.
ssCRLF (3)A carriage return followed by a line feed (ASCII 13 and 10) is appended to the segment. This is the default value.

This property is not available at design time.

Data Type

Integer

Config Method (EDIFACTTranslator Control)

Sets or retrieves a configuration setting.

Syntax

edifacttranslatorcontrol.Config ConfigurationString

Remarks

Config is a generic method available in every control. It is used to set and retrieve configuration settings for the control.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the control, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

LoadSchema Method (EDIFACTTranslator Control)

Loads schema information from a file or string data.

Syntax

edifacttranslatorcontrol.LoadSchema fileOrData, messageName

Remarks

This method loads schema information for use when parsing, validating, and translating messages.

The FileOrData parameter can be set to the path of a file containing schema data, or can be set to the contents of a schema file directly.

MessageName can be set to the name of a specific message to load only the specified message's schema information. If left empty or set to "*", the entire schema will be loaded.

Reset Method (EDIFACTTranslator Control)

Resets all properties to their default values.

Syntax

edifacttranslatorcontrol.Reset 

Remarks

This method resets all properties of the component to their default values as specified in the property definitions.

Translate Method (EDIFACTTranslator Control)

Translates the specified data.

Syntax

edifacttranslatorcontrol.Translate 

Remarks

This method translates the specified data.

Error Event (EDIFACTTranslator Control)

Fires when an error occurs during message processing. Normally, the control fails with an error.

Syntax

Sub edifacttranslatorcontrol_Error(ErrorCode As Integer, Description As String)

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally, the control fails with an error.

ConnectionId is the associated client Id, ErrorCode contains an error code, and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

ResolveSchema Event (EDIFACTTranslator Control)

Fires whenever a new EDIFACT message is encountered and no schema is found for it.

Syntax

Sub edifacttranslatorcontrol_ResolveSchema(MessageVersion As String, MessageType As String)

Remarks

This method fires when the control encounters an EDIFACT message it has not loaded a schema for. The parameters of the event can be used to locate the correct schema and load it with LoadSchema.

MessageVersion - The EDIFACT version of the message, such as D97A.

MessageType - The type of message, such as INVOIC.

After the event fires, if the control still doesn't have a matching schema, then it will attempt schema-less parsing of the EDIFACT message.

ValidateWarning Event (EDIFACTTranslator Control)

Fires to warn about validation errors.

Syntax

Sub edifacttranslatorcontrol_ValidateWarning(Position As Long64, Line As Integer, Column As Integer, ErrorCode As String, ErrorMessage As String, ErrorType As Integer)

Remarks

When the control encounters a non-blocking error while validating a document, this event fires with information about the error.

Config Settings (EDIFACTTranslator Control)

The control accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the control, access to these internal properties is provided through the Config method.

EDIFACTTranslator Config Settings

CloseStreamAfterTranslate:   Whether to close the output stream after translation.

This setting controls whether the output stream is closed after the translation process is complete. The default value is true.

Encoding:   The character encoding to use for the output EDIFACT document.

This setting specifies the character encoding to be used for the output EDIFACT document. The default value is "UTF-8".

UseDescriptions:   Whether descriptions will be included in the output XML.

This setting controls whether descriptions are included in the output XML. The default value is true.

Trappable Errors (EDIFACTTranslator Control)

EDIFACTTranslator Errors

20203    Invalid argument.
20305    Cannot write to file.
21004    Could not find the selected schema in the chosen file.
21100    Encountered an unexpected segment tag.
21101    Attempted to perform an action while the component was busy, or close an incomplete interchange.
21045    Tried to load an invalid schema file.
21204    Encountered an error while validating the UNA segment.