4.27 FAQ-386 How to avoid variable substitution?

Last Update: 3/31/2023

Variable with substitution notations, such as $, %, will be resolved to its actual value in Labtalk Script or in Legend.

To Avoid variable substitution in Labtalk Scripts

When the script is executed. variable substitution will cause trouble if you need the script run more than one time. To avoid this situation you can assign the special substitution notation to a String register instead of using it directly.

Example:

The following script will set the formula in the Set Values dialog of Col (B) to Col(A)[i] - %(Col(B)[U]$) without letting %(Col(B)[U]$) be substituted by the Units value of Col(B).

%A="%";
csetvalue f:="Col(A)[i] - %A(Col(B)[U]$)" c:=Col(B);
To Avoid variable substitution in Legend/Text Object

Substitution notation in legend will render it's actual value. For example, character \ or % in legend that may render unexpected strings. To avoid the situation, you can use escape sequences \v().

Example:

Example Entering... Results in Legend...
5%Cu 5\v(%)Cu Legend substitution.png

Keywords:substitution, avoid substitution, turn off substitution