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 My 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 Figure 2-1: The Visual Studio IDE
Configuring Visual Studio and Help System Options dialog box Help System Note: Options Dialog Box may appear different from the textbook depending upon the versions and service packs. Yet, the same functions can be found somewhere in the options. I don’t know the incentives of Microsoft engineers who changes those settings. Therefore, I will not go over the details of options and help system as it appears to be impossible to accommodate all the versions. However, the Visual Studio should be configured correctly before creating any applications, and help functions are extremely useful when you encounter a new class or new methods.
Object Browser The Object Browser is used to examine the types that make up the .NET Framework class library and the types in developer-created applications The Object Browser has a drill-down interface The Object Browser is another kind of help, yet very helpful. When you want to use a method from library class, this will tell you the syntax.
Figure 2-22: Object Browser – My Solution Component Selected Do not close object browser using the X mark at the top right corner, it will close the Visual Studio itself. The Object Browser is a tabbed page in the main screen.
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 Project Characteristics A project contains one or more namespaces Every project has one root namespace Every project has a type (Console, Windows, etc.) Every project has an entry point A Sub procedure named Main or a form Forms apply only to Windows Application projects Project References A project has references to .NET Framework class library namespaces .NET automatically adds references to commonly used namespaces based on the type of project template Use the References tab of the project property page to add additional namespace references
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 Organization of a Visual Studio Solution The Solution Explorer is used to manage the elements of a solution The folder named My Project contains configuration information common to all projects The file AssemblyInfo.vb contains assembly metadata The References folder contains references to other assemblies The bin folder contains the executable file produced as a result of compiling the application A project contains one or more modules
Document Windows Document windows are used to edit the files that make up a solution The Windows Forms Designer is used to create a form’s visual interface The 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