Professional Documents
Culture Documents
For example:
Dim Kuku As Boolean
Kuku = True
Dim YoYo As Boolean
YoYo = False
• InputBox
• In the next examples we want to receive a value from the user when the
program is running.
• To do so we will use the InputBox command.
The InputBox command syntax is:
VariableName = InputBox ("Text to Display")
• After executing this command, the variable will get the value that the user has
entered.
• Example:
• Put 1 Command button on your form and
• enter the following code to its click event:
Dim Elvis As String
Elvis = InputBox("Please Enter your name")
Print Elvis
• Run the program and click the button. A Message Box is appearing with the
• text "Please Enter your name“ as in Figure 1
Conditional Statements
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.
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
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
Using The "Not" Operator
• Lets see an example of using the operator "Not".
• Copy the following code to your Form_Load event:
Dim Password As String
Password = InputBox("Please enter the password")
If Not (Password = "let me in") Then
MsgBox "Incorrect Password!"
End
End If
The boolean expression: Not (Password = "let me in") is True only if the
Password is not "let me in". Why?