This unit helps you install the Visual Basic Working Model programming system that comes with this book. You will find that the installation of Visual Basic is easy because Windows 95 does most of the work for you. If you've installed other Windows programs before, you will have no trouble with installing Visual Basic.
Warning: This book assumes that you have used Windows 95 or Windows NT before. Although you might not be a Windows 95 or NT guru, you should be comfortable with starting and stopping Windows 95 or NT, using the mouse, selecting from Windows 95 or NT menus, and so on. Most of the time, this book will refer to Windows 95 and Windows NT generically as simply Windows.
Tip: If you want a good review of Windows 95 fundamentals, get a copy of Alpha Books' The Complete Idiot's Guide to Windows 95 (ISBN 0-7897-0403-X) and read it before going further with Visual Basic 4 in 12 Easy Lessons. You'll be glad you did.
Before installing the program, this unit takes a few moments to describe exactly what you get with the bundled CD-ROM.
Concept: With this book, you get a Visual Basic programming system with which you can learn Visual Basic and create your own Windows programs.
The Microsoft Corporation has released several versions of Visual Basic. When version 1.0 hit the market, Visual Basic changed the way in which people viewed Windows programming. Even in its first release, Visual Basic was a powerful programming tool for introductory Windows programmers. With its visual placement of program and screen elements, you will literally draw programs instead of writing them. With every release of Visual Basic, Microsoft keeps adding more functionality and programming power.
This book contains the Visual Basic version 4.0 programming system. This version of Visual Basic is called the Visual Basic Working Model Edition. It includes everything in the original Visual Basic version 4.0 Edition except for these modifications:
In addition, this book's CD-ROM also contains a special HTML document (that's Internet lingo for HyperText Markup Language) on the CD-ROM that has links to common Visual Basic resources on the Internet, including Microsoft's Visual Basic Web site, Visual Basic magazines, personal Visual Basic pages, and even some Visual Basic code repositories where you can find interesting samples and demonstrations of Visual Basic applications.
DefinitionA compiler creates a stand-alone program.
When you buy a copy of Visual Basic 4and pay a whole lot more money than you did for this book and CD-ROM!you get everything you get here plus a compiler. This copy of Visual Basic enables you to create the same programs as the regular copy, but you must run those programs from within the Visual Basic Working Model environment. In other words, when you want to run the program that you write, you have to start the Visual Basic Working Model first and use the Visual Basic Working Model menus to load and run your program.
For most beginning and intermediate programmers, the second modification is not much of a limitation. You can add only two forms, modules, or classes to a program. One or two forms, or possibly one form and one module, are probably all you would be using anyway for a long time. It sometimes takes a fairly complicated Visual Basic program to require multiple forms or modules.
What can you expect with the Visual Basic Working Model CD-ROM? A version of Visual Basic that includes all the tools that you need to learn the IN's and out's of Visual Basic. You will add advanced controls to your Visual Basic programs. You will write programs that behave just like the major Windows applications you use daily. You will learn what programming is all about by mastering the Visual Basic 4 programming language.
Note: This book often uses the term Visual Basic to refer to the Visual Basic 4 Working Model system that comes with the book and CD-ROM package.
Review: The CD-ROM that comes with this book contains the Visual Basic Working Model programming system, which includes everything you need to create complete Windows applications.
Warning: If you already have Visual Basic, you should install the Visual Basic Working Model in a different directory.
Concept: Install the contents of the companion disk on your computer's hard disk.
Installing the Visual Basic Working Model and other files on the disk is simple. The installation described in this unit assumes that you want to install the Visual Basic Working Model on your hard disk drive named D and that you are installing from the CD-ROM drive named C. Change the drive names accordingly if you want to install to or from different drives.
Follow these steps to install the Visual Basic Working Model on your system:
Figure 2.1. Getting ready to install Visual Basic.
Warning: Almost every Windows screen looks different because almost everyone uses a different configuration of software packages. Therefore, your screen might hold a set of icons completely different from what is shown in Figure 2.1. The Run dialog box shown in the lower-left corner is what matters.
DefinitionDefault is the value used if you do not type a different value.
You need about 18 megabytes of free disk space for the Visual Basic Working Model and the applications that you create with this book. Assuming there is enough disk space to install the Visual Basic Working Model system, the installation program proceeds to complete the installation.
During the installation, a new Start menu submenu group called Visual Basic is created, which contains an entry for the Visual Basic 4 Working Model. Once the installation completes, click your Start menu, select Programs, and move your mouse over the Visual Basic 4 submenu to see the Working Model's entry. For now, return to Windows so that you can learn the standard startup method.
You have now successfully installed the Visual Basic Working Model programming system. All this book's source files remain on the CD-ROM in a directory called SOURCE. As you work with various Visual Basic projects throughout this book, you'll be able to load and run those projects from the CD-ROM's SOURCE directory.
Review: Your computer now has this book's Visual Basic Working Model system installed. You are ready to start the program and master the environment.
Concept: To write a Windows program with Visual Basic, you have to start Visual Basic. And then before turning off your computer and shutting down Windows, you should first exit Visual Basic.
Display your Start menu and select the Programs option to begin starting Visual Basic. Select the Microsoft Visual Basic 4 option and then click on the Visual Basic 4 Working Model entry that appears. Visual Basic 4 will then begin. Figure 2.2 shows the Visual Basic opening screen.
Warning: Your Visual Basic opening screen may differ slightly from the figure's screen depending on installation and system differences.
Figure 2.2. The Visual Basic startup screen.
Depending on your Windows installation, underlying Windows icons can often peek through to the Visual Basic programming area. You'll be able to size your Visual Basic windows so that you don't have to compete with underlying icons when you begin to work in Visual Basic.
Warning: No matter how you shut down Visual Basic or Windows, Visual Basic will always ask you if you want to save any unsaved work.
Review: Starting Visual Basic requires only that you click the Visual Basic 4 Working Model option from the Visual Basic 4 Start menu. To exit Visual Basic, you can select File Exit.
Concept: Before you learn how to write programs with Visual Basic, you must learn all about the Visual Basic screen. Some people think that the Visual Basic screen is confusing at first. They are wrong; the Visual Basic screen is confusing not only at first but also the whole time you use it! Actually, Visual Basic's screen is more busy than it is confusing. Once you learn how to manage the parts of the screen, however, you will feel much more comfortable using Visual Basic.
Being an effective Visual Basic programmer means knowing how to rearrange the Visual Basic screen when needed. Visual Basic does not really look like every Windows program. For example, Microsoft Word is one of the most powerful and most used Windows programs. When you use Word, you basically work within one gigantic window. You can open a second document window and resize the two windows to add more screen elements, but most of the time you work within a single document window.
In Visual Basic, you work with several open windows most of the time. There are several windows open, and you will often need information from each of the windows. Therefore, you should familiarize yourself with the screen and its components early on.
Review: Learn all you can about the Visual Basic environment now so that you can concentrate on the language and controls later.
Concept: The Visual Basic environment contains several windows with which you will work as you build applications.
Figure 2.3 illustrates the major parts of the Visual Basic screen. You might not understand all the components of the screen just yet, but learn the names of the screens now so that you will move right along later when you begin learning how to program Visual Basic.
Figure 2.3. The elements of the Visual Basic screen.
Warning: Actually, Figure 2.3 does not look exactly like your screen probably will look when you first start Visual Basic. You will soon learn how to rearrange the screen so that it can look just like the screen in Figure 2.3. Figure 2.3 looks the way it does so that you can see all the major parts of the screen.
Table 2.1 describes each of the five primary windows of Visual Basic. Although you cannot understand all of the descriptions at this point, try to familiarize yourself with the descriptions so that the windows will not be so foreign later when you learn how to program in Visual Basic.
| Window | Description |
| Form | Contains the background for the Windows program that you are writing. You draw and place items on the form that your program's user will eventually see and interact with. If you use a Windows word processor, the form would hold the document that you are editing. Although not every Visual Basic program requires forms, most do because most Visual Basic programs exist to display information for, and retrieve information from, the user. |
| Toolbox | The Toolbox window contains your tools. That might seem obvious, but you need to know that the tools of Visual Basic are more often called controls. The toolbox is where you will find controls that you will place on the Form window as you create a Windows program. For example, when you need to ask the user for text, you will select a text box control from the toolbox and place that text box on the form. |
| Project | A Visual Basic Windows program often contains several different kinds of files that all work in unison to form the single running application. The Project window contains the list of all the files used in the current application. Given the common Visual Basic terminology, a Visual Basic application is generally called a project. The Project window contains the contents of the project. |
| Properties | The Properties window describes every individual element in your application. For example, there is a Properties window for a project's form because the form contains properties such as color and size. As you place controls from the Toolbox window onto the Form window, each of those controls has its own properties. Although any one Visual Basic program might have several elements with properties, there is only one Properties window. When you want to see the properties of a different form or control, you change the Properties window to display another set of properties. |
| Code | Unlike most other programming languages, you do not have to write much code as you develop applications in Visual Basic. The more advanced the application needs to be, the more code you will have to write to tie things together. The visual parts of Visual Basic, however, eliminate much of the code that you would have to write if you were still working in a text-based environment. Although you should not expect to understand anything just yet, Figure 2.4 shows a Code window that contains a fairly complex routine. The code in the Code window is the program's source code, which you learned about in the previous unit. When the user runs the program, Visual Basic and your computer interpret that source code and execute the instructions in the source code. |
Figure 2.4. A Code window with lots of code.
[ic:note}Much of the time, the code inside the Code window contains setting and retrieval instructions for form controls. For example, if you need to check whether a user clicked a command button or typed a response, you can use code to check for the click.
As with most windows used inside Windows applications, you can move, resize, and close the five windows. Use the mouse to make working with windows simple.
DefinitionMaximize means to increase a window to its largest size.
For example, when you first start Visual Basic, the Form window hides the other windows. Usually, the Form window is the largest window because the Form window is the user's background. You can maximize the Form window by double-clicking the mouse on the Form window's title bar or by clicking the maximize button in the window's upper-right hand corner. Double-click the Form window's title bar now to maximize the window. When you do, there is nothing left on the screen except for the Form window.
Obviously, there is a way to see the menu and the other windows. Press Alt to get the top of the screen back so that you can see the menu bar and toolbar again. Display the View pulldown menu, and select the Project window to see the Project window. Click the Project window's View Code button to see the Code window.
Tip: There are two other ways to display the Code window. You can select View Code to see the window. You can also press F7 to display the code.
Click anywhere on the white portion of the Form window. Clicking any window activates that window, highlights its title bar, and makes all its commands and menus available. When you activate the Form window, the Project window and Code window hide behind the form, but you can get them back by following the descriptions just offered.
To see the form's Properties window, press F4 or select View Properties to see the Properties window. Move the mouse cursor over the Properties window and click and hold the mouse button. You can now move the Properties window by dragging the mouse across the screen. When you let up on the mouse button, Visual Basic anchors the Properties window at that point.
Try resizing the Properties window. Move the mouse cursor to any edge or corner of the Properties window. The mouse changes to a double-pointing arrow. By dragging the mouse, with your mouse button held down, you can resize the window.
When you are ready to close a window, the easiest way is to double-click its control icon. However, if you click the control icon once, you will see the window's control menu, such as the one shown in Figure 2.5. You have probably seen the control menu in other Windows work that you have done. If not, you can use the control menu to move, resize, and close the window with your keyboard. Using the mouse as just described, however, is easier than using the control menu. To close the control menu, you can click the control button once again or press the Esc key twice.
Review: The five primary windows of Visual Basic supply the locations for controls and work areas that you will use to build Visual Basic applications. The Form window is the most important window for the applications that you write because it is on the Form window where you will draw and place interactive controls for the user to work with. The other windows exist to offer help and tools.
Concept: As you learn more about Visual Basic's environment, you will find that Visual Basic conforms well to the standard look and feel of other Windows programs. Many Windows programs contain menus and toolbars that work much like Visual Basic's.
The top of the screen contains the menu bar and toolbar. The menu bar contains lists of pulldown menus with which you can manage your Visual Basic program. The toolbar supplies quick push-button commands for common tasks.
Warning: Don't confuse the terms toolbar with toolbox. The toolbar appears under the menu bar and contains buttons with icons on them. The toolbox is what is typically called the Toolbox window where the controls are located that you will eventually place on the form.
If you have worked much with other Windows programs, you are already familiar with the File, Edit, View, Tools, and Help menu bar commands because they are similar across many Windows applications. Table 2.2 describes all the Visual Basic menu bar commands with which you will work.
Note: The menu bar contains additional menus that pull down just like virtually all Windows applications use. These pulldown menus are sometimes called submenus. The commands on the submenus perform tasks or produce dialog boxes that require extra information from you before Visual Basic can issue the commands.
| Command | Description |
| File | The File menu contains all file-related commands with which you can load and save Visual Basic applications. It also provides printing access for printed program descriptions as well as the Exitcommand that you learned about earlier in this unit. |
| Edit | Programmers often use the commands on the Edit menu for copying, cutting, and pasting text and graphical controls among applications. The Edit commands also help you with the creation of your programs by supplying common search and replace actions. |
| View | The View menu command enables you to control the viewing of your application's Code, Form, and Project windows, various routines that can appear inside the Code window, as well as the toolbar and toolbox. By hiding the toolbar, you can gain a little extra screen space. For instance, if you wanted more workspace and did not use the toolbar often, you could hide the toolbar by clicking View Toolbar (the default is selected so that the toolbar appears unless you hide the toolbar by clicking this option). The toolbar will disappear. Selecting View Toolbar once again displays the toolbar. |
| Insert | Lets you insert additional objects, such as a second form, in your Visual Basic application. |
| Run | When you complete an application, you can see the results of your work with the Run menu. The Run menu enables you to execute programs, halt the execution, and resume the execution after a halt. |
| Tools | Lets you test your program and work with additional tools that come with Visual Basic such as the Menu Editor. One of the most powerful features of Visual Basic is its debugging capability. With the Debug menu, you can execute a Visual Basic program one statement at a time, looking at data values along the way, and stop the program at any point to analyze what is going on. If a program does not behave the way you think it should, the Debug menu will help you pinpoint the cause of the trouble. |
| Add-Ins | Lets you add additional components to Visual Basic. The default toolbox does not contain all the tools that you get with the Visual Basic Working Model. For example, you can add additional tools to your toolbar by selecting the Add-Ins option and locating the extra Windows 95 tools. |
| Help | When you select from the Help menu with the Working Model edition of Visual Basic, you will get online help. If you select Help Contents, for example, the Visual Basic Working Model displays the window shown in Figure 2.6, which contains a tabbed dialog box (called a properties sheet) of help topics from which you can select. If you display the Help menu's About Microsoft Visual Basic box, Visual Basic shows you the copyright notice and version of the Visual Basic Working Model system. When you click the System Info command button, Visual Basic displays information about your hardware. |
Figure 2.6. The Help topics that Visual Basic offers.
DefinitionA shortcut key provides a quick method of issuing commands.
Many of the menu bar's commands also activate when you press a shortcut keystroke. For example, if you display the File pulldown menu, you will see the menu shown in Figure 2.7. You can activate any command on the File menu by displaying the menu and selecting a command. You can also issue commands for five of the commands by pressing shortcut keystrokes.
Figure 2.7. Shortcut keystrokes make selecting certain commands easier.
Instead of selecting File Add File, you can press the Ctrl+D shortcut keystroke. Instead of selecting Save File, you can press Ctrl+S. The shortcut keystrokes are available from within Visual Basic even if you do not first display the menu. For example, you can save the active file by pressing Ctrl+S without taking the time to display the File menu first.
Tip: The Ctrl key works the way the Shift and Alt keys work. Pressing Ctrl+S means press and hold the Ctrl key, and then press the S key while still holding down Ctrl, and then immediately let up on both.
Not all of the shortcut keystrokes require that you use the Ctrl key. For example, some menu commands on the Edit pulldown menu do not require a second key such as Ctrl. For example, the Edit Outdent command requires Shift+Tab.
Tip: As you will see next, many of the toolbar commands provide the same functionality as menu commands.
Figure 2.8 shows the toolbar and labels each button on the toolbar. Many of the toolbar buttons represent menu commands. Instead of issuing a menu command or using a shortcut key, you can click a toolbar button with the mouse to perform the same task.
Figure 2.8. The toolbar contains quick access to many commands.
As you progress through this book and learn how to use commands that appear on the toolbar, you will be reminded when you can use a toolbar button. Some people prefer not to use the toolbar. They either want more screen space or do not think the icons are that easy to rememberand they're right. Keep in mind that the View Toolbar command hides the toolbar from view if you do not want to see it.
Warning: Before you remove the toolbar, be sure that you do not need the measurement indicators that appear to the right of the toolbar. The next section explains what the measurement indicators do.
Notice that not all of the toolbar buttons are dark. Some are grayed out, just as some of the pulldown menu bar commands are grayed out at times. Visual Basic knows that certain commands have to be activated at specific times within the program. If you have not copied text or a control to the clipboard, for example, you cannot use the Edit Paste command.
Tip: If you move your mouse pointer over any toolbar button and rest the mouse there, a floating tooltip appears. A tooltip is the toolbar button's name displayed inside a white label. If you forget what a toolbar button does, display the button's tooltip to get a reminder.
As you draw and resize images on the Form window, you will often look to the two measurement indicators that appear to the right of the toolbar for help. The first indicator describes the upper-left corner measurement of a control, and the second indicator describes the size of the control.
DefinitionA twip is 1/1440 of an inch.
Each of the measurements appear in twips. For example, Figure 2.9 shows a box placed near the center of the Form window. You know from the measurement indicators that the box's upper-left corner appears exactly 3,000 twips from the left edge of the Form window and exactly 720 twips from the top edge of the Form window. Likewise, you know that the box is exactly 2,655 twips wide and 1,575 twips tall.
Figure 2.9. The measurement indicators enable you to size and place controls on the Form window.
By using the measurement indicators, you ensure that all screen elements in your user's application are aligned and properly adjusted for the size that you want.
Note: The Form window's grid of dots that you see in the background helps you align images with one other. The grid is sometimes called a snap to grid because controls that you place on the Form window snap to the nearest grid dot location if you place controls between two grid points. If you want to adjust the distance between grid dots, use the Tools Options menu command. If you want to turn off the grid so that you can place controls between grid points when you want, you can uncheck the Show Grid option from the same menu location.
Review: You have now seen a complete description of the Visual Basic screen and its environment. Although you do not know how to use all the elements in the environment, you are at least familiar with the environment and will recognize the names of the screen elements when they appear later in this book.
Concept: Visual Basic comes with an extensive online help system that's always available when you need to know more about a particular Visual Basic topic, command, or screen element.
DefinitionOnline means directly available from within the application.
The menu's Help command gives you access to several different forms of electronic help. The beauty of a CD-ROMbased Visual Basic system is that the CD-ROM can hold lots of help text. Table 2.3 describes each of the Help menu's options.
| Command | Description |
| Contents | Provides you with online help for every topic in Visual Basic. The Contents screen displays a properties sheet window with these three tabbed property sheets from which you can select: Contents which provides an overview of Visual Basic topics, Index which displays every available help topic by keyword just as a book's index locates topics based on keywords in the index, and Find that searches through every help topic's text looking for topics you want. (The first time you select Find, Visual Basic builds a help database of topics. If you have ample disk space (five or more megabytes), request that Visual Basic generate a comprehensive help database so your subsequent searches are as complete as possible.) |
| Search For Help On | Takes you directly to the help system's Index property sheet from where you can search for a specific help topic based on a keyword. |
| Obtaining Technical Support | Displays a list of locations, both online, by mail, and by phone, through which you can get help with Visual Basic. |
| Visual Basic Books Online | Not available in the Visual Basic Working Model version. |
| Learning Microsoft Visual Basic | Displays Figure 2.10's menu-driven screen from menu-driven screen from which you can walk through a series of introductory Visual Basic tutorials. |
| About Microsoft Visual Basic | Displays the help's About box that contains a copyright notice and a command button that describes your system hardware. |
Figure 2.10. Get an introduction to Visual Basic through the help system.
Tip: The various help screens that you find often have hot spots that link you to other helpful topics. If you click over a green underlined topic, Visual Basic displays another help screen on that particular topic. If you click over a green dotted underlined topic, Visual Basic displays the definition for that particular item.
One of the nicest help features is the context-sensitive help that Visual Basic provides. Whether you're writing Visual Basic code or placing a toolbox control, if you press F1, the context-sensitive help key, Visual Basic displays help about whatever you are doing at the time. In other words, Visual Basic is sensitive about the context where you requested the help and Visual Basic gives you help on that topic.
Warning: If you press F1 after selecting text, Visual Basic's online help system looks for help on that particular text.
Note: Most of the parts in this book end with a Review as well as a Stop & Type section, which enables you to reinforce the section's topics with a hands-on programming exercise. The primary purpose of this first unit has been to teach you the basics of programming from a historical perspective. Therefore, there are no hands-on topics for this unit.
Review: The online help system, always available from the menu bar's Help command, displays comprehensive information of virtually every aspect of the Visual Basic language and environment. Pressing F1 from anywhere within Visual Basic gives you a context-sensitive help system that you can use to get information on virtually any Visual Basic topic.
Locate each toolbar button's corresponding menu command. In doing so, you will better familiarize yourself with the menu and its contents.