X12Translator Control

Properties   Methods   Events   Config Settings   Errors  

The X12Translator control converts X12 documents to XML and back, streamlining translation between formats.

Syntax

X12Translator

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 delimiter separating controls.
DelimiterElementThe delimiter separating elements.
DelimiterRepetitionThe delimiter separating controls.
DelimiterSegmentThe delimiter separating segments.
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 a parsing error occurs.
ResolveSchemaFires to request schema information for a specific transaction set.
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 X12 document.
UseDescriptionsWhether descriptions will be included in the output XML.

DelimiterComponent Property (X12Translator Control)

The delimiter separating controls.

Syntax

x12translatorcontrol.DelimiterComponent[=string]

Default Value

":"

Remarks

The delimiter separating components.

In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

This property is not available at design time.

Data Type

String

DelimiterElement Property (X12Translator Control)

The delimiter separating elements.

Syntax

x12translatorcontrol.DelimiterElement[=string]

Default Value

"*"

Remarks

The delimiter separating elements.

In X12Reader, this type is used to hold the delimiters found when parsing the element, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

This property is not available at design time.

Data Type

String

DelimiterRepetition Property (X12Translator Control)

The delimiter separating controls.

Syntax

x12translatorcontrol.DelimiterRepetition[=string]

Default Value

"^"

Remarks

The delimiter separating components.

In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

This property is not available at design time.

Data Type

String

DelimiterSegment Property (X12Translator Control)

The delimiter separating segments.

Syntax

x12translatorcontrol.DelimiterSegment[=string]

Default Value

"~"

Remarks

The delimiter separating segments.

In X12Reader, this type is used to hold the delimiters found when parsing the segment, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

This property is not available at design time.

Data Type

String

FileWriteMode Property (X12Translator Control)

Determines how the output file is opened for writing.

Syntax

x12translatorcontrol.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.

fwmCreateCreates 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 (X12Translator Control)

The EDI message, specified as a string.

Syntax

x12translatorcontrol.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 (X12Translator Control)

The file containing the EDI message.

Syntax

x12translatorcontrol.InputFile[=string]

Default Value

""

Remarks

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

If the file is not found or cannot be opened, an error will be returned.

Note: If both InputFile and InputData are set, InputData takes precedence.

This property is not available at design time.

Data Type

String

InputFormat Property (X12Translator Control)

The format of the input data.

Syntax

x12translatorcontrol.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 (X12Translator Control)

The translated EDI data.

Syntax

x12translatorcontrol.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 (X12Translator Control)

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

Syntax

x12translatorcontrol.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 (X12Translator Control)

The format of the output data.

Syntax

x12translatorcontrol.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 (X12Translator Control)

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

Syntax

x12translatorcontrol.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 (X12Translator Control)

Sets or retrieves a configuration setting.

Syntax

x12translatorcontrol.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 (X12Translator Control)

Loads schema information from a file or string data.

Syntax

x12translatorcontrol.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 (X12Translator Control)

Resets all properties to their default values.

Syntax

x12translatorcontrol.Reset 

Remarks

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

Translate Method (X12Translator Control)

Translates the specified data.

Syntax

x12translatorcontrol.Translate 

Remarks

This method translates the specified data.

Error Event (X12Translator Control)

Fires when a parsing error occurs.

Syntax

Sub x12translatorcontrol_Error(ErrorCode As Integer, Description As String)

Remarks

This event fires when the control encounters a parsing error while processing a document.

ResolveSchema Event (X12Translator Control)

Fires to request schema information for a specific transaction set.

Syntax

Sub x12translatorcontrol_ResolveSchema(VersionNumber As String, TransactionSetIDCode As String)

Remarks

LoadSchema can be called from within this event to load the schema information for the specified transaction set.

ValidateWarning Event (X12Translator Control)

Fires to warn about validation errors.

Syntax

Sub x12translatorcontrol_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 (X12Translator 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.

X12Translator 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 X12 document.

This setting specifies the character encoding to be used for the output X12 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 (X12Translator Control)

X12Translator 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.