Transform

Performs miscellaneous math functions, bitwise operations, and tasks such as ASCII/Unicode conversion.

Transform, OutputVar, Cmd, Value1 [, Value2]

 

Parameters

OutputVar The name of the variable in which to store the result of Cmd. SetFormat determines whether integers are stored as hexadecimal or decimal.
Cmd, Value1/2 See list below.

 

Cmd, Value1, Value2

The Cmd, Value1 and Value2 parameters are dependent upon each other and their usage is described below.

Unicode [, String]: Retrieves or stores Unicode text on the clipboard. Note: The entire clipboard may be saved and restored by means of ClipboardAll, which allows "Transform Unicode" to operate without losing the original contents of the clipboard.

There are two modes of operation as illustrated in the following examples:

Transform, OutputVar, Unicode  ; Retrieves the clipboard's Unicode text as a UTF-8 string.
Transform, Clipboard, Unicode, %MyUTF_String%  ; Places Unicode text onto the clipboard.

In the second example above, a literal UTF-8 string may be optionally used in place of %MyUTF_String%.

Use a hotkey such as the following to determine the UTF-8 string that corresponds to a given Unicode string:

^!u::  ; Control+Alt+U hotkey.
MsgBox Copy some Unicode text onto the clipboard, then return to this window and press OK to continue.
Transform, ClipUTF, Unicode
Clipboard = Transform, Clipboard, Unicode, %ClipUTF%`r`n
MsgBox The clipboard now contains the following line that you can paste into your script. When executed, this line will cause the original Unicode string you copied to be placed onto the clipboard:`n`n%Clipboard%
return

Notes: 1) Windows 95 requires the Microsoft Layer for Unicode to support this command (Windows 98/Me/NT4 or later have built-in support); 2) The "Send {ASC nnnnn}" command is an alternate way to produce Unicode characters, but it does not work in all applications.


Asc, String
: Retrieves the ASCII code (a number between 1 and 255) for the first character in String. If String is empty, OutputVar will also be made empty. For example: Transform, OutputVar, Asc, %VarContainingString%. Corresponding function: Asc(String).

Chr, Value1: Retrieves the single character corresponding to the ASCII code indicated by Value1. If Value1 is not between 1 and 255 inclusive, OutputVar will be made blank to indicate the problem. For example: Transform, OutputVar, Chr, 130. Corresponding function: Chr(Number).

Deref, String: Expands variable references and escape sequences contained inside other variables. Any badly formatted variable references will be omitted from the expanded result. The same is true if OutputVar is expanded into itself; in other words, any references to OutputVar inside String's variables will be omitted from the expansion (note however that String itself can be %OutputVar%). In the following example, if var1 contains the string "test" and var2 contains the literal string "%var1%", OutputVar will be set to the string "test": Transform, OutputVar, deref, %var2%. Within a function, each variable in String always resolves to a local variable unless there is no such variable, in which case it resolves to a global variable (or blank if none).

HTML, String: Converts String into its HTML equivalent by translating characters whose ASCII values are above 127 to their HTML names (e.g. £ becomes &pound;). In addition, the four characters "&<> are translated to &quot;&amp;&lt;&gt;. Finally, each linefeed (`n) is translated to <br>`n (i.e. <br> followed by a linefeed).

Mod, Dividend, Divisor: Retrieves the remainder of Dividend divided by Divisor. If Divisor is zero, OutputVar will be made blank. Dividend and Divisor can both contain a decimal point. If negative, Divisor will be treated as positive for the calculation. In the following example, the result is 2: Transform, OutputVar, mod, 5, 3. Corresponding function: Mod(Dividend, Divisor).

Pow, Value1, N : Retrieves Value1 raised to the Nth power. Both Value1 and N may contain a decimal point. If N is negative, OutputVar will be formatted as a floating point number even if Value1 and N are both integers. If Value1 is negative, OutputVar will be made blank because negatives are not supported there. See also: ** operator.

Exp, N: Retrieves e (which is approximately 2.71828182845905) raised to the Nth power. N may be negative and may contain a decimal point. Corresponding function: Exp(N).

Sqrt, Value1: Retrieves the square root of Value1. If Value1 is negative, OutputVar will be made blank. Corresponding function: Sqrt(Number).

Log, Value1: Retrieves the logarithm (base 10) of Value1. If Value1 is negative, OutputVar will be made blank. Corresponding function: Log(Number).

Ln, Value1: Retrieves the natural logarithm (base e) of Value1. If Value1 is negative, OutputVar will be made blank. Corresponding function: Ln(Number).

