Module 2: Development Environment Features
Module 2: Development Environment Features
Environment Features
Contents
Overview 1
Describing the Integrated Development
Environment 2
Creating Visual Basic .NET Projects 3
Demonstration: Creating a
Visual Basic .NET Project 16
Using Development Environment
Features 17
Demonstration: Using the
Visual Studio .NET IDE 29
Debugging Applications 30
Demonstration: Debugging a Project 37
Compiling in Visual Basic .NET 38
Lab 2.1: Exploring the Development
Environment 41
Review 46
Information in this document, including URL and other Internet Web site references, is subject to
change without notice. Unless otherwise noted, the example companies, organizations, products,
domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious,
and no association with any real company, organization, product, domain name, e-mail address,
logo, person, place or event is intended or should be inferred. Complying with all applicable
copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part
of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted
in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or
for any purpose, without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BizTalk, FrontPage, IntelliSense, JScript,
Microsoft Press, Outlook, PowerPoint, Visio, Visual Basic, Visual C++, Visual C#, Visual
InterDev, Visual J#, Visual SourceSafe, Visual Studio, and Windows Media are either registered
trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their
respective owners.
Module 2: Development Environment Features iii
Instructor Notes
Presentation: This module teaches students some of the overall benefits of using the new
60 Minutes Microsoft® Visual Studio® .NET version 7.0 integrated development
environment (IDE) and how to create Visual Basic® .NET projects. Students
Lab: will try some of the tools that make the IDE so powerful for application
45 Minutes development. They will learn how to debug and compile projects.
After completing this module, students will be able to:
Describe the overall benefits of the new IDE.
Describe the different types of Visual Basic .NET projects and their
structures, including their file structures.
Reference external applications from a project.
View and set the properties of a project.
Use the various windows in the IDE, including the Server Explorer, Object
Browser, and Task List.
Debug a simple application.
Build and compile a simple application.
Required Materials
To teach this module, you need the following materials:
Microsoft PowerPoint® file 2373B_02.ppt
Module 2, “Development Environment Features”
Preparation Tasks
To prepare for this module, you should:
Read all of the materials for this module.
Read the instructor notes and the margin notes for the module.
Practice the demonstrations.
Complete the labs.
iv Module 2: Development Environment Features
Demonstrations
This section provides demonstration procedures that will not fit in the margin
notes or are not appropriate for the student notes.
5. Expand the new data connection. Point out the functional similarity to the
Data View window found in previous versions of Microsoft Visual Basic.
Debugging a Project
To prepare for the demonstration
• Open Visual Studio .NET, and then open the install folder\DemoCode\
Mod02\Debugging\Starter\Debugging.sln solution.
Module Strategy
Use the following strategy to present this module:
Describing the Integrated Development Environment
This lesson is an introduction to the general benefits of using the
Visual Studio .NET IDE.
The most important aspect of this lesson is that there is only one IDE that is
required to create all types of projects. Students no longer must develop
their components in the Visual Basic IDE and their Web pages in Microsoft
Visual InterDev® or another Web development tool.
Creating Visual Basic .NET Projects
This lesson introduces some of the basic concepts required to create a
Visual Basic .NET project. Many aspects of this lesson are similar to
concepts covered in previous Visual Basic courses, such as project
templates, structures, properties, and references.
This lesson also introduces assemblies and namespaces, both of which are
fundamental aspects of .NET-compatible development. Explain assemblies
enough to give the students an overall understanding of their purpose,
without going into too much depth. Concepts such as versioning and
security will be covered in Module 10, “Deploying Applications,” in
Course 2373B, Programming with Microsoft Visual Basic .NET.
The namespaces lesson has a small amount of simple code that you will
need to explain to students. This code defines classes and creates objects
based on those classes. This type of code will be easily understood by all
Visual Basic developers, but advise them that this code will be explained in
Module 5 “Object-Oriented Programming in Visual Basic .NET,” in
Course 2373B, Programming with Microsoft Visual Basic .NET.
Using Development Environment Features
This lesson introduces the various features of the IDE such as the Solution
Explorer, Server Explorer, Object Browser, Task List, Dynamic Help, XML
editing, and macros. Some of these items are similar to those found in
previous versions of Visual Basic, such as the Solution Explorer and Object
Browser, so you will not have to explain them in detail.
Students should have a basic amount of XML knowledge, but check that
they understand the structure of the XML document, Customers.xml, shown
in the demonstration.
Module 2: Development Environment Features ix
Debugging Applications
This lesson begins by discussing breakpoints and how to set them. This will
not be new to most students. However, explain how to set conditional
breakpoints in detail, because this is handled differently in
Visual Basic .NET than in previous versions of Visual Basic.
This lesson discusses the various debugging techniques and debugging
windows that are available. Again, because several of these features are
based on previous versions of Visual Basic, point out the enhancements
rather than explaining each feature in much detail.
The Command window is also discussed, and the slide shows an example of
the window’s use. Step through the example and point out the various
effects each statement has on the environment.
Compiling in Visual Basic .NET
This lesson begins by looking at how the Task List window assists you in
tracking syntax errors during an attempted compilation. The last slide
discusses the various compilation options available to the developer,
including the possible configuration settings Debug and Release. Be sure
students understand the difference between the two settings. This will affect
the assembly that is generated.
Module 2: Development Environment Features 1
Overview
Topic Objective
To provide an overview of
the module topics and
objectives. Describing the Integrated Development Environment
Lead-in Creating Visual Basic .NET Projects
In this module, you will
learn about the Using Development Environment Features
Visual Studio .NET
development environment Debugging Applications
and the many powerful
features it provides for Compiling in Visual Basic .NET
Visual Basic .NET
developers.
Note For more information about Web projects, see Module 7, “Building Web
Applications,” in Course 2373B, Programming with Microsoft
Visual Basic .NET.
Module 2: Development Environment Features 7
Note For more information about assemblies, see Module 10, “Deploying
Applications,” in Course 2373B, Programming with Microsoft
Visual Basic .NET.
8 Module 2: Development Environment Features
To add a reference
1. Select the current project in Solution Explorer. On the Project menu, click
Add Reference.
2. In the Add Reference dialog box, select the appropriate type of reference
by clicking the .NET, COM, or Projects tab. Only projects within the same
solution are displayed in the Projects tab.
3. Locate the required component in the list, or if item is not displayed in the
list use the Browse button to locate the file. Click the item in the list, and
then click Select.
4. Repeat step 3 for all the components you require, and then click OK.
After you set a reference, you can use it in the same way that you use COM
components in previous versions of Visual Basic. You can view information
about the reference in the Object Browser and create code that uses the
functionality of the reference.
Module 2: Development Environment Features 9
Creating Namespaces
Topic Objective
To explain how to create
namespaces.
Lead-in Use Namespace … End Namespace syntax
You can create your own Use the root namespace defined in Assembly Properties
namespaces or use the
namespaces that are
defined in the assembly Namespace
Namespace Top
Top 'Fully
'Fully qualified
qualified as
as MyAssembly.Top
MyAssembly.Top
properties. Public
Public Class
Class Inside
Inside 'Fully
'Fully qualified as MyAssembly.Top.Inside
qualified as MyAssembly.Top.Inside
...
...
End
End Class
Class
Namespace
Namespace InsideTop
InsideTop 'Fully
'Fully qualified
qualified as
as MyAssembly.Top.InsideTop
MyAssembly.Top.InsideTop
Public
Public Class
Class Inside
Inside
'Fully
'Fully qualified
qualified as
as MyAssembly.Top.InsideTop.Inside
MyAssembly.Top.InsideTop.Inside
...
...
End
End Class
Class
End
End Namespace
Namespace
End
End Namespace
Namespace
Namespace InsideTop
'Fully qualified as MyAssembly.Top.InsideTop
The following example shows how code from the same assembly, when outside
of the Top namespace, calls classes. Notice that the MyAssembly namespace is
not required as part of the fully qualified name, because this code also resides in
the MyAssembly namespace.
Public Sub Perform( )
Dim x As New Top.Inside( )
Dim y As New Top.InsideTop.Inside( )
...
End Sub
Note You can also create nested namespaces without nesting the definitions,
by using the fully qualified name. For example, you can declare the InsideTop
namespace anywhere by using the following code:
Namespace MyAssembly.Top.InsideTop
12 Module 2: Development Environment Features
Importing Namespaces
Topic Objective
To explain how imports and
aliases can simplify code.
Lead-in Fully qualified names can make code hard to read
Referencing the full Dim
Dim xx as
as MyAssembly.Top.InsideTop.Inside
MyAssembly.Top.InsideTop.Inside
namespace makes code
difficult to read. You can Using the Imports statement results in simpler code by
avoid this by using the providing scope
Imports statement and
aliases. Imports
Imports MyAssembly.Top.InsideTop
MyAssembly.Top.InsideTop
...
...
Dim
Dim xx as
as Inside
Inside
Module ModMain
Sub Perform( )
Dim x As New Inside( ) 'Fully qualified not needed
...
End Sub
End Module
Import Aliases
You can use the Imports statement to create import aliases for parts of
namespaces. Import aliases provide a convenient way to access items in a
namespace. They prevent naming conflicts but still make code easy to write and
understand.
The following example creates an import alias called IT for the
MyAssembly.Top.InsideTop namespace. You can reference any item
belonging to the namespace by using the IT import alias.
Imports IT = MyAssembly.Top.InsideTop
Module ModMain
Sub Perform( )
Dim x As New IT.Inside( ) 'Alias used
...
End Sub
End Module
14 Module 2: Development Environment Features
Assembly name Specify the name of the assembly when compiled into an .exe
or .dll file.
Root namespace Change the root namespace without affecting the name of the
assembly. (A default root namespace is created when you
create the project.) This property affects any fully qualified
names used for variable declaration.
Project output type Choose what type of assembly is generated when your project
is compiled. You can select Windows Application (.exe),
Console Application (.exe), or Class Library (.dll).
Startup object Select an entry point for your application. This is usually the
main form of your application or a Sub Main procedure.
Class libraries cannot have a startup object.
Importing project- Import multiple namespaces. They are then automatically
level namespaces accessible without forcing you to use the Imports statement in
each file within the project.
Some of the frequently used Configuration Property settings are listed below.
Property Purpose
Debugging settings These properties allow you to set debugging options, like for
previous versions of Visual Basic. You can choose how your
application starts up when debugging by starting the project,
starting an external program that calls your code, or displaying
a Web page from a URL that calls your code. You can also
specify any command-line arguments your application needs
for testing purposes.
Build options You can specify an output directory for your compiled code
(\bin is the default). You can also enable or disable the
generation of debugging information contained in the .pdb file.
16 Module 2: Development Environment Features
Manipulating Projects
The following features allow you to manipulate your projects with Solution
Explorer:
Drag-and-drop editing
You can use drag-and-drop editing to move existing project items between
folders.
Context menus
Most items provide context menus that allow you to perform standard
actions, such as adding items to the project, deleting items from the project,
and excluding items from the project, which removes the file from the
project but does not delete the file. If you use Microsoft
Visual SourceSafe®, you can add items to Visual SourceSafe from
Solution Explorer.
Module 2: Development Environment Features 19
Event Logs View system event logs for application, security, and system
events. The Properties window displays information about each
particular event. You can use the context menu to clear the log.
Message Queues Use message queues to send messages asynchronously between
applications. You can view and manipulate any message queues
located on the server by using the context menu for the item.
Performance Use the many performance counters provided by the Windows
Counters platform to monitor system-level and application-level
interactions, such as the total number of logons to the server.
Services Start and stop Windows services from Server Explorer by using
context menus.
SQL Servers View and manage Microsoft SQL Server™ databases directly
from Server Explorer in the same way that you view and
manage data connections.
Method
Class Namespace
Inheritance
The following screen shot shows the Microsoft Visual Basic .NET Runtime
library and its various namespaces. This screen shot highlights the
Microsoft.VisualBasic namespace and shows the classes it contains, including
the DateAndTime class, which inherits characteristics from the System.Object
class.
Module 2: Development Environment Features 23
The following example shows a code section that uses the TODO token and a
custom token named FIX_ASAP:
'TODO create icons for form
'FIX_ASAP bug in form code
24 Module 2: Development Environment Features
The following screen shot shows how the Task List window displays
information based on this example, with three extra items that have been added
to the list manually:
You can use the View menu to specify which types of tasks to display in the
Task List.
The following screen shot shows how to use the Options dialog box to create
the FIX_ASAP token. Notice that the token has been created so that the items
in the Task List display a High priority icon.
Module 2: Development Environment Features 25
If the cursor is positioned within the Dim keyword, the Dynamic Help
window displays links relevant to the Dim keyword at the top of the list.
If the cursor is positioned within the Integer keyword, the Dynamic Help
window displays links relevant to integer types at the top of the list.
26 Module 2: Development Environment Features
You can use the Options dialog box on the Tools menu to configure the items
that the Dynamic Help window displays. The following screen shot shows how
to use the Options dialog box to configure the Dynamic Help window:
Module 2: Development Environment Features 27
Lead-in Color-coding
Many of your
Data View for manipulating data
Visual Basic .NET
applications will use XML
documents to store or
retrieve information. The
IDE provides several XML
features that make it easier
for you to use these types of
documents.
You can use any of the sample macros in your projects by executing them in the
Command window or placing them on menus or toolbars.
Any macros you create are stored in a subdirectory of the Visual Studio
Projects folder in My Documents.
Module 2: Development Environment Features 29
Debugging Applications
Topic Objective
To introduce the topics
covered in this lesson.
Lead-in Setting Breakpoints
The new IDE provides Debugging Code
enhanced debugging
features based on those Using the Command Window
found in previous versions
of Visual Basic.
Setting Breakpoints
Topic Objective
To explain how to set Set breakpoints to halt code execution at a specific line
breakpoints.
Use the Breakpoint Properties dialog box to
Lead-in set conditions
Setting breakpoints in your
project allows you to step
into your code under a
variety of conditions.
You can use the Breakpoint Properties dialog box to make a conditional
breakpoint. This feature works in a way similar to watch expressions in
previous versions of Visual Basic. You set a breakpoint condition that only
halts execution when a particular condition is true or when a variable has
changed.
32 Module 2: Development Environment Features
The following screen shot shows a breakpoint condition that only halts when a
variable x has a value of 10.
You may also want to halt execution only when the breakpoint has been
reached and the breakpoint condition has been satisfied a specific number of
times. This number is called the hit count.
The following screen shot shows how you specify that you want execution to
stop the third time that the breakpoint is reached and the breakpoint condition is
satisfied:
Module 2: Development Environment Features 33
Debugging Code
Topic Objective
To discuss how to debug
code and use the various
debugging windows. Use the Debug menu or toolbar to step through code
Lead-in Use the debugging windows:
Several aspects of
debugging in Locals: to view and modify local variables
Visual Basic .NET will be
familiar to Visual Basic Output: to view output from the compiler
developers. Watch: to view watch expressions
Call Stack: to view call history, including parameter
information
Breakpoints: to view, add, or temporarily disable
breakpoints
(continued)
Debug window Use this window to:
Call Stack View the history of calls to the line of code being debugged.
This window displays the history of the call, including any
parameters to procedures and their values.
Breakpoints View a list of current breakpoints, including information such as
how many times the breakpoint has been called, and the conditions
the breakpoint has met.
You can also add new breakpoints and temporarily disable
breakpoints in this window.
Module 2: Development Environment Features 35
Compilation Options
Topic Objective
To describe the options
available when you compile
a project. Build configurations
Lead-in Debug – provides debug information
There are several
compilation options Release – optimizes code and executable size
available to you when
you compile your Build options
Visual Basic .NET projects.
Build – only builds changed projects
Rebuild – rebuilds project regardless of changes
Build Configurations
There are two types of build configurations for Visual Basic .NET projects:
Debug
During the development phase, you may want to build and test your
applications by using compiled assemblies. The Debug configuration
produces a .pdb file that contains debugging information. Other applications
can use this file to debug your code. To assist these other applications, no
optimizations are made to your code. Other applications have access to your
complete and original code.
Release
After testing is completed, you will want to deploy your application to client
computers. The Release configuration performs various code optimizations
and attempts to minimize the size of the executable file. No debugging
information is generated for a Release configuration build.
Build Options
You can choose what to build by selecting the appropriate Build menu options.
Build
The Build option only builds project items whose code has changed since
they were last compiled.
Rebuild
The Rebuild option compiles all project items even if they have not been
modified since they were last compiled. Use this option when you want to
be sure your application contains the latest code and resources.
Module 2: Development Environment Features 41
Prerequisites
Before working on this lab, you must have experience with developing
applications in an earlier version of Visual Basic.
Scenario
In this lab, you will explore the Visual Studio .NET IDE and use its features to
create a data connection and view event log information. You will create a
simple Windows-based application and add a prewritten form to the project.
Finally, you will debug the application by using the various debugging features
of the IDE.
Exercise 1
Becoming Familiar with the Visual Studio .NET IDE
In this exercise, you will use Server Explorer to create a data connection for the
Northwind SQL Server database. You will investigate Server Explorer, and the
event logs in particular. You will then view the Options dialog box to become
familiar with the default IDE settings.
The purpose of this exercise is for you to become familiar with the IDE, so take
time to explore any parts of the IDE that are interesting to you.
4. Click Test Connection to verify that you have successfully made the
connection, and then click OK.
5. Click OK on the Data Link Properties dialog box.
6. If you are not familiar with the Data View window from previous versions
of Visual Basic or Microsoft Visual InterDev®, explore the list of tables,
views, and stored procedures by expanding the newly created
servername.Northwind.dbo data connection.
Exercise 2
Creating a Visual Basic .NET Project
In this exercise, you will create a simple Visual Basic .NET project and remove
the default form from the project. You will then add a prewritten form to the
project and change the Startup object property of the project.
The prewritten form displays a text box and a command button. When you
press the button, the value in the text box is sent to a subroutine. This
subroutine verifies that the value is not empty and displays a message based on
the value. If the value is empty, an error message appears.
Exercise 3
Using the Debugger
In this exercise, you will use the Visual Studio .NET debugger to debug the
simple application that you created in the previous exercise.
You will set a breakpoint to halt execution in the btnDebug_Click event
handler and use the debugger to step through the subroutine. You will examine
the parameter passed to the PerformValidation procedure and change the
value by using the Locals window. You will then step through the rest of the
code and verify that the correct message appears. Finally, you will modify the
breakpoint so that it is conditional, and use the Command window to perform
various IDE functions.
To set a breakpoint
1. On the View menu, point to Other Windows, and then click Task List.
2. Right-click anywhere within the Task List window, point to Show Tasks,
and then click All.
3. Double-click the single TODO task to navigate to the comment in the code.
4. Place the pointer on the line immediately after the TODO comment and
press F9, the breakpoint shortcut key.
Review
Topic Objective
To reinforce module
objectives by reviewing key
points. Describing the Integrated Development Environment
Lead-in Creating Visual Basic .NET Projects
The review questions cover
some of the key concepts Using Development Environment Features
taught in the module.
Debugging Applications
Compiling in Visual Basic .NET