Lesson 1 - Introduction To Visual
Lesson 1 - Introduction To Visual
Thus, learning to create Visual Basic applications requires being very familiar with both
elements, visual and language.
The Visual Element
From a user’s standpoint, the visual part of an application is provided within a window. This is
the graphical interface that allows the user to see the input and output provided by the
application. This user interface is referred to as the graphical user interface (GUI). From a
programmer’s perspective the GUI is constructed by placing a set of visual objects on a blank
window, or form, when the program is being developed. For example, consider Figure 1–1, which
shows how a particular application would look to the user. From a programmer’s viewpoint, the
application shown in Figure 1–1 is based on the design form shown in Figure 1–2. The points
displayed on the form are a design grid used to arrange objects on the form and are only
displayed during design time.
Don’t be overwhelmed by all of the available controls. At a minimum, you will always have
the objects provided by the standard Toolbox available to you, and these are the ones we will be
working with. Once you learn how to place the basic control objects on a form, you will also
understand how to place the additional objects, because every object used in a Visual Basic
application, whether it is selected from a standard or purchased control, is placed on a form in
the same simple manner. Similarly, each and every object contains two basic characteristics:
properties and methods.
An object’s properties define particular characteristics of the object. For example, the
properties of a text box include the location of the text box on the form, the color of the box (the
background color), the color of text that will be displayed in the box (the foreground color), and
whether it is read-only or can also be written to by the user.
Methods are predefined procedures that are supplied with the object for performing
specific tasks. For example, you can use a method to move an object to a different location or
change its size.
Additionally, each object from the Toolbox recognizes certain actions. For example, a
button recognizes when the mouse pointer is pointing to it and the left mouse button is clicked.
These types of actions are referred to as events. In our example, we would say that the button
recognizes the mouse-click event. However, once an event is activated, we must write our own
procedures to do something in response to the event. This is where the language element of
Visual Basic comes into play.
The Language Element
Before the advent of GUIs, computer programs consisted entirely of a sequence of
instructions. Programming was the process of writing these instructions in a language to which
the computer could respond. The set of instructions and rules that could be used to construct a
program were called a programming language. Frequently, the word code was used to designate
the instructions contained within a program. With the advent of graphical user interfaces, the
need for code (program instructions) has not gone away—rather, it forms the basis for
responding to the events taking place on the GUI. Figure 1–4 illustrates the interaction between
an event and a program code.
As illustrated in Figure 1–4, an event, such as clicking the mouse on a button, sets in
motion a sequence of actions. If code has been written for the event, the code is executed;
otherwise the event is ignored. This is the essence of GUIs and event-driven applications—the
selection of executed code depends on what events occur, which ultimately depends on what
the user does. The programmer must still write the code that performs the desired action.
Visual Basic is a high-level programming language that supports all of the procedural
programming features found in other modern languages. These include statements to perform
calculations, permit repetitive instruction execution, and allow selection between two or more
alternatives.
With these basics in mind, it is now time to create our first Visual Basic application. In the next
section, we introduce the Visual Basic programming environment and create an application that uses
only a single object: the form itself. We will then add additional objects and code to create a more
complete Visual Basic application.