Round, Value1 [, N]: If N is omitted, OutputVar will be set to Value1 rounded to the nearest integer. If N is positive number, Value1 will be rounded to N decimal places. If N is negative, Value1 will be rounded by N digits to the left of the decimal point. For example, -1 rounds to the ones place, -2 rounds to the tens place, and-3 rounds to the hundreds place. Note: Round does not remove trailing zeros when rounding decimal places. For example, 12.333 rounded to one decimal place would become 12.300000. This behavior can be altered by using something like SetFormat, float, 0.1 prior to the operation (in fact, SetFormat might eliminate the need to use Round in the first place). Corresponding function: Round(Number [, N]).

Ceil, Value1: Retrieves Value1 rounded up to the nearest integer. Corresponding function: Ceil(Number).

Floor, Value1: Retrieves Value1 rounded down to the nearest integer. Corresponding function: Floor(Number).

Abs, Value1: Retrieves the absolute value of Value1, which is computed by removing the leading minus sign (dash) from Value1 if it has one. Corresponding function: Abs(Number).

Sin, Value1: Retrieves the trigonometric sine of Value1. Value1 must be expressed in radians. Corresponding function: Sin(Number).

Cos, Value1: Retrieves the trigonometric cosine of Value1. Value1 must be expressed in radians. Corresponding function: Cos(Number).

Tan, Value1: Retrieves the trigonometric tangent of Value1. Value1 must be expressed in radians. Corresponding function: Tan(Number).

ASin, Value1: Retrieves the arcsine (the number whose sine is Value1) in radians. If Value1 is less than -1 or greater than 1, OutputVar will be made blank. Corresponding function: ASin(Number).

ACos, Value1: Retrieves the arccosine (the number whose cosine is Value1) in radians. If Value1 is less than -1 or greater than 1, OutputVar will be made blank. Corresponding function: ACos(Number).

ATan, Value1: Retrieves the arctangent (the number whose tangent is Value1) in radians. Corresponding function: ATan(Number).


NOTE: Each of the following bitwise operations has a more concise bitwise operator for use in expressions.

BitNot, Value1: Stores the bit-inverted version of Value1 in OutputVar (if Value1 is floating point, it is truncated to an integer prior to the calculation). If Value1 is between 0 and 4294967295 (0xffffffff), it will be treated as an unsigned 32-bit value. Otherwise, it is treated as a signed 64-bit value. In the following example, the result is 0xfffff0f0 (4294963440): Transform, OutputVar, BitNot, 0xf0f

BitAnd, Value1, Value2: Retrieves the result of the bitwise-AND of Value1 and Value2 (floating point values are truncated to integers prior to the calculation). In the following example, the result is 0xff00 (65280): Transform, OutputVar, BitAnd, 0xff0f, 0xfff0

BitOr, Value1, Value2: Retrieves the result of the bitwise-OR of Value1 and Value2 (floating point values are truncated to integers prior to the calculation). In the following example, the result is 0xf0f0 (61680): Transform, OutputVar, BitOr, 0xf000, 0x00f0

BitXOr, Value1, Value2: Retrieves the result of the bitwise-EXCLUSIVE-OR of Value1 and Value2 (floating point values are truncated to integers prior to the calculation). In the following example, the result is 0xff00 (65280): Transform, OutputVar, BitXOr, 0xf00f, 0x0f0f

BitShiftLeft, Value1, Value2: Retrieves the result of shifting Value1 to the left by Value2 bit positions, which is equivalent to multiplying Value1 by "2 to the Value2th power" (floating point values are truncated to integers prior to the calculation). In the following example, the result is 8: Transform, OutputVar, BitShiftLeft, 1, 3

BitShiftRight, Value1, Value2: Retrieves the result of shifting Value1 to the right by Value2 bit positions, which is equivalent to dividing Value1 by "2 to the Value2th power", truncating the remainder (floating point values are truncated to integers prior to the calculation). In the following example, the result is 2: Transform, OutputVar, BitShiftRight, 17, 3

 

Remarks

In v1.0.30.03+, sub-commands that accept numeric parameters can also use expressions for those parameters.

If either Value1 or Value2 is a floating point number, the following Cmds will retrieve a floating point number rather than an integer: Mod, Pow, Round, and Abs. The number of decimal places retrieved is determined by SetFormat.

To convert a radians value to degrees, multiply it by 180/pi (approximately 57.29578). To convert a degrees value to radians, multiply it by pi/180 (approximately 0.01745329252).

The value of pi (approximately 3.141592653589793) is 4 times the arctangent of 1.

 

Related

SetFormat, Expressions, EnvMult, EnvDiv, StringLower, if var is type

 

Example

Transform, OutputVar, Asc, A  ; Get the ASCII code of the letter A.