Automation with Managed Code
TextConverter managed code samples for use in automation
location: InstallDir/Samples/TextConverter/Automation/Managed Code/
Sample Solution
A Visual Studio solution is provided with sample projects demonstrating TextConverter Automation using C#, Managed C++, and VB.Net. TextConverter Samples.exe is already built for your convenience. You can open TextConverterSamples.sln and build any of the samples yourself.
The C#, Managed C++, and VB.Net projects all show/implement the same set of samples. An image of what appears when your run TextConverter Samples.exe is shown below:
The actual implementation of the samples are broken down into several different categories: Sample, Text Converter Properties, Output Data source modifications(which is further broken down into Flat File output, output via OLE DB providers, and output via ODBC data sources) , TARGET Variable Manipulations, and Input/Output Mapping. A general description the functionality of each category is listed below. For more detailed information about actual API calls used by these samples please refer to the sample code provided, file and method names will be provided for each sample.
Run Sample
This sample simply loads a sample Text Converter file (“\Samples\TextConverter\1 Well formed input\1.1 Products.ConverterX” ), sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\SampleOutput.dbf”, runs the conversion, and if successful displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: RunSampleProject
Managed C++
File: TextConverterSamples.h
Method: RunSampleProject
VB.Net
File: TextConverterSamples.vb
Method: RunSampleProject
TextConverter Properties
Set Record Delimiter: This sample shows how you can modify what character is being used as a record delimiter when reading textual data in to be converted. This sample makes use of a sample Text Converter file, “\Samples\TextConverter\1 Well formed input\1.1 Products.ConverterX”, and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\RecordDelimiterOutput.dbf”. If successful, it displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetRecordDelimiter
Managed C++
File: TextConverterSamples.h
Method: SetRecordDelimiter
VB.Net
File: TextConverterSamples.vb
Method: SetRecordDelimiter
Set Field Delimiter
This sample shows how you can modify what character is being used as a record delimiter when reading textual data in to be converted. This sample makes use of a sample input Text file, “\Samples\TextConverter\Automation\Projects\Input Files\CustomersSemiColonField.txt”, and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\FieldDelimiterOutput.dbf”. If successful, it displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetFieldDelimiter
Managed C++
File: TextConverterSamples.h
Method: SetFieldDelimiter
VB.Net
File: TextConverterSamples.vb
Method: SetFieldDelimiter
Set Text Qualifier
This sample shows how you can modify what character is being used as a text qualifier when reading textual data in to be converted. This sample makes use of a sample text input file, “\Samples\TextConverter\Automation\Projects\Input Files\CustomersTextQual.txt” and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\TextQualifierOutput.dbf”. If successful, it displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetTextQualifier
Managed C++
File: TextConverterSamples.h
Method: SetTextQualifier
VB.Net
File: TextConverterSamples.vb
Method: SetTextQualifier
Skip Input File Records
This sample demonstrates how to tell Text Converter how many initial records or lines of an input file to skip before attempting to read in data. This sample makes use of the Text Converter file, “\Samples\TextConverter\1 Well formed input\1.1 Products.ConverterX”, and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\RecordSkip.dbf”. If successful, it displays a message about where the file is output to. Please not that the resultant file will have 5 fewer rows( the first 5 rows of the text file will be omitted from the output .dbf ) than the .dbf file generated from the “Run Sample”
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetRecordSkip
Managed C++
File: TextConverterSamples.h
Method: SetRecordSkip
VB.Net
File: TextConverterSamples.vb
Method: SetRecordSkip
Append to Existing Table
This sample demonstrates how to tell Text Converter that you wish to append any and all converted data to an existing file. By default output files are overwritten. This sample makes use of a sample Text Converter file, “\Samples\TextConverter\1 Well formed input\1.1 Products.ConverterX”, and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\AppendOutput.dbf”. If successful, it displays a message about where the file is output to. Successive runs of this sample will cause the size of the output file will grow.
Source Locations:
C#
File: TextConverterSamples.cs
Method: AppendOutput
Managed C++
File: TextConverterSamples.h
Method: AppendOutput
VB.Net
File: TextConverterSamples.vb
Method: AppendOutput
Use Column Names
This sample demonstrates how to inform Text Converter that you wish to use a certain line’s textual data to be taken for column name definitions. This sample makes use of a sample Text Converter file, “\Samples\TextConverter\1 Well formed input\1.1 Products.ConverterX”, and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\OutputWithoutColNames.dbf”. It then sets name_lines to 1 and reruns the conversion and outputs it to “\Samples\TextConverter\Automation\Projects\Output Files\OutputWithColNames.dbf”.
Source Locations:
C#:
File: TextConverterSamples.cs
Method: UseColNames
Managed C++:
File: TextConverterSamples.h
Method: UseColNames
VB.Net:
File: TextConverterSamples.vb
Method: UseColNames
Swap Input Text File
This sample demonstrates how to load a new input file into an existing project and run a conversion. This is useful if all of your data has the same basic format, but each file has different data. An example would be say monthly bank statements. It always has the same form, account number, check number, amount, etc, but from month to month the actual numbers will differ. This sample makes use of a sample Text Converter file, “\Samples\TextConverter\1 Well formed input\1.1 Products.ConverterX”, a replacement input text file, “\Samples\TextConverter\Automation\Projects\Input Files\ModifiedTextInput.txt”, and outputs its results to “\Samples\TextConverter\Automation\Projects\Output Files\ReplaceTextFile.dbf”. If successful, the sample displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SwapTextInputFile
Managed C++
File: TextConverterSamples.h
Method: SwapTextInputFile
VB.Net
File: TextConverterSamples.vb
Method: SwapTextInputFile
Output Datasource Modifications
Text Converter allows conversions to be output to different types of data sources such as a dbase file, excel table, access table, SQL Server table, etc. The samples listed here demonstrate how to setup various kinds of output data sources. All Output Data source samples load “\Samples\TextConverter\Manual Mode\1 Well formed input\1.1 Products.ConverterX” Text Converter project and modify the output data source. Flat File Datasources: The suggested method to set flat file data sources is to use the SetDS method. For Excel and Access files you will additionally need to set the table name. For Text/CSV output files there are also additional properties that can be set. DBF Output Datasource: This sample sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\output_table.dbf” and runs the conversion.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetDBFDataSource
Managed C++
File: TextConverterSamples.h
Method: SetDBFDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetDBFDataSource
Excel Output Datasource
This sample sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\output_table.xls” to a table/sheet named MyTable and runs the conversion.
Source Locations:
C#
File: TextConverterSamples.
Method: SetExcelDataSource
Managed C++
File: TextConverterSamples.
Method: SetExcelDataSource
VB.Net
File: TextConverterSamples.
Method: SetExcelDataSource
MS Access Output Datasource
This sample sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\output_table.mdb” to a table named MyTable and runs the conversion.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetAccessDataSource
Managed C++
File: TextConverterSamples.h
Method: SetAccessDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetAccessDataSource
Text/CSV Output Datasource
This sample sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\output_table.txt” and runs the conversion. This output file is setup to include column names as the first line of the file and separates fields with “,” and to identify text it uses the qualifier “||”.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetTextDataSource
Managed C++
File: TextConverterSamples.h
Method: SetTextDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetTextDataSource
OLEDB Datasources
To setup OLEDB data sources you need to set CLSID, dsn, database, schema, and table values explicitly as well as user name and password if needed.
MS Sql Server Output Datasource: This sample demonstrates how to setup a MS Sql Server data source. For MS Sql Server the CLSID use is SQLOLEDB. This is the progid of the SQL OLEDB Provider. Dsn is assigned to the server name, database is set to the database name, schema name is set to “dbo” by default, and in this case the table name is set to “MyTable”.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetSqlServerDataSource
Managed C++
File: TextConverterSamples.h
Method: SetSqlServerDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetSqlServerDataSource
Oracle Output Datasource
This sample demonstrates how to setup a MS Sql Server data source. For Oracle the CLSID used is “MSDAORA”. This is the progid of the Microsoft Provider for Oracle you could also use “OraOLEDB.Oracle” which is the progid for the Oracle Provider for OLEDB. Dsn is assigned to the server name, database is set to the database name, schema name is set to “MySchema”, and in this case the table name is set to “MyTable”.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetOracleDataSource
Managed C++
File: TextConverterSamples.h
Method: SetOracleDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetOracleDataSource
ODBC Datasources
For every ODBC data source connection the CLSID must be set to “MSDASQL” which is the progid for Microsoft Provider for ODBC drivers. Dsn should be set to the file or system dsn name created for this particular driver setup. In MOST cases it should not be required to specify user name and password because this information is usually stored in the driver setup.
MS Sql Server ODBC Output Datasource: This sample demonstrates how setup an output data source for an ODBC driver that is setup to connect to a MS Sql Server table.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetODBCSqlServerDataSource
Managed C++
File: TextConverterSamples.h
Method: SetODBCSqlServerDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetODBCSqlServerDataSource
MySQL ODBC Output Datasource
This sample demonstrates how setup an output data source for an ODBC driver that is setup to connect to an Oracle table.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetODBCMysqlDataSource
Managed C++
File: TextConverterSamples.h
Method: SetODBCMysqlDataSource
VB.Net
File: TextConverterSamples.vb
Method: SetODBCMysqlDataSource
TARGET Variable manipulations
The 2 following samples make use of the file: “\Samples\TextConverter\Automation\Projects\Input Files\Variable Samples.ConverterX”. The script in this sample has been modified with 3 TARGET variables, “MyVal”, “MyDate”, and “MyArray”. There are also 3 additional fields in the output dictionary: “MyVal”, “MyDateVal”, and “MyArrayVal”. The script implements the OnRecord event that is called each and every time a record is about to be written into the final output table. For each record added to the output table this script adds values for the fields: “MyVal”, “MyDateVal”, and “MyArrayVal” with the values coming from the TARGET variables: “MyVal”, “MyDate”, and “MyArray” respectively. For the value of the “MyArrayVal” field this script adds 1 value from the array at a time and then repeats itself. Example: for the default value of “A,B,C,D” the first record will have the value “A”, the second “B”, and so on, the fifth record will again have the value of “A”.
The DEFAULT values:
MyVal = 1
MyDate = 09/29/1977 00:00:00
MyArray = {A, B, C, D}
Edit TARGET Variable Value
This sample opens the sample file stated above, accesses the “MyVal” TARGET variable and alters its value to 24503. The output data source is then set to “\Samples\TextConverter\Automation\Projects\Output Files\SetTARGETVariableValue.dbf” and the conversion is then run. . If the conversion was successfully run, the sample displays a message about where the file is output to. Instead of having the value of 1 for the 12th column in the output table each record should now contain 24503.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetTARGETVariableValue
Managed C++
File: TextConverterSamples.h
Method: SetTARGETVariableValue
VB.Net
File: TextConverterSamples.vb
Method: SetTARGETVariableValue
Modify TARGET Variable Array
This sample opens the sample file stated above, accesses the “MyArray” TARGET variable and alters its array values from {A,B,C,D} to {J, K, L, M} . The output data source is then set to “\Samples\TextConverter\Automation\Projects\Output Files\ SetTARGETVariableArray.dbf” and the conversion is then run. . If the conversion was successfully run, the sample displays a message about where the file is output to. Instead of having the value of 1 for the 14th column in the output table each record should now contain J, K, L, or M.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetTARGETVariableArray
Managed C++
File: TextConverterSamples.h
Method: SetTARGETVariableArray
VB.Net
File: TextConverterSamples.vb
Method: SetTARGETVariableArray
TARGET Variable Value as Date
Demonstrates how to display the date value of a TARGET variable as a string by specifying different formats. The results are displayed in a message box.
Source Locations:
C#
File: TextConverterSamples.cs
Method: GetTARGETVariableAsDateString
Managed C++
File: TextConverterSamples.h
Method: GetTARGETVariableAsDateString
VB.Net
File: TextConverterSamples.vb
Method: GetTARGETVariableAsDateString
TARGET Variable Value as Numeric
Demonstrates how to display the numeric value of a TARGET variable as a string by specifying different formats. The results are displayed in a message box.
Source Locations:
C#
File: TextConverterSamples.cs
Method: GetTARGETVariableAsNumericString
Managed C++
File: TextConverterSamples.h
Method: GetTARGETVariableAsNumericString
VB.Net
File: TextConverterSamples.vb
Method: GetTARGETVariableAsNumericString
Input/Output Mapping
Input/Output Mappings are used to specify which field in the input dictionary is linked to which field in the output dictionary.
Get Input/Output Field Maps: This sample loads the file: “\Samples\TextConverter\Automation\Projects\Input Files\ VariableSamples.converterX”. It then displays a message box showing the current mappings in the form dictionary field In -> dictionary Field Out. It then sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\MapOutput.dbf” and runs the conversion. If the conversion was successfully run, the sample displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: GetInOutMap
Managed C++
File: TextConverterSamples.h
Method: GetInOutMap
VB.Net
File: TextConverterSamples.vb
Method: GetInOutMap
Set Input/Output Field Maps
This sample loads the file: “\Samples\TextConverter\Automation\Projects\Input Files\ VariableSamples.converterX”. It alters the current mappings by reversing which output dictionary field each input dictionary field is mapped to. ( Ex for 10 fields in each dictionary normal mapping would be in1->out1, in2->out2….in10->out10. After reversing the results would look like in1->out10, in2->out9….in10->out1. It then displays a message box showing the current mappings in the form dictionary field In -> dictionary Field Out. ) It then sets the output data source to “\Samples\TextConverter\Automation\Projects\Output Files\MapSetOutput.dbf” and runs the conversion. If the conversion was successfully run, the sample displays a message about where the file is output to.
Source Locations:
C#
File: TextConverterSamples.cs
Method: SetInOutMap
Managed C++
File: TextConverterSamples.h
Method: SetInOutMap
VB.Net
File: TextConverterSamples.vb
Method: SetInOutMap