Chapter 2 Creating a Console Application with Visual Studio.

23
Chapter 2 Creating a Console Application with Visual Studio

Transcript of Chapter 2 Creating a Console Application with Visual Studio.

Chapter 2

Creating a Console Application with Visual Studio

Class 2: Visual Studio

• Visual Studio IDE

• Create and Compile a Visual Basic project

• Creating Application Comments• MyMy object

Introduction to Visual Studio

• Visual Studio simplifies the process of creating, compiling, and testing applications

• Visual Studio can create applications in Visual C++, C#, J#, and Visual Basic

• The same development environment is used regardless of the programming language

Visual Studio IDE

• Visual Studio IDE (integrated development environment)

• The interface is similar to the interface of other applications

• It has menus, toolbars, a status bar, and windows with which you develop applications

Types of Visual Studio Applications

• Templates are used to create different types of applications– The supported templates vary based on the installed Visual

Studio edition

• Common templates– Console Application project– Windows Application project– Class Library project– ASP.NET Web Application project– Web Service project

Introduction to Visual Studio Solutions and Projects

• A solution is the heart of an application– A solution contains several folders that define an

application’s structure– Solution files have a file suffix of .sln

• A solution contains one or more projects– The project file is used to create an executable

application– A project file has a suffix of .vbproj– Project properties are set using the project's property

pages

Figure 2-26: Project Property Page – Application tab

Creating a New Solution

• Click File, New Project to display the New Project dialog box– Specify the project template and the project file

name

• Different templates appear based on the installed Visual Studio edition

Figure 2-28:New Project Dialog Box

Saving a Visual Studio Project

• Click File, Save All to save the solution the first time

• Specify the solution name and the folder where the solution will be created– By default, a new folder is created for a new

solution

Document Windows

• Document windows are used to edit the files that make up a solution– The Windows Forms Designer Windows Forms Designer is used to create a

form’s visual interface– The Code Editor Code Editor is used to create an application’s

code– Other document windows exist

• Document windows appear on group tabs– Each tab is used to edit a particular document

Figure 2-34:The Code Editor

Code Editor Features

• The Code Editor checks syntax as statements are entered– Statements with syntax errors appear

underlined– Syntax errors also appear in the Error List

window

• The Code Editor automatically indents statement blocks

Using Intellisense with the Code Editor

• Intellisense technology displays pop-up menus as statements are entered

• Intellisense displays classes applicable to a namespace

• Intellisense displays members of a class or other type

• Intellisense displays arguments to functions or methods

Figure 2-35: Intellisense Pop-up Menu

Figure 2-37: Code Editor and Error List Window Displaying Syntax Errors

Compiling and Executing a Visual Studio Project

• Clicking Build ProjectName compiles a project– ProjectName is a placeholder for the actual project

name

• Visual Studio calls the same compiler you called directly in Chapter 1– Project configuration options are used to set the

compiler options

• Compiler output appears in the Output window

Executing a Visual Studio Project

• Pressing F5 builds and runs a project

• Clicking Debug, Start Debugging builds and runs a project

• Console Application output appears in a Command Prompt window

Creating Application Comments

• Comments document an application’s code

• Comments are ignored by Visual Studio

• Comments begin with an apostrophe (')– Comments can appear alone on a line– Comments can appear at the end of a statement

• These comments must appear at the end of a line

– Comments cannot break up a continuation line

• White space lines do not need a comment character

Comments (Best Practices)

• Create comments when developing or modifying an application

• Create a comment block at the beginning of a class or module to describe its purpose

• Create comment blocks for procedures

• Don’t overuse or create unnecessary comments

the My Object

• The My object simplifies programming• My.Application gets information about

the current application• My.Computer gets information about the

computer• My.Computer.Network gets information

about the network• My.User gets information about the current

user

The My.Application Object

• My.Application.Info has properties to get information about project attributes– Description– CompanyName– ProductName– Copyright– Trademark– Version

The My.Computer Object

• My.Computer.Info has properties to get information about the computer– AvailablePhysicalMemory– AvailableVirtualMemory– TotalPhysicalMemory– TotalVirtualMemory– OSFullName– OSPlatform– OSVersion