IF Commands|
IF expression = true command block END IF Another Example, using ELSE: IF (expression) command block (if true) ELSE command block (if false) (the ELSE block is optional) END IF Another Example, using ELSE IF: IF expression #1 command block ELSE IF expression #2 command block ELSE IF expression #3 command block ELSE command block END IF |
| IF (expression) = FALSE THEN [failure action] |
|
IF NOT (expression which fails) THEN [success]
More Examples: "IF File Exists" + IF NOT: (file does not exist yet) = [success] "IF File Exists" + IF NOT: (file exists) = [failure] |

*Tip:
Be sure to use the Auto-Indent and Validate command
with scripts that use Loops and IF statements.
It will help your script be more readable and reliable.
|
| *Tip:
There is an abbreviated way to do an IF...THEN...ELSE block in a vTask script, which helps to minimize steps.
Programmers may be already familiar with this trick, which is called a "Ternary conditional."
A ternary operation has the basic structure "IF condition ? if true : if false".
Putting that into practice, when you have a block of steps that looks like this: ![]() They can be combined into a single step, like this: ![]() A reduction from 5 steps into just 1! That's definitely a great optimization, especially when clarity is not sacrificed. For more information, refer to the Excel-compatible IF conditional in vTask. |
| *Tip: NOTE: "ELSE IF" is contained as an option inside of each "IF" check (meaning that any IF check can be turned into an ELSE IF check) |
IF Expression
| *Tip: To compare two text strings, use the IF Text action instead of IF Expression. IF Text includes many text-specific options, and also is necessary for comparisons if the text contains embedded operator characters such as >, <, or =. |
| Expression | Evaluates To: |
| %foo = 1 | True if %foo is set to 1 |
| %foo = hello world | True if %foo is set to the text "hello world" |
| (1+2/3) >= (4+5/6) | False (see Math Calculations for more examples of math functions.) |
| test != Test test <> Test |
True (see Expressions for more examples of equality testing.) |
| 1 = 2 (with IF NOT option) |
True |
| 1 || 2 | True |
| 0 || 1 | True |
| 1=2 || 2=3 | False |
| 1=2 || 2=2 | True |
| 1 && 0 | False |
| 1=1 && 2=2 | True |
| 1 && 7 && 2 | True |
| 1 && 0 && 2 | False |
| hello = goodbye || yes = yes | True |
| %foo = 10 || %foo = 20 | True |
| hello = goodbye && yes = yes | False |
| 1 || 7 && 2 | Multi-part expression with mixed operators are not supported in the current version of vTask. |
IF Text
| String | Check Type | Comparison Value | Result |
| abc123 | Has Any Value (default) | True | |
| abc123 | Is Empty | False | |
| abc123 | Equals Exact Value | abc123 | True |
| abc123 | Equals Exact Value | abc1 | False |
| abc123 | Equals Value Insensitive | ABC123 | True |
| abc123 | Starts with | ab | True |
| abc123 | Ends with | 23 | True |
| abc123 | Length Equals | 6 | True |
| abc123 | Length Equals | 7 | False |
| abc123 | Length Less Than | 10 | True |
| abc123 | Length More Than | 10 | False |
| abc123 | Contains Exact Substring | bc | True |
| abc123 | Contains Exact Substring | BC | False |
| abc123 | Contains Substring (Insensitive) | BC | True |
| abc123 | Contains Any Characters from List | abcdefg | True |
| abc123 | Contains Any Characters from List | xyz | False |
| abc123 | Contains Only Characters from List | abcdef123456 | True |
| abc123 | Contains Only Characters from List | abcdef | False |
IF Variable
| Variable Check | Description |
| If Defined (Exists) | Returns TRUE if the variable has been previously defined. This is often referred to as checking if the variable is not NULL. This will return TRUE even if the variable is empty. Note that this can return TRUE if the variable was defined in another script, and the "Reset user variables before each run" is turned OFF. |
| If Empty | Returns TRUE if the variable has been previously defined, but contains no value. This will fail if the variable does not exist. |
| Has Numeric Value | Returns TRUE if the variable contains only numbers or the characters [space], [-], [,], or [.] |
IF File Exists
IF Folder Exists
IF Window Exists
IF Key is Pressed
IF Caps Lock is On
IF Image is Visible
IF Clipboard Contains
IF Internet
| Check Type | Description |
| Connected | Checks to see if an the computer has a valid and active internet connection. If the computer is not connected, this command will not cause it to make a connection. This is different from the Ping command in that it actually checks for live web access, instead of verifying an IP address. |
| Valid Link | Confirms a web URL (address) for existence. A "404" (Not Found) error, as well as other errors, will make this return FALSE. Use this option to confirm that a web link is correct and active. |
IF Registry Key Exists
IF Process is Running
ELSE
| *Tip: The ELSE action is not required in an IF block. It is only necessary if you need to execute alternative steps when an IF evaluates to false. |
| *Tip: NOTE: "ELSE IF" is contained as an option inside of each "IF" check (meaning that any IF check can be turned into an ELSE IF check) |
END IF
| *Tip: The END IF action is always required when using an IF statement. If it is not included, vTask will still execute the script, but the results may not work as expected. |
