Chapter One
Welcome to Visual Basic 2008
This is an exciting time to enter the world of programming with Visual Basic 2008 and Windows Vista. Windows Vista represents the first Windows operating system upgrade since Windows XP was first released in 2002. A lot has changed in the Windows user interface and Visual Basic 2008 makes it easy to write professional-looking Windows applications as well as web applications and web services. Haven''t upgraded to Windows Vista yet? No worries, Visual Basic 2008 also allows you to write professional-looking applications for Windows XP as well.
The goal of this book is to help you use the Visual Basic 2008 programming language, even if you have never programmed before. You will start slowly and build on what you have learned in subsequent chapters. So take a deep breath, let it out slowly, and tell yourself you can do this. No sweat! No kidding!
Programming a computer is a lot like teaching a child to tie his shoes. Until you find the correct way of giving the instructions, not much is accomplished. Visual Basic 2008 is a language you can use to tell your computer how to do things. But, like a child, the computer will understand only if you explain things very clearly. If you have never programmed before, this sounds like an arduous task, and sometimes it can be. However, Visual Basic 2008 gives you an easy-to-use language to explain some complex tasks. Although it never hurts to have an understanding of what is happening at the lowest levels, Visual Basic 2008 frees the programmer from having to deal with the mundane complexities of writing Windows applications. You are free to concentrate on solving real problems.
Visual Basic 2008 helps you create solutions that run on the Microsoft Windows operating systems, such as Windows Vista, Windows Server 2008, and Windows Mobile 6. If you are looking at this book, you might have already felt the need or desire to create such programs. Even if you have never written a computer program before, as you progress through the Try It Out exercises in this book, you will become familiar with the various aspects of the Visual Basic 2008 language, as well as its foundations in the Microsoft .NET Framework. You will find that it is not nearly as difficult as you had imagined. Before you know it, you will feel quite comfortable creating a variety of different types of programs with Visual Basic 2008.
Visual Basic 2008 can also be used to create web applications and web services as well as mobile applications that can run on Pocket PCs or SmartPhones. However, you will begin by focusing on Windows applications before extending your boundaries to other platforms.
This chapter covers the following topics:
Event-driven programming The installation of Visual Basic 2008 A tour of the Visual Basic 2008 Integrated Development Environment (IDE) How to create a simple Windows program How to use the integrated Help system
Event-Driven Programming
A Windows program is quite different from yesteryear''s MS-DOS program. A DOS program follows a relatively strict path from beginning to end. Although this does not necessarily limit the functionality of the program, it does limit the road the user has to take to get to it. A DOS program is like walking down a hallway; to get to the end you have to walk down the hallway, passing any obstacles that you may encounter. A DOS program would only let you open certain doors along your stroll.
Windows, on the other hand, opened up the world of event-driven programming. Events in this context include clicking a button, resizing a window, or changing an entry in a text box. The code that you write responds to these events. In terms of the hallway analogy: In a Windows program, to get to the end of the hall, you just click the end of the hall. The hallway can be ignored. If you get to the end and realize that is not where you wanted to be, you can just set off for the new destination without returning to your starting point. The program reacts to your movements and takes the necessary actions to complete your desired tasks.
Another big advantage in a Windows program is the abstraction of the hardware; which means that Windows takes care of communicating with the hardware for you. You do not need to know the inner workings of every laser printer on the market just to create output. You do not need to study the schematics for graphics cards to write your game. Windows wraps up this functionality by providing generic routines that communicate with the drivers written by hardware manufacturers. This is probably the main reason that Windows has been so successful. The generic routines are referred to as the Windows application programming interface (API), and the classes in the .NET Framework take care of communicating with those APIs.
Before Visual Basic 1.0 was introduced to the world in 1991, developers had to be well versed in C and C++ programming, as well as the building blocks of the Windows system itself, the Windows API. This complexity meant that only dedicated and properly trained individuals were capable of turning out software that could run on Windows. Visual Basic changed all of that, and it has been estimated that there are now as many lines of production code written in Visual Basic as in any other language.
Visual Basic changed the face of Windows programming by removing the complex burden of writing code for the user interface (UI). By allowing programmers to draw their own UI, it freed them to concentrate on the business problems they were trying to solve. When the UI is drawn, the programmer can then add the code to react to events.
Visual Basic has also been extensible from the very beginning. Third-party vendors quickly saw the market for reusable modules to aid developers. These modules, or controls, were originally referred to as VBXs (named after their file extension). Prior to Visual Basic 5.0, if you did not like the way a button behaved, you could either buy or create your own, but those controls had to be written in C or C++. Database access utilities were some of the first controls available. Version 5 of Visual Basic introduced the concept of ActiveX, which allowed developers to create their own ActiveX controls.
When Microsoft introduced Visual Basic 3.0, the programming world changed significantly. Now you could build database applications directly accessible to users (so-called front-end applications) completely with Visual Basic. There was no need to rely on third-party controls. Microsoft accomplished this task with the introduction of Data Access Objects (DAO), which allowed programmers to manipulate data with the same ease as manipulating the user interface.
Versions 4.0 and 5.0 extended the capabilities of Version 3.0 to allow developers to target the new Windows 95 platform. They also made it easier for developers to write code, which could then be manipulated to make it usable to other language developers. Version 6.0 provided a new way to access databases with the integration of ActiveX Data Objects (ADO). The ADO feature was developed by Microsoft to aid web developers using Active Server Pages (ASP) to access databases. All of the improvements to Visual Basic over the years have ensured its dominant place in the programming world - it helps developers write robust and maintainable applications in record time.
With the release of Visual Basic .NET in February 2002, most of the restrictions that used to exist have been obliterated. In the past, Visual Basic was criticized and maligned as a "toy" language, because it did not provide all of the features of more sophisticated languages such as C++ and Java. Now, Microsoft has removed these restrictions and made Visual Basic .NET a very powerful development tool. This trend has continued with the release of Visual Basic 2003, Visual Basic 2005, and the latest release, Visual Basic 2008. Each new release of the Visual Basic .NET programming language brings about many new trends, features, and improvements, making it a great choice for programmers of all levels.
Installing Visual Basic 2008
You may own Visual Basic 2008 in one of the following forms:
As part of Visual Studio 2008, a suite of tools and languages that also includes C# (pronounced C-sharp) and Visual C++. The Visual Studio 2008 product line includes Visual Studio Professional Edition or Visual Studio Tools Team Editions. The Team Edition versions come with progressively more tools for building and managing the development of larger, enterprise-wide applications. As Visual Basic 2008 Express Edition, which includes the Visual Basic 2008 language, and a reduced set of the tools and features that are available with Visual Studio 2008.
Both of these products enable you to create your own applications for the Windows platform. The installation procedure is straightforward. In fact, the Visual Studio Installer is smart enough to figure out exactly what your computer requires to make it work.
The descriptions in the following Try It Out exercise are based on installing Visual Studio 2008 Professional Edition. Most of the installation processes are straightforward, and you can accept the default installation options for most environments. So, regardless of which edition you are installing, the installation process should be smooth when accepting the default installation options.
Try It Out Installing Visual Basic 2008
1. The Visual Studio 2008 DVD has an auto-run feature, but if the Setup screen does not appear after inserting the DVD, you need to run Setup.exe from the root directory of the DVD. To do this, click the Windows Start menu at the bottom left of your screen and then select the Run start menu item or browse to the Setup program on the DVD. In the Run dialog box, you can click the Browse button to locate the setup.exe program on your DVD. Then click the OK button in the Run dialog box to start the setup program. After the setup program initializes, you will see the initial screen as shown in Figure 1-1.
2. The dialog box shown in Figure 1-1 shows the order in which the installation will occur. To function properly, Visual Studio 2008 requires various updates to be installed depending on the operating system that you have (for example, Service Pack 2 on Windows XP). The setup program will automatically inform you of these updates if they are not installed. You should install those updates first and then return to the Visual Studio 2008 setup program. The individual updates required are different from the service releases listed as the third option in Figure 1-1. Step 1 of the setup program will install Visual Studio 2008 so click the Install Visual Studio 2008 link shown in Figure 1-1.
3. The next step in the installation process asks you if you want to send the setup information from the installation of Visual Studio 2008 to Microsoft. This is a good idea to help streamline the installation process of future editions of Visual Studio, and no personal information will be sent. You can click the Next button at this screen after you have selected or cleared the check box indicating whether or not you want this information sent.
4. The third step in the installation process is the license agreement. Read the license agreement and then select the option button indicating your acceptance of the licensing terms. Then click the Next button to continue.
5. As with most setup programs, you are presented with a choice of options to be installed as shown in Figure 1-2. The default installation installs the recommended product features as determined by Microsoft. You have the option to choose the default installation, a full installation, or to customize the installation. When choosing the custom installation feature, you will be presented with a dialog box allowing you to choose the languages and features of each language to be installed. If disk space allows, it is recommended that you choose a full installation. However, if you choose to customize the installation and omit some features from being installed, you can always install those features later by rerunning the setup program. After choosing your installation option, click the Install button to have those features installed.
6. The first component that is installed is the Microsoft .NET Framework version 3.5. During the installation of this component you will be required to restart your computer. After your computer has restarted and you log back in, the setup program will continue. Note to Windows Vista users: you will be prompted that the setup program needs to run and will need to grant permission to let the setup program continue. After the setup program continues, you can sit back and relax while all of the features are being installed. The setup program can take anywhere from 20 minutes on up depending on the installation features chosen and the speed of your computer.
7. Once the installation has been completed, you will be presented with a dialog box informing you of the status of the installation. Here you can see any problems that the setup program encountered. At this point you are encouraged to update your computer with the latest security patches and a link is provided in the notes to Windows Update. When you have finished reviewing the setup status, click the Finish button to move on to the next step.
8. If you chose to have your setup information sent to Microsoft, the next step will be a dialog box sending the setup information. This dialog box requires no action on your part and it will automatically close when finished. The next dialog box is the one shown earlier in Figure 1-1 with the option to install the production documentation enabled. Click the Install Product Documentation link to install the MSDN library.
9. The first step in installing the MSDN library is choosing whether to send the setup information to Microsoft. Make the appropriate choice and then click the Next button to continue. Again, it is recommended to send this information to help streamline future MSDN library installations.
10. Next, read and accept the license agreement. After you click the option button to accept the license agreement, click the Next button to continue.
11. Like the installation of Visual Studio 2008, the MSDN library installation provides you with the options to choose the installation that best suits your needs, as shown in Figure 1-3. If you chose to install the complete Visual Studio 2008 product set then you''ll most likely want to choose the full installation of the MSDN library. After making your installation option choice, click the Install button to begin the installation.
If you have the spare hard drive space, it is a very good idea to install the full documentation. That way you have access to the full library, which will be important if you choose a limited set of options during the install and later add more features.
12. After the MSDN documentation has been installed, you are presented with a dialog box informing you of the status of the installation. Click the Finish button to be returned to the initial setup screen again. The Check for Service Releases option is now available.
It is a good idea to select Service Releases to check for updates. Microsoft has done a good job of making software updates available through the Internet. These updates can include anything from additional documentation to bug fixes. You will be given the choice to install any updates through a Service Pack CD or the Internet. Obviously, the Internet option requires an active connection. Since updates can be quite large, a fast connection is highly recommended.
* * *
After you have performed the update process, Visual Studio 2008 is ready to use. Now the real fun can begin! So get comfortable, relax, and enter the world of Visual Basic 2008.
(Continues...)
Excerpted from Beginning Microsoft Visual Basic 2008by Thearon Willis Bryan Newsome Copyright © 2008 by Thearon Willis. Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.