TextConverter's methods and properties for automation

TextConverter is the main object for automation purposes. It exposes properties and methods to be used from external programming environments.

The object is exposed through the IConverterX interface.

Properties

skip

The number of records to skip in the input file.

Read/Write property
Type: integer

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.skip = 8
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

record_delimiter

The record delimiter transforms the input text stream into input records. (See setting a record delimiter for details.)

Read/Write property
Type: string

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.record_delimiter = "<LF>"
TextConverter.record_delimiter = "<Tab>"
TextConverter.record_delimiter = "<CR>"
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

field_delimiter

The field delimiter separates the input record into fields.  (See setting field delimiters for details.)

Read/Write property
Type: string

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.field_delimiter = "<Tab>"
TextConverter.field_delimiter = "(;)(,)(:)"
TextConverter.field_delimiter = "( +)(<Tab>+)"
TextConverter.field_delimiter = "<LF>"
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

text_qualifier

A character that separates blocks of text, within which all field and record delimiters are ignored (See options.)

Read/Write property
Type: 1 character string

Dim TextConverterC:\data
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.text_qualifier = "'"
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

firstrow_colnames

Set this property to true to retrieve column names from the first record in the input file (See options.)

Read/Write property
Type: boolean

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.firstrow_colnames = true
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

append

If append is true, the conversion appends records to the existing table if it is already present.  If it is false, the original table is deleted.

Read/Write property
Type: boolean

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.append = true
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

Methods 

NewProject

Creates a new Text Converter project clearing any settings or changes previously done.

Function NewProject()

Parameters:
none

Return value:
none

An exception is thrown in case of errors.

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.NewProject() 

OpenProject

Opens a TextConverter project from a file.

Function OpenProject( path )

Parameters:
string path - a file path to a project file location.

Return value:
none

An exception is thrown in case of errors.

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
TextConverter.Convert() 


SetInputFile

Sets an input file.

Function SetInputFile( path, delimiter(optional, default = False ) )

Parameters:
path string(input) - a file path to an input file location
delimiter variant (optional, input) - "true" automatically detects a delimiter by by analyzing the input file; "false" reads the delimiter from the project; string - uses the string as a delimiter.  default = false

Return value:
none

An error will cause this to throw an exception. 

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
TextConverter.SetInputFile( "C:\data\input.txt" )
TextConverter.Convert()
TextConverter.SaveProject( "C:\data\Test.ConverterX" )


SaveProject

Saves the current TextConverter project to a file.

Function SaveProject( path(optional) )

Parameters:
string path - a file path to a project file location; if this parameter is omitted the project is saved to the same file it was loaded from.

Return value:
none

An exception is thrown in case of errors. 

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.text_qualifier = "'"
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

GetStartPath

Returns a file path to the location from where the TextConverter component was started.

Function GetStartPath()

Parameters:
none

Return value:
string - a file path from where the TextConverter component was started.

An exception is thrown in case of errors.
 

Dim TextConverter, path
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
path = TextConverter.GetStartPath()

GetWorkPath

Returns the path to the TextConverter component's working folder.

Function GetWorkPath()

Parameters:
none

Return value:
string - a TextConverter component's path to a working folder.

An exception is thrown in case of errors.
 

Dim TextConverter, path
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
path = TextConverter.GetWorkPath()

LoadTextFile

Loads an input file.  Please note that pdf and all other formats are supported by this method.  The name LoadTextFile is a legacy vestige from the early days of TextConverter when only text files could be loaded as input.  While the name is obsolete, the method is fully up to date with all of TextConverter's enhancements.

Function LoadTextFile( path, check(optional, default = true ) )

Parameters:
string path - a file path to an input text file location.
boolean check - true: check input and output dictionaries and make sure they correspond to the new input; false: do not check anything, useful when the new input text file structure is definitely the same as the previous one.

Return value:
none

An exception is thrown in case of errors. 

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
TextConverter.LoadTextFile( "C:\data\input.txt" )
TextConverter.Convert() 
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

Convert

Starts the text conversion process.

Function Convert( reserved(optional, default = "") )

Parameters:
string reserved - reserved for future use.

Return value:
integer - the number of records inserted into the output database table.

An exception is thrown in case of errors.

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
TextConverter.Convert() 
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

IsValid

Checks if the component is ready for the text conversion process.

Function IsValid()

Parameters:
none

Return value:
boolean - true: the component is setup properly for a text conversion process; false otherwise.

An exception is thrown in case of errors.

Dim TextConverter
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
If TextConverter.IsValid Then TextConverter.Convert() 

GetOutputDS

Returns the output data source object.

Function GetOutputDS( reserved(optional, default = "") )

Parameters:
string reserved - reserved for future use.

Return value:
ITDataSource - an output data source object, see data source for details.

An exception is thrown in case of errors.

Dim TextConverter, DS
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
Set DS = TextConverter.GetOutputDS()
DS.SetDS( "c:\data\output.dbf" )
TextConverter.Convert() 
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

GetVar

Returns a target variable.

Function GetVar( name )

Parameters:
string name - name of the variable to look for.

Return value:
ITargetVar - target variable if it was found (See value variable for details.)

An exception is thrown in case of errors.

Dim TextConverter, Var
Set TextConverter = CreateObject( "ConverterX.ConverterX.1" )
TextConverter.OpenProject( "C:\data\Test.ConverterX" )
Set Var = TextConverter.GetVar( "MyVar" )
Var.value = 25
TextConverter.Convert() 
TextConverter.SaveProject( "C:\data\Test.ConverterX" )

Related Sections
Comments