Context Methods

Implementation of context methods is required when additional customization is needed for recognition of record/field delimiters, to filter output records, to perform custom calculation of output values and other tasks. Context methods are called by TextConverter during the conversion process and can be divided into three groups:

1. Methods called once for each process: OnStartProcess, OnFinishProcess

2. Methods called before processing each next input text line: IsNewRecord

3. Methods called for each input record: OnRecord, OnRecordDone

To start the implementation of a context method, you can create a placeholder for a new method by typing it into the script editor.  You can also use one of the following three user interface based approaches:

OnStartProcess

OnStartProcess is called before the first input record is processed. Implement this method if you want to make any kind of custom preparation for the process like creating a new file for custom output, setting up a database connection to be used as an additional reference during the conversion and so on.

Function: OnStartProcess

Parameters:
none

Return value:
none

VB sample This sample creates and opens a text file to be used during the conversion procedure:

Dim fso, file
Function OnStartProcess
Set fso = CreateObject( "Scripting.FileSystemObject" )
Set file = fso.CreateTextFile( "c:/work.txt", true )
file.WriteLine( "Process Started" )
End Function

OnFinishProcess

This method is called after the last input record is processed. Implement this method if you want to customize the final actions after the conversion process is done.

Function OnFinishProcess

Parameters:
none

Return value:
none

VB sample

This sample closes the text file created in the previous sample:

Function OnFinishProcess
file.WriteLine( "Process Ended" )
file.Close()
End Function 

IsNewRecord

IsNewRecord is called for each new line of the input text. An implementation of this method is needed to handle an irregular record delimiter. For example, a record number is a designated record delimiter and several input text lines belong to a single input record. You can not use the record delimiter option for a non-constant delimiter like this, but you can easily solve the problem by implementing IsNewRecord.

Function IsNewRecord( text_line )

Parameter:
string text_line - a line of the input text, which should be analyzed to make a decision if a new record begins with this line

Return value:
boolean true|false
   return true to indicate that the line is a beginning of a new record; otherwise, return false .

VB sample

This sample illustrates how to handle a non constant record delimiter (record number)

Function IsNewRecord( text_line )
Dim words
words = target.SplitString( text_line )
If IsArray( words ) And IsNumeric( words(0) ) Then IsNewRecord = true Else IsNewRecord = false
End Function 

OnRecord

OnRecord is called for each input record before the corresponding output record is inserted into the output database table. That is the primary method to be implemented for custom calculations of output values, input record analysis, filtering of output records and other tasks.  (See samples and walkthroughs for more information)

Function OnRecord

Parameters:
none

Return value:
none

VB sample

This sample shows how to implement OnRecord to have an output field as a function of two input fields

Function OnRecord
DictOut.Field.value = Left( DictIn.Field1.value, 3 ) & Left( DictIn.Field2.value, 4 )
End Function

OnRecordDone

OnRecordDone is called after TextConverter has inserted a new output record into the output database table. You would rarely implement this method.  Its primary use is handling of custom errors.

Function OnRecordDone( ok )

Parameter:
boolean ok - true if the record was inserted successfully, false if errors occurred.

Return value:
none

VB sample

This sample demonstrates custom error log implementation. db_log is a DataObject variable

Function OnRecordDone( ok )
If ok Then Exit Function
db_log.AppendStart()
db_log.SetCelllValue "Description", "Record failed"
db_log.SetCelllValue "RecordInfo", DictOut.Field.value
db_log.AppendFinish
End Function

Related Sections

TextConverter's Methods

TARGET Object

TextConverter's Concept

Setting up a Conversion: Step-by-Step

Samples and Walkthroughs

Scripting

Automation