|
|
 |
 |
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
Chapter 1 Visual Basic Overview
Welcome to our big book on Visual Basic. Its no secret that Visual Basic is the favorite programming environment of many programmers. (In fact, youre reading a book written by one of those programmers right now.) When Visual Basic first appeared, it created a revolution in Windows programming, and that revolution continues to this day. Never before had Windows programming been so easyjust build the program you want, right before your eyes, and then run it. Visual Basic introduced unheard-of ease to Windows programming and changed programming from a chore to something very fun.
In time, Visual Basic has gotten more complex, as well as more powerful. In this book, were going to see how to use Visual Basic in a task-oriented way, which is the best way to write about programming. Instead of superimposing some abstract structure on the material in this book, well organize it the way programmers want ittask by task.
This book assumes you have some familiarity with Visual Basic; when you use this book, youll usually have some task in mindsetting a programs startup form, for example, or optimizing for a specific processorand this book will provide the answer. Well try to be as complete as possible (unlike the frustrating recordings of frequently asked questionswhich never seem to address your particular problemyou can access while on hold for tech support). This book is designed to be the one you come back to time and time again. Its not just to learn new techniques, but it is also to reacquaint yourself with the forgotten details of familiar methods.
Well start with an overview of Visual Basic, taking a look at topics common to the material in the rest of the text. In this chapter, well create the foundation well rely on later as we take a look at the basics of Visual Basic, including how to create Visual Basic projects and seeing whats in such projects. Well also get an overview of essential Visual Basic concepts like forms, controls, events, properties, methods, and so on. And well examine the structure of a Visual Basic program, taking a look at variables, variable scope, and modules. In other words, were going to lay bare the anatomy of a Visual Basic program here.
Well also take a look at programming practices common to all Visual Basic programs. This overview chapter is the place to take a look at those practices because they involve the rest of the book.
Most Visual Basic programmers do not have formal programming training and have to learn a lot of this material the hard way. As programming has matured, programmers have learned more and more about what are called best practicesthe programming techniques that make robust, easily debugged programs. Well take a look at those practices in this chapter, because they are becoming more and more essential for programmers in commercial environments these days, especially those programmers that work in teams. And well look at those practices from the viewpoint of programmers who program for a living; frequently theres a gap between the way best practices are taught by academics and how they are actually needed by programmers facing the prospect of writing a 20,000-line program as part of a team of programmers.
Well start our overview chapter by creating and dissecting a Visual Basic project, jumping right into the code.
Creating A Project In Visual Basic
There are three different editions of Visual Basic:
- The Learning Edition, which is the most basic edition. This edition allows you to write many different types of programs, but lacks a number of tools that the other editions have.
- The Professional Edition, designed for professionals. This edition contains all that the Learning Edition contains and more, such as the capability to write ActiveX controls and documents.
- The Enterprise Edition, which is the most complete Visual Basic edition. This edition is targeted towards professional programmers who may work in a team and includes additional tools such as Visual SourceSafe, a version-control system that coordinates team programming.
Well use the Enterprise Edition in this book, so if you have either of the other two editions, we might occasionally use something not supported in your Visual Basic edition. Well try to keep such occurrences to a minimum.
Start Visual Basic now, bringing up the New Project dialog box, as shown in Figure 1.1.
Figure 1.1 Creating a new Visual Basic project.
In Figure 1.1 you see some of the project types that Visual Basic supports:
- Standard Windows EXE programs
- ActiveX EXE files
- ActiveX DLLs
- ActiveX controls
- Programs written by the Visual Basic Application Wizard
- Data projects
- IIS (the Microsoft Internet Information Server) applications
- Visual Basic add-ins
- ActiveX document DLLs
- ActiveX document EXE files
- DHTML applications
- VB Enterprise Edition controls
This list of project types indicates some of the ways Visual Basic has grown over the years. As you can see, theres a whole galaxy of power here (and well cover that galaxy in this book). In this case, we just want to take a look at the basics of a standard Visual Basic project, so double-click the Standard EXE item in the New Project dialog box, opening Visual Basic itself. Figure 1.2 shows the Visual Basic Integrated Development Environment (IDE). (Were going to cover all parts of the Visual Basic Integrated Development Environment in the next chapterhere, well just use it to create our first project.)
Figure 1.2 A new Visual Basic project.
For our first example, we might create a small tic-tac-toe program using nine buttons in a form, as shown in Figure 1.3.
Figure 1.3 Designing our first project.
When the user clicks a button, we can display an x in the buttons caption, as shown in Figure 1.4.
Figure 1.4 Clicking a button in the tic-tac-toe program to display an x.
If the user clicks another button, we can display an o, and so forth.
This example will create a program that lets us take a look at Visual Basic projects, controls, control arrays, events, properties, coding, variables, and variable scope.
|