GRADE 9 REVIEWER ore buttons.
VbYesNoCancel 3 Displays the Yes, no, and Cancel
CREATING MESSAGE AND INPUT BOXES buttons.
VbYesNo 4 Displays the Yes and No buttons.
The Message Box () Function VbRetryCancel 5 Displays the Retry and Cancel buttons.
Here’s the format for the message box function:
Table 1.1 The Icons displayed in a message box.
MsgBox (Prompt, [Buttons} , [title] , [Help file], [context] Name literal Valu Description
e
Example: VbCritical 16 Displays the Critical Message icon.
MsgBox “This Message will close the program”, vbOKonly, VbQuestion 32 Displays the Query icon.
“Sample Message” VbExclamation 48 Displays the Warning icon
Or VbInformation 64 Displays the Information icon
MsgBox “This message will close the program”, 0, “Sample VbSystemmodal 409 Displays the System icon
Message” 6
NOTE: The Message box shown here requires one
You can also display icons on your message box by using the
(Prompt), one optional [Button] and one optional [Title].
values shown on the table. To display different buttons with the
The MsgBox () can accept more arguments, but these are
icons, simply add the value of the appropriate button.
the only ones needed in most applications. The button can
be a named literal (vbOKonly) pr its value equivalent (0). The Input Box () function
Format for the InputBox function:
The different arguments of the message Box function are: InputBox (Prompt, [Title], [Default], [XPos], [YPos], [Helpfile],
1. Prompt – the message or information displayed on the [Context] ) As string
message box.
2. Buttons & icons – allows you to insert the appropriate Example:
buttons and icons. InputBox “What is your name”, “Sample code”, “Larry”, “100, 100
3. Title – the message box title that appears on its title bar.
4. Help file – specifies the help file for the message box.
The different arguments of the InputBox function:
5. Function – accepts arguments and returns a single value.
6. Argument – is a value passed to a function, so the function 1. Prompt -displays your message or desired information.
has data to work with. 2. Title – specifies the window title shown on its little bar.
Table 1.0 The buttons displayed in a message box 3. Default – allows you to display a standard or automatic
Name literal Valu Description entry that appears in the input Text box.
e 4. XPos – indicates the vertical position of the window inside
VbOKonly 0 Displays the OK button. the screen.
VbOK Cancel 1 Displays the OK and Cancel buttons. 5. YPos – indicates the horizontal position of the window
VbAbortRetryIgn 2 Displays the Abort, Retry, and Ignore inside the screen.
INTRODUCTION TO INDEX AND CONTROL ARRAYS Using the ElseIF Clause
A control array is a list of the same type of control, all of If you have multiple conditions to check, you can also use the
which share the same name. Visual Basic automatically sets the ElseIf clause. Each condition is checked until a True condition is
index property of each of these controls to a unique value. The found.
index property plus the name of the control is now your
determinant to be able to distinguish one control from another.
Here’s the syntax:
A control array is a collection of identical interface objects.
Each object in the group shares the same object name and can be If <condition> Then <statement>
identified only by its index number. Creating array of controls only
ElseIf <condition 2> Then <statement 2>
requires the simple copy and paste technique.
ElseIF <condition 3> Then <statement 3>
USING CONDITIONAL LOGIC
End If
A conditional logic is an action that allows users to
manipulate an object in several ways. It uses term IF and ELSE to An “If statement” makes decisions. If a comparison test
describe the choices available to the object as the user is true, the body of the If statement is executed. If you have
manipulates it. multiple conditions, you use the “ElseIf” statement. “End If”
lets Visual Basic know where the body of the if statement ends.
NOTE: The Ampersand (&) symbol links together or
concatenates the series of values in a statement.
Using If…Then..statement
The If…Then decision structure lets you evaluate a condition in
the program and take a course of action based on the result.
The If….Then statement is terminated with an End If statement.
Syntax for One-line If…Then statement:
If <condition> Them <statement>
Where condition is a conditional expression and statement is a
valid Visual Basic program statement.