<< Prev        Next >>

ID : 137

If...Then...Else

Function

To perform conditional judgment of logical expression.

Syntax

If condition Then Statement [Else ElseStatement]

Guaranteed entry

Condition
Designate a Conditional Expression.
Statement
Designate statements to execute when the designated condition is True.
Else ElseStatement
Designate statements to execute when the designated condition is False. This is an optional value. Nothing is executed if the conditional expression is False when it is omitted.

Explanation

If the Conditional Expression designated in condition is True, Statement is executed.

If the Conditional Expression designated in condition is False, ElseStatement is executed when ElseStatement is designated.

If the Conditional Expression designated in condition is False, nothing is executed when ElseStatement is not designated.

Attention

-

Example

'!TITLE "Executing Conditional Judgment of Logical Expression"
' Determine a value for aaa and assign 1 if the value is 0, or double aaa if not
Sub Sample_IfThenElse

  Dim aaa As Integer
  aaa = 1

  If aaa = 0 Then aaa = 1 Else aaa = aaa * 2

  ' Display "1" on the message output window
  PrintDbg aaa

End Sub
If aaa > 0 Then Debug.Print "aaa is Plus" Else "aaa is Minus or 0"

ID : 137

<< Prev        Next >>