If...Then...Else


You can use an If...Then...Else block to define several blocks of statements, one of which will execute:

If condition1 Then
[statementblock-1]
[ElseIf condition2 Then
[statementblock-2]] ...
[Else
[statementblock-n]]
End If

Visual Basic first tests condition1. If it’s False, Visual Basic proceeds to test condition2, and so on, until it finds a True condition. When it finds a True condition, Visual Basic executes the corresponding statement block and then executes the code following the End If. As an option, you can include an Else statement block, which Visual Basic executes if none of the conditions are True.

Private Sub mnuCut_Click (Index As Integer)

If Index = 0 Then ' Cut command.

CopyActiveControl ' Call general procedures.

ClearActiveControl

ElseIf Index = 1 Then ' Copy command.

CopyActiveControl

ElseIf Index = 2 Then ' Clear command.

ClearActiveControl

Else ' Paste command.

PasteActiveControl

End If

End Sub

No comments:

Post a Comment