This chapter is designed to give you an introduction to visual Basic and how it differs from other programming languages you may have used. While this chapter does assume knowledge of programming techniques and concepts,it assumes no knowledge of Visual Basic. If you have already used Visual Basic, you may just want to skim this chapter to make sure you understand everything covered.Before you begin learning how to use Visual Basic 6, it's important that you understand a little bit about how the product developed. Before Microsoft Windows 3.0 was introduced in May 1990, application programming for IBM-compatible PCs was a very boring proposition--all text with no concept of a mouse or a window. Some enterprising programmers created toolkits to create window-like atmospheres using IBM's extended character set, which included graphical characters such as line segments and partially shaded characters.
However, after the introduction of Microsoft Windows for IBM-compatible PCs, PC programmers had a whole newworld to explore. Application programs such as Microsoft Word and Excel gave programmers ideas for their own applications, including features such as the following:
Toolbars
Multiple windows within an application's window
Basic support for multiple applications running simultaneously
Unfortunately, programming these features was time-consuming and confusing. The only languages that were available were traditional languages, such as Basic, COBOL, and C. Microsoft did have a product called QuickBasic, which was fairly popular among Basic programmers. QuickBasic could run old Basic programs that used line numbers and lots of GOTO statements, but it was better than Basic. It supported many additional language concepts, but it could not create Windows applications. It did not support the Windows API (application programming interface), which specified how to create windows, graphics, and the other components used in Windows applications.
Windows introduced the concept of amessage. Every action you perform in Windows generates one or more messages. For instance, if the user moves the mouse across the screen, a series of messages are generated for each position the mouse occupies while it is being moved. If the user moves the mouse over the window for an application that is running, Windows sends these messages to that application. The application then has to determine if the user is doing something within itself, or if the user is just "passing through." Every application has to look at every message sent by Windows and make this determination. The code required to make this work is lengthy and complex, to say the least.
Besides having to handle simple messages such as mouse movements, a Windows application also has to handle complex actions, such as when the user moves a window from one place to another. Windows tells your program what the user is doing, but it doesn't do any of the work of handling the user's action for you. Your application has to repaint your windows in anew position, for instance. Even after you have dealt with all the Windows messages you might receive, you're still not done. Your program still has to have code to handle all of your application's features.
Visual Basic revolutionised all this tedious code. Instead of a programmer's having to write lengthy code to make a window respond to a mouse, Visual Basic handled all those actions and hid them from the programmer. To indicate to your program that the user clicked the mouse, Visual Basic provides an event instead of a series of messages. You then write code to respond to the event and not the message. This is an important distinction.
An event, when translated into Windows messages, could consist of one or more messages. Even a simple action such as a mouse click actually consists of more than one Windows message.
With the introduction of the event, Visual Basic programmers could concentrate on writing the application's features and not worry about the low-level things such as why a button clickworked. They could simply write the code to run when a button was clicked. The code that runs when the user clicks a button (or any other event, for that matter) is known as an event handler. Besides hiding the complexities of Windows messaging, Visual Basic also provided a design environment in which the programmer could draw an application's windows instead of writing code to create them. Want a button on your form? Pick it from the Visual Basic Toolbox and draw it on your window. Button not quite in the right place? Grab it with your mouse and drag it to the correct position.
This ability to rapidly draw the interfaces of an application made Visual Basic into an excellent tool for creating prototypes. A prototype is a preliminary version of an application used for discussion among designers. For consultants, a prototype is an excellent way to show your client what the application might look like. With Visual Basic, you could even add simple code to cause one window to flow into the next. Speaking frompersonal experience, it is much easier to let your client interact with a real live application instead of one on paper. Besides being able to see how the windows work, the user might also suggest changes in functionality before you even start writing your application.
Since its introduction in 1991, Visual Basic has become the most popular programming language among professional programmers. Over half of the programmers in the United States report VB as their primary language. Besides its popularity among programmers, Visual Basic has also created an entire industry: the third-party component market. Components can be added to the Visual Basic environment to provide features not currently available in the Visual Basic product. Literally hundreds of components are available from third parties that provide features such as geographic mapping, complex mathematical processing, and more. By taking advantage of the reusability of component software, you can make your programs much quicker to build andmaintain.
VISUAL BASIC 6 PROGRAMMING BIBLE
Eric A Smith, Valor Whisler and Hank Marquis
Published by Comdex Computer Publishing
Price: Rs 395 (with CD).
Copyright © 1998 Indian Express Newspapers (Bombay) Ltd.