Mastering Visual Basic(1).pdf
(
14776 KB
)
Pobierz
77044137 UNPDF
Contents at a Glance
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Part I • The Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1 • Getting Started with VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2 • Visual Basic Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Chapter 3 • Visual Basic: The Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Chapter 4 • Writing and Using Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Chapter 5 • Working with Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Chapter 6 • Basic Windows Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Chapter 7 • More Windows Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Part II • Rolling Your Own Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Chapter 8 • Building Custom Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Chapter 9 • Building Custom Windows Controls . . . . . . . . . . . . . . . . . . . . . . . 391
Chapter 10 • Automating Microsoft Office Applications . . . . . . . . . . . . . . . . . . 433
Part III • Basic Framework Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Chapter 11 • Storing Data in Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Chapter 12 • Handling Strings, Characters, and Dates . . . . . . . . . . . . . . . . . . . . 529
Chapter 13 • Working with Folders and Files . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Part IV • Intermediate Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Chapter 14 • Drawing and Painting with Visual Basic . . . . . . . . . . . . . . . . . . . . 619
Chapter 15 • Printing with VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
Chapter 16 • The TreeView and ListView Controls . . . . . . . . . . . . . . . . . . . . . 741
x
CONTENTS AT A GLANCE
Chapter 17 • Error Handling and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 791
Chapter 18 • Recursive Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811
Chapter 19 • The Multiple Document Interface . . . . . . . . . . . . . . . . . . . . . . . . 837
Part V • Database Programming with VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
Chapter 20 • Databases: Architecture and Basic Concepts . . . . . . . . . . . . . . . . . 869
Chapter 21 • Building Database Applications with ADO.NET . . . . . . . . . . . . . 925
Chapter 22 • Programming the ADO.NET Objects . . . . . . . . . . . . . . . . . . . . . 963
Part VI • VB.NET on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997
Chapter 23 • Introduction to Web Programming . . . . . . . . . . . . . . . . . . . . . . . 999
Chapter 24 • Accessing Data on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
Chapter 25 • XML Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1099
Chapter 1
Getting Started with VB.NET
Welcome to the Enterprise
Edition of Visual Basic .NET. I’m assuming you have installed
Visual Studio .NET, Enterprise Edition. You may have even already explored the new environ-
ment on your own, but this book doesn’t require any knowledge of Visual Basic 6. It doesn’t
require anything more than a familiarity with programming. As you already know, Visual Basic
.NET is just one of the languages you can use to build applications with Visual Studio .NET. I
happen to be convinced that it is also the simplest, most convenient language, but this isn’t really
the issue. What you should keep in mind is that Visual Studio .NET is an integrated environ-
ment for building, testing, and debugging a variety of applications: Windows applications, Web
applications, classes and custom controls, even console applications. It provides numerous tools
for automating the development process, visual tools to perform many common design and pro-
gramming tasks, and more features than any author would hope to cover.
The first thing you must learn is the environment you’ll be working in from now on. In the
first chapter of this book, you’ll familiarize yourself with the integrated development environment
(IDE) and how its tools allow you to quickly design the user interface of your application, as well
as how to program the application.
It will be a while before you explore all the items of the IDE. Visual Studio is an environment
for developing all types of applications, from a simple Windows application to a complete Web
app involving databases and XML files. I will explain the various items as needed in the course of
the book. In this chapter, we’ll look at the basic components of the IDE needed to build simple
Windows applications.
The Integrated Development Environment
Visual Studio .NET is an environment for developing Windows and Web applications. Visual
Basic .NET is just one of the languages you can use to program your applications. Actually,
Visual Studio .NET was designed to host any language, and many companies are working on lan-
guages that will be integrated in Visual Studio .NET. Some people will develop Windows appli-
cations in Visual Studio .NET with COBOL, or FORTRAN.
4
Chapter 1
GETTING STARTED WITH VB.NET
So, what’s the distinction between Visual Studio .NET and the language? Visual Studio .NET is
the environment that provides all the necessary tools for developing applications. The language is
only one aspect of a Windows application. The visual interface of the application isn’t tied to a spe-
cific language, and the same tools you’ll use to develop your application’s interface will also be used
by all programmers, regardless of the language they’ll use to code the application.
The tools you’ll use to access databases are also independent of the language. Visual Studio pro-
vides tools that allow you to connect to a database, inspect its objects, retrieve the information you’re
interested in, and even store it in objects that can be accessed from within any language.
There are many visual tools in the IDE, like the Menu Designer. This tool allows you to visually
design menus and to set their names and basic properties (such as checking, enabling, or disabling
certain options). Designing a menu doesn’t involve any code, and it’s carried out with point-and-
click operations. Of course, you will have to insert some code behind the commands of your menus,
and (again) you can use any language to program them.
To simplify the process of application development, Visual Studio .NET provides an environment
that’s common to all languages, which is known as
integrated development environment (IDE).
The purpose
of the IDE is to enable the developer to do as much as possible with visual tools, before writing code.
The IDE provides tools for designing, executing, and debugging your applications. It’s your second
desktop, and you’ll be spending most of your productive hours in this environment.
The Start Page
When you run Visual Studio for the first time, you will see the window shown in Figure 1.1. On the
My Profile tab, you will set your personal preferences by specifying your language. Select Visual
Basic Developer in the Profile box, and the other two boxes will be filled automatically. You can
leave the other fields to their default values. The ComboBox control at the bottom of the page, the
At Startup control, is where you define what you want Visual Studio .NET to do when it starts.
The choices are the following:
Show Start Page
Every time you start Visual Studio .NET, this page will appear.
Load Last Loaded Solution
Once you start working on a real project (a project that will take
you from a few days to a few months to complete), select this option so that the project will be
loaded automatically every time you start Visual Studio .NET.
Show Open Project Dialog Box
Every time you start Visual Studio .NET, the Open Project
dialog box will appear, where you can select a project to open.
Show New Project Dialog Box
Every time you start Visual Studio .NET, the New Project
dialog box will appear, where you can specify the name of a new project—a setting to avoid.
Show Empty Environment
This option instructs Visual Studio .NET to start a new empty
solution, and you’re responsible for adding new or existing projects to the solution and new or
existing items to a project.
The actions are self-explanatory, and the most common setting is to show the Start Page. The
Start Page displays the four most recently opened projects, as well as the New Project and Open
Project buttons. To see the Start Page, select the Get Started option.
THE INTEGRATED DEVELOPMENT ENVIRONMENT
5
Figure 1.1
This is what you’ll
see when you start
Visual Studio for
the first time.
The remaining options lead to Visual Studio sites with up-to-date information about the prod-
uct, such as news articles, updated documents, and service packs or patches. At the very least, you
should switch to the Downloads option from time to time to check for updates. The installation of
the updates should be automatic—after you confirm your intention to download and update any
new component, of course.
The Web Hosting option leads to a page with information about ISPs that support ASP.NET.
You will need the services of these ISPs to post an actual Web application or Web services to the
Internet. Web applications and Web services are two types of projects you can develop with Visual
Studio (they’re discussed in the last part of the book). These projects aren’t distributed to users;
instead, they run on a Web server; users must connect to the URL of the Web server and run the
application in their browser.
Note
The official names of the products are Visual Studio .NET and Visual Basic .NET. Throughout the book I will
refer to the language as VB.NET and mostly as VB. When referring to the previous version of the language, I will use VB6.
Starting a New Project
At this point, you can create a new project and start working with Visual Basic .NET. To best explain
the various items of the IDE, we are going to build a simple form—it’s not even an application. The
form is the window of your application—what users will see on their desktop when they run your
application.
Open the File menu and select New
➢
Project. In the New Project dialog box (Figure 1.2), you
will see a list of project types you can create with Visual Studio. Select the Windows Application
Plik z chomika:
martindude
Inne pliki z tego folderu:
Pizza Hut KFC MC DONALDS PRZEPISY.pdf
(946 KB)
SQL skladnia.doc
(19 KB)
Podstawy języka SQL(1).doc
(449 KB)
KursSQLa.doc
(454 KB)
Kurs - Administracja Oracle.doc
(3639 KB)
Inne foldery tego chomika:
GRY - godne uwagi
Prywatne
zachomikowane
Zgłoś jeśli
naruszono regulamin