Conditional Statements Tutorial

Lesson 1
Tutorials - Page 1 - Page 2 - Page 3 - Page 4 - Page 5 - Page 6 - Page 7 - Page 8 - Page 9 - Page 10

Using "And" and "Or" In Boolean Expressions (Continue)
The "And" operator is similar to the "Or"
operator, except it has different Effects on boolean expressions:

True And True = True
True And False = False
False And True = False
False And False = False

When using the "And" operator, the
expression will be True only if both
boolean expressions are True.

For example, copy the following code
to your Form_Load event:


Dim UserName As String
Dim Password As String

UserName = InputBox("Please enter the user name")
Password = InputBox("Please enter the password")
If (Password = "let me in") And (UserName = "elvis") Then
   MsgBox "The login is correct!"
Else
   MsgBox "Incorrect Login!"
   End
End If



This code will pop up two InputBoxes.
The first will ask you to enter the user name,
and the second will ask you to enter the password.
The login will be correct only if both user name
and password are correct.

The boolean expression (Password = "let me in") And (UserName = "elvis")
is True only if (Password = "let me in") is True, and
(UserName = "elvis") is True, because
True And True = True, and any other
combination is equal to False.

Back  Forward