If
This command executes one of two blocks of statements based on a conditional expression. If expression is True, the program executes the first group of statements. If the expression is False, the program executes the second group of statements.
When using this statement, remember the following:
- The Else clause is optional.
- The structure can occupy either a single line or several lines.
When coding single and multi-line statements, remember the following:
- The single-line form does not require an EndIf before the Else.
- In the multi-line form, each clause must contain at least one statement.
Syntax
If expr Then
Parameters
The following table describes the parameters of the If command:
| Parameter | Description |
|---|---|
| expression | An expression that evaluates to True or False |
| Then | The word “then”; mandatory |
Examples
The following example shows the syntax of a one-line script statement:
If IsShown(General_Bar) Then; MessageBox "Shown"; Else MessageBox "Not
Shown"; EndIfThe following
example
is part of the COPYMENU.WIS demonstration program.
* Copy Text to Notepad
Sub CopyTextNotepad()
If Not(IsApp("notepad.exe")) Then
Dialog RunProgram
Set Filename = 'notepad.exe'
Set Arguments = ''
Invoke
EndIf
title_text = "Untitled - Notepad"
If IsTask(title_text) Then
Invoke EditCopy
Activate title_text
SendKeys "^V" ;* Paste key for notepad
Else
MessageBox "This example copies to ":title_text:" only","Copy To Notepad"
EndIf
EndSubRelated Script Commands
And, Or