|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Variable Definitions and Operations > Variable Commands |
MiniRobotLanguage (MRL)
VSW. Command
Variable Swap
Intention
This command can be used to swap the content of two variables, including their vartype.
It exchanges the values and types between the specified variables, ensuring that any associated metadata or type information is preserved after the swap.
This is useful for temporarily exchanging variable states without needing temporary storage variables.
In most cases, the function of VSW. provides a concise way to perform mutual assignments.
The VSW.-command performs a complete swap of variable contents and types.
Unlike simple assignment commands, it handles both variables simultaneously.
Syntax
VSW.P1|P2
Parameter Explanation
P1 - First variable name (e.g., $$VAA)
P2 - Second variable name (e.g., $$VAB)
The contents and vartype of P1 and P2 will be exchanged.
Example
'Assume $$VAA contains "ValueA" (string type) and $$VAB contains 42 (numeric type)
'After execution, $$VAA will contain 42 (numeric) and $$VAB will contain "ValueA" (string)
VAS.$$VAA=Hallo
VIN.$$VAB=9
VSW.$$VAA|$$VAB
' Now $VAB 0s Hallo and $$VAA is 9
'Swap back to original
VSW.$$VAA|$$VAB
ENR.
Limitations:
The variables must exist prior to the swap; undefined variables will cause an error.
See also:
• VAR. - Variable Set Value/Clear
• VAV. - Variables with Variables
• VBA. - Variable Binary Append
• CAL. - mathematical CALculation