Procedures:
Visual Basic application
is made up of small, self-contained segments. It will be made up of small
segments called procedures. Procedures are useful for implementing
repeated tasks, such as frequently used calculations.
Creating
a Sub Procedure
|
|
Calling a Sub Procedure
- Display the form
- Double-click the bottom
Calculate button and, in its body, type SquareArea
Private Sub cmdCalcArea_Click()
SquareArea
End Sub
|
- Text the application
Answer-22(b): In Visual Basic, the Form is the container for all the controls that make up the user interface. When a Visual Basic application is executing, each window it displays on the Desktop is a Form. The Form is the top-level object in a Visual Basic application, and every application starts with the Form.
The
Appearance of Forms: The main
characteristic of a Form is the title bar on which the form’s caption is
displayed. On the left end of the title bar is the Control Menu icon. Clicking
this icon opens the Control menu. On the right side of the title bar are three
buttons: Minimize, Maximize, and Close. Clicking these buttons performs the
associated function.
You can customize the appearance of
the Form with the following Form properties:
• MinButton,
MaxButton These two properties are True by default. Set them to False to
hide the corresponding buttons on the title bar.
• ControlMenu
This property is also True by default. Set it to False to hide the icon and
disable the Control menu. Although the Control menu is rarely used, Windows
applications don’t disable it.
When the ControlMenu property is False, the three buttons on the title bar are also disabled. If you set the Caption property to an empty string, the title bar disappears altogether.
When the ControlMenu property is False, the three buttons on the title bar are also disabled. If you set the Caption property to an empty string, the title bar disappears altogether.
• BorderStyle
The BorderStyle property determines the style of the Form’s border and the
appearance of the Form.
|
|||
VALUE
|
CONSTANT
|
DESCRIPTION
|
|
|
|||
0–None
|
vbBSNone
|
Form has no border and can’t be
resized; this setting should be avoided
|
|
1–Fixed Single
|
vbFixedSingle
|
Form has a visible border, but
can’t be resized
|
|
2–Sizable
|
vbSizable
|
Border and a title bar and can be
repositioned on the Desktop and resized
|
|
3–Fixed Dialog
|
vbFixedDialog
|
Fixed dialog box
|
|
4–Fixed ToolWindow
|
vbFixedToolWindow
|
Form has a Close button only and
can’t be resized; looks like a toolbar
|
|
5–Sizable ToolWindow
|
vbSizableToolWindow
|
Same as the Fixed ToolWindow, but
can be resized
|
|
|
|||
Loading and
Unloading Forms: To load and unload Forms, use the Load and Unload
statements. The Load statement has the following syntax: Load formName
and the Unload
statement has this syntax: Unload formName
Showing Forms: To show a Form, you use the Show method. If the Form
is loaded but invisible, the Show method brings the specified Form on top of
every other window on the Desktop. If the Form isn’t loaded, the Show method
loads it and then displays it. The Show method has the following syntax: formName.Show mode
The formName variable is the
Form’s name, and the optional argument mode determines whether the Form
will be modal or modeless. It can have one of the following values:
• 0–Modeless (default)
• 1–Modal
Modeless Forms are the norm. They
interact with the user, and they allow the user to switch to any other Form of
the application. If you don’t specify the optional mode argument, the
Show method displays the Form as modeless.
A modal Form takes total control of
the application and won’t let the applications proceed unless the Form is
closed. A modal Form, therefore, must have a Close button or some means for the
user to close it so that they can return to the Form from which the modal Form
was loaded
Hiding Forms:
If your application uses many Forms, you may want to hide some of them to
make room on the Desktop for others. To hide a Form, use the Form’s Hide
method, whose syntax is: Form.Hide