Macro Language Reference > Macros > Application > ^
  
^
Description
Defines, modifies or inserts the value of a variable item, depending on what operator is used. PTC ALD keeps only one set of variables which it shares across the entire system. All open documents use the same variables.
 
Example 20. Error log builder script using a variable and its operators
This example is part of a error log builder from a frame building script. It processes the variable and getvar values to show into the ^result variable, this is then appended to the end of the error log stream.
^result?There were $^frames_on_page placed on page $^01530
^"error_log".^result
Syntax
^ variable:m operator:w value:n
variable
The name of the variable whose value is to be set: any valid tag name prefixed by a ^ character.
 
Pre version 7, the use of upper or lower case letters was not significant: ^fred was the same variable as ^FRED. Following the implementation of Perl in PTC ALD , variable names are now case sensitive: ^fred is a different variable entirely to ^FRED or ^Fred.
Variable names must not contain hyphens.
operator
The type of operation to be carried out on a variable:
=
Set variable to value. The example below creates three new variables:
^num=123 ^string1=Dave ^num=^Dave
If variable already existed these macros would reset them to the new values.
+
Increase the value of variable by value:
^Num+^Val
^Num+1
^Num1++
 
++ is a shortcut for increasing the value of variable by 1.
-
Decrease the value of variable by value.
 
-- is a shortcut for decreasing the value of variable by 1.
*
Multiplies the value of variable by value:
^Num*5
^Num1*^Num2
/
Divide the value of variable by value.
}
Make the contents of variable have exactly value characters, by truncating it or by adding spaces on the left. The example below makes ^string have five characters, making its final value ...Ad (where points represent a space character):
^string1=Adv ^string1}5
{
Make the contents of variable have exactly value characters, by truncating it or by adding spaces on the right. The example below makes ^string1 have five characters, making its final value Adv.. (where points represent a space character):
^string1=Adv ^string1{5
.
Appends value to the end of the contents of variable. The example below sets two variables and then concatenates them, with the result that ^string 1 will contain 'HelloDave':
^string1=Hello
^string2=Dave ^string1.^string2
!
Gets the length of a string. The example below gives ^string1 a value of 4, this being the number of characters in the word 'Four':
^string1=Four ^string!^string1
[
Replaces the contents of variable with a sub-string of itself, counting from the v1st to the v2nd characters where v1 is the first character, numbered 1, in the string. The last character's number is the same as the length of the string. If v1 is zero or not present it defaults to the first character of the string. If v2 is zero or not present it defaults to the last character of the string. If you wish you can add a ] at the end of the line: this has no effect and is for readability only. The example below effectively cuts off the first character of ^string1, which becomes def):
^string1=(def) ^string1[2..]
]
The ] operator is similar to [, but works from the end of the string. v1 is therefore the last character in the string. v2, is the first character in the string. If v2 is zero or not present it defaults to the first character of the string. If v1 is zero or not present it defaults to the last character of the string. If you wish you can add a [ at the end of each line: this has no effect and is for readability only.
@
Retrieves the position of a single specified character in a line. The example below gets position of the dcharacter, set in ^var from the contents of the ^string variable: this command will set the value of ^var to 4:
^string=abcdefg ^var=d ^var@^
string
$
Convert values from deci-microns to any PTC ALD unit: used with floating points with variables and measurement getvars.
#
Convert values from PTC ALD unit form to deci-microns. The syntax of 'mm' is the same as for the '$' operator, but this time it provides the default units if none are present in ^variable. A valid default must always be specified, even if ^variable is known to contain its own unit type.
|
Logical or used to perform binary bitwise arithmetic on two binary values. In the result, digits that are set in either value are returned with a value of 1.
:
Logical and used to perform binary bitwise arithmetic on two binary values. In the result digits which are set in both values are returned with a value of 1.
^
Logical xor used to perform binary bitwise arithmetic on two binary values.
%
Modulus (remainder of division).
value
The value of the variable: a string or the name of another variable
Additional Information
Post version 7 PTC ALD has no limit on the character content of regular named variables, whereas pre version 7 there is a character limit of 159. Characters shown to variables above this amount are simply ignored.
It is important to ensure that script variable names do not clash with other variable names in use by PTC ALD , in other user scripts running at the same time, or in macros such as those used in keyboard assignments.
Most of the 'Extensions' scripts supplied have been edited to minimize memory usage by reusing variables wherever possible. They therefore use variable names in the form ^_z_..^_a_.. Using this limited set of variable names helps avoid possible conflicts with variable names chosen by the user. You can conserve memory by using the same names for variables which only need to be stored whilst a particular script is running, but should realise that these variables' contents may be changed by other scripts.
Once a variable has been assigned a value, it can be used with any macro in place of the parameters that the macro would usually take. This is done by including the variable name on a macro line and appending a ^ character to the end of the line. When PTC ALD macro processor receives a macro line ending with ^ it immediately scans the whole line looking for valid variable names with their preceding ^ and replaces them with the variables' contents. The resulting line is then executed as a normal macro.