Section 1.4. An Introduction to Visual Basic 2005


[Page 18 (continued)]

1.4. An Introduction to Visual Basic 2005

Visual Basic 2005 is one of the most exciting developments in programming in many years. It is the latest generation of Visual Basic, a language used by millions of software developers.

Visual Basic was designed to make user-friendly programs easier to develop. Prior to the creation of Visual Basic, developing a friendly user interface usually required a programmer to use a language such as C or C++, often requiring hundreds of lines of code just to get a window to appear on the screen. Now the same program can be created with much less time and fewer instructions using a language that is a direct descendant of BASICthe language most accessible to beginning programmers.

Visual Basic requires the Microsoft Windows operating system. Although you don't need to be an expert user of Microsoft Windows, you do need to know the basics before you can master Visual Basicthat is, you need to be comfortable with manipulating a mouse, you need to know how to manipulate a window, and you need to know how to use Notepad and Windows Explorer. However, there is no better way to master Microsoft Windows than to write applications for itand that is what Visual Basic is all about.

Why Windows and Why Visual Basic?

What people call graphical user interfaces, or GUIs (pronounced "gooies"), have revolutionized the computer industry. Instead of the confusing prompts that earlier users once saw, today's users are presented with a desktop filled with little pictures called icons. Icons provide a visual guide to what a program does or is used for.

Accompanying the revolution in how programs look was a revolution in how they feel. Consider a program that requests information for a database. Figure 1.6 shows how a program written before the advent of GUIs got its information. The program requests the six pieces of data one at a time, with no opportunity to go back and alter previously entered information. Then the screen clears and the six inputs are again requested one at a time. Figure 1.7 shows how an equivalent Visual Basic program gets its information. The boxes may be filled in any order. When the user clicks on a box with the mouse, the cursor moves to that box. The user can either type in new information or edit the existing information. When the user is satisfied that all the information is correct, he or she just clicks on the Write to Database button. The boxes will clear, and the data for another person can be entered. After all names have been entered, the user clicks on the Exit button. In Figure 1.6, the program is in control; in Figure 1.7, the user is in control!


[Page 19]

Figure 1.6. Input screen of a pre-VB program to fill a database.

Enter name (Enter EOD to terminate): Mr. President

Enter Address: 1600 Pennsylvania Avenue

Enter City: Washington

Enter State: DC

Enter Zipcode: 20500

Enter Phone Number: 202-456-1414


Figure 1.7. Input screen of a Visual Basic program to fill a database.


How You Develop a Visual Basic Application

One of the key elements of planning a Visual Basic application is deciding what the user seesin other words, designing the screen. What data will he or she be entering? How large a window should the application use? Where will you place the buttons the user clicks on to activate the applications? Will the applications have places to enter text (text boxes) and places to display output? What kind of warning boxes (message boxes) should the application use? In Visual Basic, the responsive objects a program designer places on windows are called controls. Two features make Visual Basic different from traditional programming tools:

  1. You literally draw the user interface, much like using a paint program.

  2. Perhaps more important, when you're done drawing the interface, the buttons, text boxes, and other objects that you have placed in a blank window will automatically recognize user actions such as mouse movements and button clicks.


    [Page 20]

    That is, the sequence of procedures executed in your program is controlled by "events" that the user initiates rather than by a predetermined sequence of procedures in your program.

In any case, only after you design the interface does anything like traditional programming occur. Objects in Visual Basic recognize events like mouse clicks; how the objects respond to them depends on the instructions you write. You always need to write instructions in order to make controls respond to events. This makes Visual Basic programming fundamentally different from conventional programming.

Programs in traditional programming languages ran from the top down. For these programming languages, execution started from the first line and moved with the flow of the program to different parts as needed. A Visual Basic program works differently. Its core is a set of independent groups of instructions that are activated by the events they have been told to recognize. This event-driven methodology is a fundamental shift. The user decides the order in which things happen, not the programmer.

Most of the programming instructions in Visual Basic that tell your program how to respond to events like mouse clicks occur in what Visual Basic calls event procedures. Essentially, anything executable in a Visual Basic program either is in an event procedure or is used by an event procedure to help the procedure carry out its job. In fact, to stress that Visual Basic is fundamentally different from traditional programming languages, Microsoft uses the term project, rather than program, to refer to the combination of programming instructions and user interface that makes a Visual Basic application possible.

Here is a summary of the steps you take to design a Visual Basic application:

1.

Design the appearance of the window that the user sees.

2.

Determine the events that the controls on the window should recognize.

3.

Write the event procedures for those events.

Now here is what happens when the program is running:

1.

Visual Basic monitors the controls in the window to detect any event that a control can recognize (mouse movements, clicks, keystrokes, and so on).

2.

When Visual Basic detects an event, it examines the program to see if you've written an event procedure for that event.

3.

If you have written an event procedure, Visual Basic executes the instructions that make up that event procedure and goes back to Step 1.

4.

If you have not written an event procedure, Visual Basic ignores the event and goes back to Step 1.

These steps cycle continuously until the application ends. Usually, an event must happen before Visual Basic will do anything. Event-driven programs are reactive more than activeand that makes them more user friendly.


[Page 21]

The Different Versions of Visual Basic

Visual Basic 1.0 first appeared in 1991. It was followed by version 2.0 in 1992, version 3.0 in 1993, version 4.0 in 1995, version 5.0 in 1997, and version 6.0 in 1998. VB.NET, initially released in February 2002, was not backward compatible with the earlier versions of Visual Basic. It incorporated many features requested by software developers, such as true inheritance and powerful Web capabilities. Visual Basic 2005, released in November 2005, is a significantly improved version of VB.NET.




An Introduction to Programming Using Visual Basic 2005
Introduction to Programming Using Visual Basic 2005, An (6th Edition)
ISBN: 0130306541
EAN: 2147483647
Year: 2006
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net