This document discusses various topics in VB including dialog boxes, timer controls, control arrays, and menus. It describes:
- How dialog boxes like msgbox and inputbox functions are used to exchange information with the user.
- The timer control and its interval property which is used to create applications with timed events.
- How control arrays allow grouping multiple controls of the same type with a common name and index property.
- The process for creating drop-down and pop-up menus through the menu editor including adding menu headings, items, shortcuts, and submenus.
3. DIALOG BOXES
Used to exchange information between the
program and user.
Contain common controls such as labels, text
boxes, option buttons, check boxes, command
buttons.
Commonly used dialog boxes are
MsgBox Function
InputBox Function
4. MsgBox Function
Used to display information during computation.
Displays a given output string with one or more
command buttons.
Syntax
integer variable = MsgBox(string,integer,title)
5. Function returns a positive integer depending on
the command button selected by the user.
String argument represents the string to be
displayed.
Integer argument represents the command
buttons that must appear.
Title argument is the string that appears on the
title bar of the dialog box
6. Integer Argument Named Constants Resulting
Command Buttons
0 vbOkonly OK
1 vbOkCancel OK & Cancel
2 vbAbortRetryIgnore Abort, Retry, Ignore
3 vbYesNoCancel Yes, No, Cancel,
4 vbYesNo Yes, No
5 vbRetryCancel Retry, Cancel
testmsg = MsgBox("Click to test", 1, "Test message")
Or
testmsg = MsgBox("Click to test", vbOkCancel, "Test message")
7.
8. Depending on the command button selected an
integer value is returned.
In the previous example
1 is returned to testmsg if OK button is selected
2 is returned to testmsg if Cancel is selected
Command Button Return Value
OK 1
Cancel 2
Abort 3
Retry 4
Ignore 5
Yes 6
No 7
9. InputBox Function
Used to accept an input.
Include
A string prompting the user for input
A textbox where the user can enter the input
Two command buttons- OK and Cancel
Syntax
String variable=InputBox(prompt, title,
default)
10. prompt
Represents the prompt for input.
Title
String that appears on the title bar of the box
Default
String that appear initially in the textbox of
InputBox
Empty if the last arguemnt is not included in the
function
11. n = InputBox("Enter the limit", "ARRAYS")
(In this example the last argument is omitted. 4 is
the input. )
The value returned to variable n is string. It can be
converted to integer using Val function
n = Val(InputBox("Enter the limit", "ARRAYS"))
12. Timer Control
Used to create application involving timed events
Digital clock, stop watch etc
Placed in the form during design time.
Does not appear on the form when the program is
executed.
13. Important property- Interval
Interval property is assigned with values ranging from
0 to 65,535.
0 value disables timer.
+ve value represents milliseconds
Eg- 1000 represents 1 second interval, 60000
represent 1 minute interval
14. Control Arrays
Array of controls.
Multiple controls of the same type can be
grouped into an array with a common name.
Each element is distinguished by the value of
index
Created by placing a control in the Form Window
and assigning value 0 to its index property.
Copy and paste control,with subsequent index
values(1,2,3….)
15. Draw a control in the control array.
While the control has the focus, choose Copy from
the Edit menu.
From the Edit menu, choose Paste. Visual Basic displays
a dialog box asking you to confirm that you want to create
a control array. Choose Yes to confirm the action. This
control is assigned an index value of 1. The first control you
drew has a value of 0.
The index value of each new array element corresponds to
the order in which the element was added to the control
array. When controls are added this way, most of the visual
properties, such as height, width, and color, are copied
from the first control in the control array to the new
controls.
20. Enter the caption & Name for each menu item
Caption will appear in the large area at the
bottom of the Menu Editor.
Example: Caption-Continents, name-
mnucontinents
Press Enter key or Click Next Button
Click the "right-arrow" button. A ellipsis (...) will
appear as the next item in the menu list,
indicating that this item is a level-two item.
The ellipsis is the indentation pattern that
distinguishes menu heading from menu items.
(The left arrow is for deleting indentation)
21. Now enter the sub menu items by entering the
caption and name.
Caption Name
Africa mnuAfrica
Antarctica mnuAntarctica
Asia mnuAsia
Australia mnuAustralia
Europe mnuEurope
22. Keyboard shortcuts can be added for accessing
menu from keyboard.
Keyboard shortcuts are selected directly from the
Shortcut field within the Menu editor.
Keyboard shortcuts must be unique.
24. Order of menu components
1. First menu heading
2. Corresponding menu items for first menu
3. Second menu heading
4. Corresponding menu items for second menu
and so on.
25. SUBMENU
To create submenu, indent the submenu items
beneath the parent menu item.
Menu item having submenu will be identified by a
right-pointing arrow at its edge.
26. POP UP MENU
Can appear anywhere in a form.
Appear in response to clicking the right mouse
button.
also called context menus
Created in the same manner as drop-down menu.
But the visible feature of the main menu item
will be unchecked
An event procedure must be entered as shown:
27. Select the code editor window.
Select Form in the left portion and MouseDown in
the right portion
The first and last lines of the event procedure will
be generated automatically.
Write the following code in the event procedure.
If Button=vbRightButton Then
PopupMenu <menuname>
End if
<menuname> must be the name of the menu (eg;
mnucontinents)