TARGET is an auxiliary object that facilitates common scripting tasks. The script editor shows Target's methods when you type a .(dot) after the object's name. The methods implemented by the TARGET object facilitate common tasks like parsing text data into elements or manipulating arrays as well as the program's more powerful features such as executing external code and pulling data from the web.
TARGET methods are obtained by typing "target." (or "trg." for short) in the script editor then selecting from the list of methods. Functions and properties in the TARGET Object are similar to TextConverter, TARGET Reports, as well as any other software developed on the TARGET platform.
See also:
This object - The set of methods implemented by the specific software, that is, either the TextConverter object or the TARGET Reports Object depending on which program you are using. You call this methods from your context methods to pass data to and fro with the TextConverter or TARGET Reports object. This methods are obtained by typing " this." in the script editor then selecting from the list of methods.
Here is a syntax example. The syntax for Arrayfind in the TARGET Object is:
target.ArrayFind(ary, value, pos)
The groups of target methods are listed below in the order that they appear on the fly menu. In addition to these groups, there are may methods, like the example above, that come directly after the target object. Here are the groups:
The first of the grouped methods in the .Target drop-down allows to use and manipulate files outside of the TextConverter software. After typing "target.file." in the script pane of the program, the following fly menu appears (each method explained below):
This function returns a file's MIME type.
Function GetMIME( filename, system )
Parameters:
filename (input) - the file to be checked
system Boolean (input) - enter true to return the registered MIME type, false for a user friendly name
Return value:
either a registered MIME type or a user friendly name depending on "system"
VB Sample
Dim file
file = this.GetInputFile
target.Message "Input File MIME value: " & target.file.GetMIME(file, false)
End Function
Returns a file's size.
Function GetSize( filename )
Parameters:
filename (input) - the file to be checked
Return value:
the size of the file (measured in bytes)
VB Sample
Dim file
file = this.GetInputFile
If target.file.GetSize(file) < 1024 Then target.Message "Input file less than 1 KB. Check to make sure you are using the correct file."
End If
End Function
Returns an iSequentialStream that holds the file's content. This is the only way to read binary files (can be saved as database field).
Function Read( filename )
Parameters:
filename (input) - the file to be read (only works with text files)
Return value:
iSequentialStream
Writes a file.
Function Target.file.Write( filename )
Parameters:
filename (input) - the file to be written (append is not supported, use FileSystemObject for append)
Return value:
none
Compresses a list of files into a zip file or updates an existing zip file.
Function Zip(files, zip, update)
Parameters:
files (input) - Either an array of files or a list of filenames (separated by commas)
zip (input) - The name of the output zip file
update Boolean (input) - If "true," then the script will update a pre-existing zip file. If "False," the script will create new zip file.
Return value:
The resulting zip file
Unzips a .zip file into a designated folder.
Function UnZip(zip, folder)
Parameters:
zip (input) - The .zip file to be unzipped.
folder (input) - The location/path of the folder for the unzipped content.
Return value:
Files from the .zip file will be placed in the designated folder/path.
The mail object in the .Target drop-down is a group of methods that control
name based containers of arbitrary values. After typing "target.mail."
in the script pane of the program, the following options appear in a
fly menu (each method explained below): Send, SetAttachments, SetCC, SetFont, SetHeaders, and SetupSMPT. NOTE: The mail object requires supporting objects from the target platform and exchange server. Check with SiMX for proper server configuration before using these methods.
Sends an e-mail message. As of version 2.2 this function is not for stand alone TextConverter and Target Reports installations requires the Target platform to be running together with MS Exchange server. Enhancements are planned (and may exist on the current version).
Function Send(from, to, subject, body, HTML)
Parameters:
from (input) - The from e-mail address
to (input) - The to e-mail address
subject (input) - the text of the subject
body (input) - the text of the body of the e-mail
HTML (input) - the HTML body of the e-mail
Return value:
Sends an e-mail message.
Sets the SMTP server for mail operations. An attempt to find a server automatically will be made if all parameters are omitted.
Function SetSMTP( server, login, password )
Parameters:
server (input) - name/address of the mail sever
login (input) - username for the mail server
password (input) - password for the mail server
Return value:
none
Documentation not yet published
Function SetAttachments( a )
Parameters:
a (input) - not yet published
Return value:
not yet published
Documentation not yet published
Function SetCC( cc, bcc )
Parameters:
cc (input) - The cc e-mail address
bcc (input) - The bcc e-mail address
Return value:
not yet published
Documentation not yet published
Function SetFont( name, size, weight, color )
Parameters:
name (input) - not yet published
size (input) - not yet published
weight (input) - not yet published
color (input) - not yet published
Return value:
not yet published
e-mail will be sent using the local SMTP service and e-mail will be picked up from the specified folder.
Function SetPickupFolder( folder )
Parameters:
folder (input) - name/address of the folder for mail pick-up
Return value:
Used to modify e-mail headers. Reserved for SiMX internal use.
Function SetHeaders( names, values )
Parameters:
names (input) - advanced
values (input) - advanced
Return value:
not yet published
The map methods in the .Target drop-down. These methods control name based containers of arbitrary values. After typing "target.map." in the script pane of the program, the following options appear in a fly menu (each method explained below): Empty, Get, GetValue, Set, and SetValue.
Clears the container.
Function Empty()
Parameters:
none
Return value:
none
Retrieves container values by name.
Function Get(names)
Parameters:
names (input) - An array of names or a comma separated list of names.
Return value:
A value or if multiple names are inputted, an array of values.
Retrieves the content of the container.
Function GetValue()
Parameters:
none
Return value:
The content of the container as name1=value1&name2=value2…
The progress methods in the .Target drop-down. These methods control progress bar's behavior. After typing "target.progress." in the script pane of the program, the following options appear in a fly menu (each method explained below): Increment, SetLimit.
Sets the number of steps.
Function SetLimit(pos)
Parameters:
pos integer (input) - The integer used
to set the number of steps
Return value:
none
Increments the number of steps by a chosen integer.
Function Increment(pos)
Parameters:
pos integer (input) - The
integer used to increment the progress bar. If no integer is entered, the default is 1.
Return value:
Boolean - If true, the file was incremented by user. If false, the user canceled the process.
The strlib methods in the .Target drop-down are some of the most powerful and unique text string manipulation functions in existence. These methods
control certain key string manipulation functions. After typing "target.strlib." in the
script pane of the program, the following options appear in a fly menu
(each method explained below): Mid, Replace, Extract, Split, GetSSN, GetPhone, GetEmail, GetName, GetAddress, GetCityStateZip, GetWord, GetWords, InStr
This special Mid function, returns a string between two tags. The Tags can be regular expressions.
Function Mid( input, left_tag, right_tag, look_for, pos )
Parameters:
input string
left_tag (optional) - the start string used to define the output range, this string can be a regular expression
right_tag (optional) - the end string used to define the output range, this string can be a regular expression
look_for (optional) - a regular expression that defines the extraction
pos integer (optional, in/out) - the search from position (default is 0)
Return value:
the output string
Search for a string and replace it with another string. The look_for and replace_with input parameters can be arrays or comma separated multi values. The look_for input parameter can be a regular expression(s), but if it is, then reg_expr should be set to "true".
Function Replace( input, look_for, replace_with, reg_expr )
Parameters:
look_for variant - This can be a string, array, or comma separated multi values or, if reg_expr is set to "true", look_for can be a regular expression
replace_with - This is the string that will replace the string(s) found
reg_expr Boolean (optional) - If reg_expr is set to "true", look_for can be a regular expression (default is false)
Return value:
The input modified as specified
VB Sample
option explicit
'----------------- OnRecord -----------------
Function OnRecord
Dim c
c = DictIn.Field_1.value
If Len(c) > 20 Then
c = Replace(c, VbCr, Empty)
c = Replace(c, VbLf, Empty)
c = Replace(c, "-", Empty)
c = Replace(c, ";", Empty)
c = Replace(c, "INFO", Empty)
c = Replace(c, "KEY", Empty)
c = Replace(c, "(PM_TYPE)", Empty)
DictOut.Field_2.value = c & "`19"
Else
This.SkipRecord
End If
End Function
Extracts and returns an array of strings found.
Function Extract( input, look_for, pos_len )
Parameters:
look_for - This is a regular expression
pos_len array of two parallel arrays (optional) - position and length pairs
Return value:
An array of strings found
Breaks up the input string into parts based on an arbitrary delimiter. The delimiter can be a regular expression.
Function Split( input, delimiter )
Parameters:
delimiter - This is a string or regular expression
Return value:
An array of strings found
VB Sample 1 - Positional Function OnRecord
Dim a a = Trg.strlib.Split(This.GetLine(), Array(14,25,65)) DictOut.SetFieldValue 1, a(0) DictOut.SetFieldValue 2, a(1) DictOut.SetFieldValue 3, a(2) DictOut.SetFieldValue 4, a(3) This.AppendRecord
End Function
VB Sample 2 - Regex
option explicit
Dim t1, text, qst
'----------------- OnRecord -----------------
Function OnRecord
Dim s, a, i
s = DictIn.Field_1.value
If s = "CROSS" Then
If Len(qst) > 0 Then
a = Trg.strlib.Split(qst, "\(")
If IsArray(a) Then
For i = 1 To Ubound(a)
If InStr(a(i), "A)") > 0 Then
SetVal a, i, "A"
DictOut.SetFieldValue "Stem", text
Extracts a US Social Security Number (SSN) from the input.
Function GetSSN( input, format,
pos )
Parameters:
format Boolean - Would you like your SSN formatted? (default is true)
pos integer (optional, in/out) - search from position
(default is 0)
Return value:
The string found
Extracts a telephone number from the input. Designed to handle US numbers, international numbers with country prefixes, and extension numbers.
Function GetPhone( input, format,
pos )
Parameters:
format Boolean - Would you like your phone number formatted?
(default is true)
pos integer (optional, in/out) -
search from position
(default is 0)
Return value:
The string found
Extracts an e-mail address from the input.
Function GetEmail( input, pos )
Parameters:
pos integer (optional, in/out) -
search from position
(default is 0)
Return value:
The string found
Extracts a person's name from the input. This function is used to parse a name from a given input string.
Function GetName( input, f_name, l_name, prefix, middle, suffix )
Parameters:
f_name (output) - First Name
l_name (output) - Last Name
prefix (optional, output) - Prefix, for example, Mr. or Mrs.
middle (optional, output) - Middle Name
suffix (optional, output) -
Suffix, for example, Jr. or Ph.D.
Return value:
none - Use this function to parse a name rather than to find a name.
VB Sample
option explicit
'----------------- OnRecord -----------------
Function OnRecord
Dim fn, ln, pf, mn, sf
Trg.strlib.GetName DictIn.Field_1.value, fn, ln, pf, mn, sf
DictOut.SetFieldValue "First Name", fn
DictOut.SetFieldValue "Last Name", ln
DictOut.SetFieldValue "Middle Name", mn
End Function
Extracts a US formatted address from the input. This function both parses and finds addresses.
Function GetAddress( input, city, state, zip, address1, address2 )
Parameters:
city (output) - City
state
(output) - State
zip (output) - US formatted ZIP Code
address1 (optional,
output) - address line 1
address2 (optional,
output) - address line 2
Return value:
true/false Boolean - Was and address found?
Extracts a US city state and zip from the input. This function is used to
parse out a City, State, and ZIP code from a given input string.
Function GetCityStateZip( input, city, state, zip )
Parameters:
city (output) - City
state (output) - State
zip (output) -
ZIP code
Return value:
none - Use this function to parse a sub address rather than to find an address.
Extracts a word of text from the input. This function is a smart way to locate and parse words just like double clicking highlights a word.
Function GetWord( input, pos, to_the_right )
Parameters:
to_the_right Boolean (input) - the function returns the next word to the right when true or to the left when false
(default is true) non-political
pos integer (optional, in/out) -
search from position
(default is 0)
Return value:
The output string, that is, the next or previous word.
Extracts an array of words of text from the input. This function is a smart way
to locate and parse words just like double clicking highlights a word.
Function GetWords( input, root_words)
Parameters:
root_words Boolean (input) - when set to true only the root of the word(s) are returned, that is all prefixes and suffixes are striped off, for example "words" or "wording" become "word"
(default is false)
Return value:
An array of words.
Use this to find the exact location of something in a string.
Function InStr( input, look_for, length, s_pos )
Parameters:
look_for (input) - This is a regular expression
length integer (output) - The length of the sub-string found
s_pos integer (optional,
in/out) -
search from position
(default is 0)
Return value:
The starting position of the found sub-string
VB Sample
option explicit
Dim t1, text, qst
'----------------- OnRecord -----------------
Function OnRecord
Dim s, a, i
s = DictIn.Field_1.value
If s = "CROSS" Then
If Len(qst) > 0 Then
a = Trg.strlib.Split(qst, "\(")
If IsArray(a) Then
For i = 1 To Ubound(a)
If InStr(a(i), "A)") > 0 Then
SetVal a, i, "A"
DictOut.SetFieldValue "Stem", text
ElseIf InStr(a(i), "B)") > 0 Then
SetVal a, i, "B"
End If
Next
End If
End If
This.AppendRecord
'x section omitted x
If Trg.strlib.InStr(s, "\([ABCD]\)") > 0 Then
qst = qst & " " & Trim(s)
End If
This.SkipRecord True
End Function
Finds a value of an arbitrary type in a one dimensional array.
Function ArrayFind(ary, value)
Parameters:
one dimensional variant array ary - an array in which the search is to take place
variant value - the value to search for
Return value:
integer - an index of the found value or -1 if the value was not found
VB Sample
'-----------------
Function AddRecords
Dim i, j, k, c, s, n, cc, cr, rt, lc, lz, acr(), m_cr
If IsArray(sw) Then
n = Ubound(sw)
m_cr = 0
For k = 0 To n
s = sw(k)
cr = Trim(Mid(s, 60, 50)) '<- craft
If Target.ArrayFind(acr, cr) = -1 Then
ReDim Preserve acr(m_cr)
acr(m_cr) = cr
m_cr = m_cr + 1
End If
Next
Inserts a value of an arbitrary type into a one dimensional array at a specified position.
Function ArrayInsert(ary, value, index)
Parameters:
one dimensional variant array ary - an array where the insertion is to take place
variant value - the value to be inserted
integer index - the position at which the new value should be inserted
Return value:
one dimensional variant array - a new array with the value inserted at the specified position
Creates an arbitrary object specified as the path to the object.
CreateObject(path)
Parameters:
string path - the path to the object
Return value:
object - the new object
Acts as a shell to run an arbitrary executable specified as input.
Execute(command, login, password, domain, synch)
Parameters:
string command - the command (required)
string login - the login/UID (optional)
string password- the password (optional)
string domain- the domain (optional)
string synch - synch (optional)
Return value:
boolean - true: the command executed, false if there is an error and message if applicable.
Formats a date value according to a specified format.
Function FormatDate(value, format(optional), time(optional))
Parameters:
variant value - data value to be formatted
variant format (optional, default value = false) - either a string containing the desired date format (See date formats) or a boolean (false: the default date format, true: SQL compatible date format.)
boolean time (optional, default value = false) - applicable if the first parameter is a boolean; true: include the time portion in the return value, false: do not include the time portion in the return value
Return value:
string - a text representation of the date value according to the specified format
VB Sample
Dim dt, val
dt = CDate( "11/16/2005 13:34:12" )
val = UserVar.FormatDate( dt, "DDDD, MMMM DD, YYYY" ) ' the return value: Wednesday, November 16, 2005
val = UserVar.FormatDate( dt, "MM/DD/YYYY h:m:s p" ) ' the return value: 11/16/2005 1:34:12 PM
Formats a numeric value according to a specified format.
Function FormatNumeric(value, format)
Parameters:
variant value - the numeric value to be formatted
string format - the numeric format to be applied to the value (See numeric formats.)
Return value:
string - a text representation of the numeric value according to the input format.
VB Sample
Dim val, dt
dt = CDbl( "4123.26" )
val = UserVar.FormatNumeric( dt, "#,###" ) ' the return value: 4,123
val = UserVar.FormatNumeric( dt, "#,###.#" ) ' the return value: 4,123.3
val = UserVar.FormatNumeric( dt, "E" ) ' the return value: 4.12326E+003
Prevents errors from appearing to the user.
GetMessage(remove)
Parameters:
boolean remove - if true, removes the messages. If false, does not remove.
Return value:
variant - either message or no message.
Available but not yet documented.
GetService(serv_id)
Parameters:
Not yet documented
Return value:
Not yet documented
Initializes a date value from a text date string according to a provided format.
Function InitDate(text, format)
Parameters:
string text - a text date string
string format - the date format description ("MM/DD/YYYY", "DDDD, MMMM DD, YYYY", etc. See date and numeric formats for more information)
- The masks for time parsing are:
h:m:s (24 hours time)
h:m:s p (12 AM/PM time)
Samples:
Return value:
date - a date value initialized from the text using the specified format
VB Samples
Function OnRecord
Dim str, dt
str = "01/01/2012"
dt = Trg.InitDate(str, "DD/MM/YYYY") 'for euro date format
dt = Trg.InitDate(str, "MM/DD/YYYY") 'for USA date format
Function OnRecord
Dim str, dt
str = "10/11/2011 11:12:34 pm"
dt = trg.InitDate(str, "M/D/YYYY h:m:s p")
Function OnRecord
Dim str, dt
str = "10/11/2011 14:12:34"
dt = trg.InitDate(str, "M/D/YYYY h:m:s")
Initializes a numeric value from a text representation of a number according to a provided format.
Function InitNumeric(text, decimals)
Parameters:
string text - a string containing a numeric value
integer decimals - the number of decimal positions to be used for numeric initialization.
Return value:
numeric - the numeric value initialized from the text using the specified format
InitNumeric( "12376", 2 ) will produce 123.76 as a numeric value.
Checks if the value passed to the function is Empty, Null or has zero length.
Function IsEmpty(value)
Parameters:
variant value - a value to be checked.
Return value:
boolean - true: the value is empty, false otherwise
VB Sample
'-----------------
Function SetByTagNum( i, s, t1, t2 )
Dim p1, p2, d, r, c
r = Empty
d = Len(t1)
p1 = InStr(1, s, t1, 1) + d
If d = 0 Then p1 = 1
If p1 > d Then
r = Trim(Mid(s, p1))
If Len(t2) > 0 Then
p2 = InStr(1, r, t2, 1)
If p2 > 0 Then r = Trim(Left(r, p2 - 1))
End If
If Len(r) > 0 Then
if Target.IsEmpty(v(i))
Then
v(i) = r
ElseIf IsNumeric(v(i)) Then
v(i) = ChNum(v(i)) + ChNum(r)
End If
End If
End If
End Function
Checks if the value passed to the function is Numeric.
IsNumeric(value)
Parameters:
variant value - a value to be checked.
Return value:
boolean - true: the value is numeric, false otherwise
VB Sample
See example for IsEmpty() above
Checks if the value passed to the function is True.
IsTrue(value)
Parameters:
variant value - a value to be checked.
Return value:
boolean - true: the value is true, false is null, empty, or otherwise false.
Compares 2 or 3 numeric, date, or string values and returns the maximum value. String values are compared based on their ASCII value.
Max(val1, val2, val3(optional))
Parameters:
variant val1 - a numeric, date, or string value to be checked. (required)
variant val2 - a numeric, date, or string value to be checked. (required)
variant val3 - a numeric, date, or string value to be checked. (optional)
Return value:
variant value - the largest/maximum value
Compares 2 or 3 numeric, date, or string values and returns the minimum value. String values are compared based on their ASCII value.
Min(val1, val2, val3(optional))
Parameters:
variant val1 - a numeric, date, or string value to be checked. (required)
variant val2 - a numeric, date, or string value to be checked. (required)
variant val3 - a numeric, date, or string value to be checked. (optional)
Return value:
variant value - the smallest/minimum value
Outputs a text message to the end user. Can be used for debugging purposes. If TextConverter is running in a batch mode, the messages are placed into a log file. If TextConverter is automated from other programming environments, the error message is returned to the calling function.
Function Message(text, error)
Parameters:
string text - a message to be shown to the end user
boolean error - true: show the message as an error; false: show as an information message
Return value:
none
VB Sample
'----------------- OnRecord -----------------
Function OnRecord
Dim s, c, i, p1, p2
s = DictIn.Field_1.value
SetByTag v(1), s, "DATE:", " "
This.SkipRecord
End Function
'Target.Message This.GetRecordNumber() & " - " & s
Available but not yet documented.
Replace(val, names, values)
Parameters:
Not yet documented
Return value:
Not yet documented
Waits doing nothing for a specified number of milliseconds.
Function Sleep(msecs)
Parameters:
integer msecs - a number of milliseconds to wait for
Return value:
none
Sorts a one dimensional array containing arbitrary type values.
Function Sort(ary, permutations)
Parameters:
one dimensional variant array ary - an array to sort
boolean permutations - controls how to return the result. See the Return value section.
Return value:
one dimensional array - permutations = true: the return value is an array of integer indices corresponding to the sorting of the input array; permutations = false: the return value is a sorted array of original values
Breaks an input string into an array of words. Any character which is not a letter, underscore, or a digit is considered to be a word separator.
Function SplitString(text)
Parameters:
string text - input text
Return value:
one dimensional array - will contain all of the words in the input text
VB Sample
'-----------------
Function IsName( s, ByRef v1, ByRef v2, ByRef v3 )
Dim w, n, l, c
w = Target.SplitString(s)
n = UBound(w)
IsName = 0
l = Len(w(0))
If Mid(s, l+1,2)=", " Or Mid(s, l+1,2)=". "Then
If n = 1 Then
IsName = 1
v2 = w(1)
ElseIf n > 1 Then
If Len(w(2)) < 3 Then IsName = 1
If n > 2 Then
For i = 3 To n: c = c & " " & w(i): Next
v3 = Trim(c)
End If
v2 = w(1) & " " & w(2)
End If
v1 = Left(s, l)
End If
End Function
This function updates value_to with value_from but only if value_from is not empty. This efficient function replaces a lot if extra code as shown in the example.
Function Update( value_to, value_from )
Parameters:
value_to (input) - the variable that will be updated
value_from (input) - the value that, if not empty, will
be placed into the variable
Return value:
none
VB Sample
'----------------- OnRecord -----------------
Function OnRecord
target.update v(1), target.strLib.mid(s, "DATE:\ *", " ")
Without the target.Update() function the code would look like this...
'----------------- OnRecord -----------------
Function OnRecord
Dim s, c, i, p1, p2
s = DictIn.Field_1.value
SetByTag v(1), s, "DATE:", " "
This.SkipRecord
End Function
'-----------------
Function SetByTag(ByRef val, s, t1, t2)
Dim p1, p2, d, r, c
r = Empty
d = Len(t1)
p1 = InStr(1, s, t1, 1) + d
If d = 0 Then p1 = 1
If p1 > d Then
r = Trim(Mid(s, p1))
If Len(t2) > 0 Then
p2 = InStr(1, r, t2, 1)
If p2 > 0 Then r = Trim(Left(r, p2 - 1))
End If
If Len(r) > 0 And Len(val) = 0 Then val = r
End If
End Function
Determines whether a value is within the set parameters.
Validate(val, deflt, from, to)
Parameters:
val - value to be validated (required)
default - a default value to be outputted when tested value not within parameters (required)
from - a numeric, date, or string value to be checked (required)
to - a numeric, date, or string value to be checked (required)
Return value:
Variant value - the original value if it passes through validation, or the "default" if not within the set parameters
|