Section I: The Visual Studio IDE and Controls
The lessons in this section explain how to use the Visual Studio integrated development environment (IDE) and how to use the controls that make up a user interface. These form the foundation on which you build everything else in a Visual Basic program.
Lesson 1, "Getting Started with the Visual Studio IDE," explains Visual Studio. It describes some of the IDE's useful features and demonstrates how to build a simple program and run it. From the very first lesson, you'll be able to build a program!
Lesson 2, "Creating Controls," explains what controls are, what they are for, and how to use them. It shows how to add controls to a form to make a user interface. In Visual Basic programs, controls are critical for getting the job done.
Lesson 3, "Making Controls Arrange Themselves," explains how to use control properties to make controls automatically rearrange themselves at run time to take full advantage of the available space. When the user resizes a form, the controls can automatically move and resize as needed.
Lesson 4, "Handling Events," explains what events are. It shows how to catch events to respond to user actions so the user can interact with the program.
Lesson 5, "Making Menus," explains how to add main menus and context menus to an application, and how to respond when the user selects a menu item. By responding to menu events, the program gives the user an easy and well-understood way to control the application.
Lesson 6, "Making Tool Strips and Status Strips," explains how to build tool strips and status strips, and how to handle their events. Tool strips provide a faster method for the user to control the application than menus, while status strips provide useful feedback to let the user know what the program is doing.
Lesson 7, "Using RichTextBoxes," explains the RichTextBox control and shows how to manipulate it with code. The RichTextBox enables the user to enter text and, if the program provides the right tools, lets the user format the text with different fonts, colors, bullets, and other text decorations.
Lesson 8, "Using Standard Dialogs," explains how to use standard dialogs to display messages and questions, change fonts and colors, browse for folders, and let the user select files for opening and saving.
Lesson 9, "Creating and Displaying New Forms," explains how a program can display new instances of forms and interact with the controls on those forms. This is important for more complicated programs that cannot do everything they need to on a single form.
Lesson 10, "Building Custom Dialogs," explains how to use new forms as custom dialogs. It shows how to display a custom dialog and determine which button the user pressed to close it.
Section II: Variables and Calculations
The lessons in this section deal with variables and calculations. They explain how variables hold values and how a program can use them to calculate results. Whereas the lessons in Section I explain how to make controls that enable the user to enter information, the lessons in this section explain how to do something with that information.
Lesson 11, "Using Variables and Performing Calculations," explains how to declare and use variables and constants, and how to perform simple calculations. It also shows how to convert information from one data type to another. For example, it demonstrates how to take an age entered by the user and convert it from a textual value (for example, "47") into a numeric value (47). (It's a small distinction to a person but a huge one to a program.)
Lesson 12, "Debugging Code," explains techniques for finding and fixing bugs. It shows how to determine which line of code the program is executing, examine and modify variable values, and use watches to keep track of variable values. Almost every nontrivial program starts with a bug or two. This lesson shows how to find those bugs.
Lesson 13, "Understanding Scope," explains how scope restricts a variable's accessibility to certain pieces of code. It also explains why a programmer should restrict scope as much as possible.
Lesson 14, "Working with Strings," explains how to combine, manipulate, and format strings. It explains the String class's ToString and Format methods, which enable you to build nicely formatted strings to show the user.
Lesson 15, "Working with Dates and Times," explains how to use date and time values. It explains the Date and TimeSpan classes, and shows how to use and format them.
Lesson 16, "Using Arrays and Collections," explains single- and multi-dimensional arrays and collection classes such as List and Stack. It explains how to declare and initialize arrays and collections.
Lesson 17, "Using Enumerations and Structures," explains how to define and use customized data types such as structures and enumerations. These help make the code easier to understand, debug, and maintain.
Section III: Program Statements
The lessons in the previous sections explain how to write code that flows through a series of steps, one at a time in a predefined order. The lessons in this section explain how to make code follow more complex paths. They explain how code can choose between one path and another and repeat operations. While controls and message boxes are more visible pieces of an application, these statements let the program do most of its work.
Lesson 18, "Making Choices," explains how programmers can control the flow of code with If, Select Case, nested If, and cascading If statements. These statements let the program take different actions depending on the situation.
Lesson 19, "Repeating Program Steps," explains looping code that uses statements such as For, For Each, Do, and While. It explains how to use these statements to iterate through a series of integer values, arrays, and lists, and how to break out of loops.
Lesson 20, "Reusing Code with Procedures," explains how a programmer can write procedures and why procedures are important. It explains the syntax of declaring subroutines and functions, defining return values, and using parameters passed by value or by reference.
Lesson 21, "Handling Errors," explains how to use Try blocks to handle unexpected errors. It also explains how to raise errors to tell other parts of the program that something has gone wrong.
Lesson 22, "Preventing Bugs," explains bug proofing techniques that make it easier to detect and correct bugs. It explains how to use Assert statements to validate inputs and results so you can catch bugs quickly, rather than let them remain hidden in the code.
Section IV: Classes
Structures, enumerations, and procedures are all programming abstractions that let you think about pieces of the program at a higher level. For example, when you call the CalculateInterest procedure, you don't need to know how it works, just that it does.
The ultimate programming abstraction is the class. A class lets you think about data and functions packaged as a single unit. For example, a Customer class might include data (name, employee ID, office number) together with functions (ScheduleWork, PrintPaycheck).
The lessons in this section deal with classes. They explain how to create and use classes and how to use more advanced class features such as generics and operator overloading.
Lesson 23, "Defining Classes and Their Properties," explains how to define classes. It explains the main benefits of classes and how to build simple properties to hold data for classes.
Lesson 24, "Defining Class Methods and Events," explains how to add methods and events to a class. Methods enable the program to make an object perform some action, and events enable an object to tell the program that something interesting has happened.
Lesson 25, "Using Inheritance and Polymorphism," explains two of the most important and confusing aspects of classes: inheritance and polymorphism. It explains how you can make one class inherit from another to reuse code and how you can make an object of one class behave as if it were from another class.
Lesson 26, "Initializing Objects," explains constructors, destructors, and initializers, and shows how to use them to make creating objects easier.
Lesson 27, "Fine-Tuning Classes," explains how you can overload and override class methods. These techniques enable you to make classes more flexible and easier to use.
Lesson 28, "Overloading Operators," explains operator overloading. Ths technique enables you to define the behavior of operators such as +, *, and % for objects other than numbers.
Lesson 29, "Using Interfaces," explains what a class interface is and how to build one. Just as a program's user interface defines features that a program shows to the user, a class interface defines features that a class shows to the program's code.
Lesson 30, "Making Generic Classes," explains how to build new generic classes. Lesson 16 shows how to use generic collection classes such as List to work with specific kinds of data. This lesson explains how you can build your own generic classes and methods.
Section V: System Interactions
Earlier lessons explain how to enable a program to interact with the user. The lessons in this section explain methods a program can use to interact with the operating system and other programs.
Lesson 31, "Reading and Writing Files," explains how a program can read and write files. It explains how to use streams to manipulate the text in a file all at once or in pieces--for example, one line at a time.
Lesson 32, "Using File System Classes," explains ways in which a program can use classes to find, examine, and manipulate directories and files. It describes file-handling classes such as DriveInfo, DirectoryInfo, Directory, and FileInfo.
Lesson 33, "Printing," explains how to create printouts and print previews. It describes how to draw simple shapes and text on one or more pages sent to the printer.
Lesson 34, "Using the Clipboard," explains how to move text, images, and other data in and out of the clipboard. Using the clipboard in this way is somewhat crude, but it's simple and flexible, enabling your program to interact with many others without understanding anything about how those other applications work.
Lesson 35, "Providing Drag and Drop," explains how a program can use drag-and-drop to interact with other programs. It explains how to start a drag, provide "drag over" feedback, and handle a drop. Like the clipboard, drag and drop enables your program to interact with others without knowing how the other programs work.
Section VI: Specialized Topics
The lessons presented in the earlier sections cover topics that are generally useful for a large variety of programs. Whether you are writing a sales tax calculator, an invoice tracking system, or a word guessing game, techniques such as handling events, debugging code, using If statements, and printing will be useful to you.
This section introduces topics that are more specialized, so you might not need them in every program you write. For example, localizing your application for different locales is important for some applications but not for every program you write.
Each of the lessons in this section provides a sense of what its topic is about, and offers enough detail to get started, but a lesson cannot cover its topic in complete detail due to the topic's length and complexity.
Lesson 36, "Using the My Namespace," explains the My namespace, which makes using certain .NET features easier. This namespace provides shortcuts for performing common tasks such as reading and writing entire files; saving and restoring program settings; and checking the network's status.
Lesson 37, "Localizing Programs," explains how to make programs that can run in multiple cultures. It shows how to use different text and images for different locales and discusses some of the other issues an international application must address.
Lesson 38, "Manipulating Data with LINQ to Objects," explains how you can use Language-Integrated Query (LINQ) to filter and extract values from collections and other enumerable lists into new ones. This enables you to perform database-like queries on data stored in program objects instead of in an actual database.
Lesson 39, "Manipulating Databases with the Entity Framework," explains how you can use the Entity Framework (EF) to manipulate database entities as if they were objects inside the program. It enables your program to treat records in tables as if they were instances of classes and enables your program to fetch, modify, and save records while treating them as objects.
This book's appendices summarize useful information for handy reference.
Appendix A, "Glossary," explains common programming terms that you may encounter while studying Visual Basic programming.
Appendix B, "Control Summary," summarizes each of the standard controls provided by Visual Basic. You can use it to help select the right control for your needs.
Appendix C, "What's on the DVD?," goes into more detail about using the DVD that comes with the book.