TextPipe: Online Help
    Script Filter
 

Submit feedback on this topic 

 Home  User Assistance   Tutorials   How to Use TextPipe
 Menus: File   Edit   Filters[ Wizards  Convert   Unicode   Add   Remove   Replace   Extract   Special   Maps   Restrict ]  Tools   Window   Help   Advanced

 

 (Pro version only)

This filter allows you to program your own TextPipe filter in VBScript, JScript, VBA, PerlScript, Python, Lisp, REXX etc. You could use your own code to perform custom text processing, e.g. adding line numbers to the end of each line, deleting every second line, deleting every third blank line etc. You could use a message box to ask the user for some input, and then add that input to every line. Or you could invoke Excel, paste text into it, perform a complex statistical calculation and then put the result back in the file. See the example filters in the VBScript folder (such as the one to copy numeric data into an excel spreadsheet, create a 3d graph and then rotate it!). The possibilities are endless!

For the latest information about the extra downloads required, see www.datamystic.com/otherdownloads.html

Inside an script, TextPipe provides the TextPipe internal automation object so that scripts can determine vital data about the current filter, and turn on and off sub filters according to programmed criteria.

See also Automating TextPipe from another program

Script Language

The script language to use. Default values are VBScript, JScript and VBA, but you can download and install others (they will not appear in the list - you must enter them manually). TextPipe will display an error message if the language you specified is not installed. You can download the Microsoft VBScript and JScript engines and reference documentation from the Microsoft web site at  http://msdn.microsoft.com/scripting/default.htm

Timeout (milliseconds)

Specify the timeout in milliseconds. A script will be aborted if it runs for more than the specified number of milliseconds. The default value is 10000 (i.e. 10 seconds).

Check script

This button checks the script for any errors. If there is an error, a dialog box will appear with a description of the error.

Use default

This button replaces the existing script with the default script for the current language. This can be used as a template for your own code. TextPipe comes with a default script for VBScript inbuilt, and a sample JScript script can be loaded from the VBScript folder.

Set default

This button sets the default script for the current language to the current script. The default script is language dependant, so you can have different scripts for JScript and VBScript etc.

Functions

The following functions are REQUIRED by the script filter. Each filter is followed by explanatory text.

A processing run results in a series of calls as follows:

startJob()

for each input file
  startFile()

  for each line of the file
    processLine(...)

  endFile()

endJob()

function processLine( line : string; EOL : string) : string

TextPipe calls this function for every line in the input file (if your file has 10,000 lines, this function will get called 10,000 times). The function must return the processed line with the EOL string already appended to it.

Lines can be of unlimited length, and are delimited by CR/LF, CR or LF, depending on how the file was generated. TextPipe allows a file to contain more than one kind of end of line character. If needed, you can force all end of line characters to be standard by preceding this filter with a convert end of lines filter. You can also use your own end of line character instead of EOL.

If you need to process multiple lines, paragraphs, pages of text or the entire file, the best approach is to accumulate each line and EOL into a global buffer variable, and then output the entire processed buffer in the endFile() function.

sub startJob()

Called once at the start of a processing job, before any files are processed. Use it to initialize any job-wide variables. A processing job is the combination of all filters applied at once.

sub endJob()

Called once at the end of a processing job, after all files have been processed. Use it to dispose of OLE objects etc. A processing job is the combination of all filters applied at once.

function startFile() : string

Called at the start of each file. Use it to initialize file variables. The return value is any string that must be output at the beginning of the file (header text).

Note: startFile() is ALSO called when the Script is a sub filter, for each text value that the sub filter operates on. The impact of this is that real per-file initialization/finalization needs to be performed in a script that is not inside any sub filters. Global variables set using TextPipe.setGlobalVar should be initialized in this script as well.

function endFile() : string

Called at the end of each file. The return value is any string that must be output at the end of the file (footer text). This may also be used to flush any pending output, such as when the entire file is buffered before being output.

Note: endFile() is ALSO called when the Script is a sub filter, for each text value that the sub filter operates on. The impact of this is that real per-file initialization/finalization needs to be performed in a script that is not inside any sub filters. Global variables set using TextPipe.setGlobalVar should be initialized in this script as well.

Global variables

You can declare global variables at the top of the script (see the 'a' variable below). You should initialize these values in the startJob() function, and dispose of them (e.g. for OLE Objects) in the endJob() function.

Debugging

Currently, the easiest way to debug the script is to use VBScript MsgBox() or alert() functions to display text.

Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
   ' MyVar contains either 1 or 2, depending on which button is clicked.

JScript: Does NOT have an alert or MsgBox method. These are part of Internet Explorer, not JScript (but strangely they are in VBScript). Use the alert function of the TextPipe object instead.

Example VBScript

'This example script keeps a line counter that 
'does not reset for each file

'Our line counter
dim a

'Called for every line in the file
'EOL contains the end of line characters (Unix, DOS or Mac) that must be
'appended to each line
function processLine(line, EOL)
  a = a + 1
  'add the count to the end of each line
  processLine = line & " " & a & EOL
end function


'Called at the start of a processing job -
'perform one-time initialization here
sub startJob()
  a = 0
end sub


'Called at the end of a processing job -
'destroy any declared objects here
sub endJob()
  'do nothing
end sub


'Called before each file is opened -
'perform per-file initialization here
function startFile()
  startFile = ""
end function


'Called before each file is closed -
'flush all pending file output here
function endFile()
  endFile = ""
end function

Example JScript

//This example script keeps a line counter that
//does not reset for each file

//Our line counter
var a;

//Called for every line in the file
//EOL contains the end of line characters (Unix, DOS or Mac) that must be
//appended to each line
function processLine(line, EOL)
{
a = a + 1;
//add the count to the end of each line
return line + " " + a + EOL;
}


//Called at the start of a processing job -
//perform one-time initialisation here
function startJob()
{
a = 0;
}


//Called at the end of a processing job -
//destroy any declared objects here
function endJob()
{
; //do nothing
}


//Called before each file is opened -
//perform per-file initialisation here
function startFile()
{
return "";
}


//Called before each file is closed -
//flush all pending file output here
function endFile()
{
return "";
}

 

 Contact Us   Support   Community   Tutorials and User Guides (online)
 Copyright © 1999-2006 DataMystic. All rights reserved.