Visual Basic .NET - Lesson 1: Introduction to Applications
Home

Introduction to Microsoft Visual Basic .NET

 

Microsoft Visual Basic .NET Fundamentals

 

Introduction

Microsoft Visual Basic .NET is a programming environment used to create graphical user interface (GUI) applications for the Microsoft Windows family of operating systems. It usually ships in two types, either by itself or as part of Microsoft Visual Studio .NET. To use the lessons on this site, you must have installed either Microsoft Visual Basic .NET 2003 or Microsoft Visual Studio .NET 2003. All instructions on this site will be based on an installation of Microsoft Visual Studio .NET. From now on, unless specified otherwise, we will use the expressions "Microsoft Visual Basic" or "Visual Basic" to refer to Microsoft Visual Basic .NET 2003. If we want to refer to another version, we will state it.

After installing Microsoft Visual Studio .NET 2003, to use the programming environment, you must first open it. To do that, you would click Start -> (All) Programs -> Microsoft Visual Studio .NET 2003 -> Microsoft Visual Studio .NET 2003.

Practical LearningPractical Learning: Launching Microsoft Visual Basic

  • To start Microsoft Visual Studio .NET 2003, on the Taskbar, click Start (All) Programs -> Microsoft Visual Studio .NET 2003 -> Microsoft Visual Studio .NET 2003

 

The Integrated Development Environment: The Title Bar

After Microsoft Visual Studio has been opened, the screen you look at is called an Integrated Development Environment or IDE. The IDE is the set of tools you use to create a program.

The system icon System Icon is used to identify the application that you are using. Almost every application has its own system icon. The system icon holds its own list of actions; for example, it can be used to move, minimize, maximize or close (when double-clicked) a window.

When you freshly start Visual Studio, the main section of the title bar displays the name of the application as Microsoft Developer Environment. Later on, if you start a project, the title bar would display the name of your project, followed by the name of the programming environment you selected.

The main section of the title bar is also used to move, minimize, maximize the top section of the IDE, or to close Visual Studio. On the right section of the title bar, there are three system buttons with the following roles:

Button Role
Minimizes the window
Maximizes the window
Restores the window
Closes the window
 

The Integrated Development Environment: The Main Menu

Under the title bar, there is a range of words located on a gray bar. This is called the menu or main menu. In our lessons, the expression “Main Menu” refers to the menu on top of the IDE. To use a menu, you click one of its words and the menu expands. If an item is missing from the main menu, you can customize it. There are four main types of menus you will encounter.

When clicked, the behavior of a menu that stands alone depends on the actions prior to clicking it. Under the File menu, examples include Close, Save All, or Exit. For example, if you click Close, Microsoft Visual Studio will find out whether the current file had been saved already. If it has been, the file would be closed; otherwise, you would be asked whether you want to save it before closing it.

A menu that is disabled is not accessible at the moment. This kind of menu depends on another action or the availability of something else.

A menu with three dots means that an intermediary action is required in order to apply its assigned behavior. Usually, this menu would call a dialog box where the user would have to make a decision.

A menu with an arrow holds a list of menu items under it. A menu under another menu is called a submenu. To use such a menu, you would position the mouse on it to display its submenu.

Notice that, on the main menu (and any menu), there is one letter underlined on each word. Examples are F in File, E in Edit, V in View, etc. The underlined letter is called an access key. It allows you to access the same menu item using the keyboard. In order to use an access key, the menu should have focus first. The menu is given focus by pressing either the Alt or the F10 keys.

On some menu items, there is a key or a combination of keys we call a shortcut. This key or this combination allows you to perform the same action on that menu using the keyboard.
If the shortcut is made of one key only, you can just press it. If the shortcut is made of two keys, press and hold the first one, while you are holding the first, press the second key once and release the first key. Some shortcuts are a combination of three keys.

From now on, in this book,

Press Means
T Press the T key
Alt, G Press and release Alt. Then press G
Ctrl + H Press and hold Ctrl. While you are still holding Ctrl, press H once. Then release Ctrl
Ctrl + Shift + E Press and hold Ctrl. Then press and hold Shift. Then press E once. Release Ctrl and Shift
 

Practical LearningPractical Learning: Using the Main Menu

  1. On the main menu, click File -> New -> Project...
  2. In the Project Types tree list of the New Project dialog box, click the Visual Basic Projects node 
  3. In the Templates list, click Windows Application
  4. In the Name edit box, type Exercise1
  5. In the  Location text box, type C:\Programs\MSVB unless you are not allowed to create that directory for any reason. In that case, use any directory
     
  6. Click OK
    This creates a new project
 

The Integrated Development Environment: The Toolbars

A toolbar is an object made of buttons. These buttons provide the same features you would get from the (main) menu, only faster. Under the main menu, the IDE is equipped with an object called the Standard toolbar. For example, to create a new project, on the main menu, you could click File -> New -> Project… On the other hand, the Standard toolbar is equipped with a button to perform the same action a little faster: New Project.

By default, the Standard toolbar is positioned under the main menu but you can position it anywhere else on the IDE. To move a toolbar, position the mouse on the dotted line on its left section. The mouse pointer will change into a cross:

Then click and drag away from that position:

In the same way, you can position the toolbar anywhere on the screen. You can also attach or "dock" it to one of the four sides of the IDE. When a toolbar is not docked to one side of the IDE, it is said to float. When a toolbar is floating, you can resize it by dragging one of its borders. If a toolbar is floating, to put it back to its previous position, you can double-click its title bar.

By default, when you start Visual Studio, it is equipped with one one toolbar: Standard. To get more toolbars, on the main menu, you can click View -> Toolbars and click the toolbar of your choice. You can also right-click any available toolbar or the main menu. This displays a list of all the available toolbars. Those that are currently opened have a check mark next to them. You can get a list of the toolbars that are available if you right-click any button on any toolbar or menu. On this site, every toolbar is referred to by its name.

A toolbar is equipped with buttons that could be unfamiliar. Just looking at one is not obvious. To know what a button is used for, you can position the mouse on top of it. A tool tip will come up and display for a few seconds.

From now on, each button on any toolbar will be named after its tool tip. This means that, if a tool tip displays "Hungry", its button will be called the Hungry button. If a tool tip displays "Exercises and Assignments", its button will be called the Exercises and Assignments button. If you are asked to click a button, position your mouse on different buttons until one displays the referred to name.

Some buttons present an arrow on their right side. This arrow represents a menu.

Like the menu, the toolbars can be customized.

Practical LearningPractical Learning: Customizing a Toolbar

  1. To customize the Standard toolbar by adding buttons to it, right-click anything on the main menu or the toolbar and click Customize...
  2. On the Customize dialog box, click the Commands tab
  3. In the Categories list, click Debug
  4. In the Commands list, click and drag Start Without Debugging
  5. Position it somewhere in the Standard toolbar:
     
  6. Release the mouse
  7. Click the Close button on the Customize dialog box
 

The Integrated Development Environment: The Studio Windows

 

Introduction

When creating your applications, you will use a set of windows that each accomplishes a specific purpose. Some windows are represented with an icon but hides the rest of the body. For example, by default, on the left of the screen, you may see an icon made of two computers . To display such a window, you can position the mouse on it. This would expand the window:

If you expand a window, it would display a title bar with two buttons. One is called Auto Hide and the other is the classic Close button:

If you expand a window but find out you don't need it any more, you can just move the mouse away from it. The window would return to its previous state. Based on this functionality, if you are working with a window and move the mouse away from it, it would retract. If you need it again, you would have to reopen it using the same technique. If you are going to work with a certain window for a while, you can keep it open even if you move the mouse away. To do this, click the Auto Hide button. If clicked, the Auto Hide button changes from pointing left to pointing down.

When Visual Studio opens, it make some windows necessary. These are the most regularly used windows. If you think that one of them is not regularly used in your types of assignments, you can remove it from the screen by clicking its Close button. All of the windows you can use are listed in the View menu. Therefore, if a window is not displaying, you can click View on the main menu and click a window of your choice.

By its default installation, Visual Studio installs some windows to the left and some others to the right of the screen. You can change this arrangement if you want. To do this, expand a window, then drag its title bar to another location on the screen. Windows can then be "coupled", that is docked together to one side of the screen. When windows are grouped, they automatically create tabs, allowing you to select the desired one by clicking its tab. 

The options available in windows display differently depending on the window and the items in it. Some item are organized in a tree list equipped with + or – buttons. To expand a list, you can click its + button. To collapse a list, click its – sign. Some other items appear as button.

Studio Windows: The Server Explorer

The Server Explorer is an accessory that allows you access SQL Server databases without using the physical server and without opening Enterprise Server or SQL Query Designer.

The items of this window display in a tree. To expand a node, you can click its + button. To collapse it, click its - button. Later on, you will see that you can drag some items to add to your application.

 

Studio Windows: The Toolbox

The Toolbox is one of the most regularly used windows. It provides objects called Windows Controls or simply, controls. Because there are so many items available, the Toolbox organizes them by categories and each category is represented with a button. To display a category, you can click its button. This causes the other categories to be hidden. In the same way, you can click a different category. The available items in each category appear as buttons, you can click one of these to select it.
 

Studio Windows: The Solution Explorer

Solution Explorer The Solution Explorer is window that displays the "physical" items used in your project.

The items of this window display in a tree. To expand a node, you can click its + button. To collapse it, click its - button. To explore an item, you can double-click it. The result depends on the item you double-clicked.

Studio Windows: The Class View

The Class View displays the various classes, including there ancestry, used by your project
Class View

The Resource View displays an organized tree list of the resources used on a project

 

Projects Fundamentals

 

The .NET Framework

In the early days of Microsoft DOS, there was a language called Basic. It provided a simplified and easy way to create small applications using words very close to the English language. Since the language was easy, it became popular with the help of Microsoft operating systems gaining ground. To continue this tendency and provide more support for Basic, Microsoft used that language as the platform to create graphical user interface (GUI) applications. Once again, this move was welcomed and the language became the widely accepted Visual Basic.

The Microsoft Visual Basic programming environment became very popular for its ease of use and it was a candidate for serious productive applications. Because Visual Basic was not tied to the operating systems low-level operations, its programmers had to use library calls to access functions of the Win32 Application Programming Interface (API), the library that "defines" Microsoft Windows. This also accentuated the difference with other programming environments like Microsoft Visual C++ or other libraries like Microsoft Foundation Class (MFC). In fact, although Microsoft shipped Visual Studio 6 that combined various programming environments with different languages (Visual Basic, C++, ASP, Win32, etc), the only real thing they had in common was that they shipped in the same box (and the same DVD).

To unify the various languages or programming environments that Microsoft had developed for many years, the company created a new library aside from Win32. This was the birth of the .NET Framework. This library is used by, or shared among, different programming languages or environments so that programmers can benefit from a better collaboration. Now it is possible for people who "speak", that is, people who program in, different languages to work on the same project with less regard for compatibility issues. This is because (most of) the functions, classes, and resources, are used in conceptually the same way in the different languages.

Microsoft Visual Basic .NET is Microsoft's implementation of the .NET Framework for Visual Basic programmers. Although Visual Basic .NET is a "child" of Visual Basic 6.0, there are many differences that can be interpreted as a complete shift, with a lot of improvements. Because of these differences, many already Visual Basic 6.0 programmers resisted the move to this new environment (there were also many other considerations) but those programmers are catching up.

On this site, we are going to learn how to use the .NET Framework to create graphical (GUI) applications using the Microsoft Visual .NET and the Microsoft Visual Studio .NET environment. This site assumes that you are familiar with our VBasic lessons intended to lay a foundation for Visual Basic .NET. This means that, in our lessons, we will not define such concepts as variables, procedures, classes, inheritance, properties. We will cover only issues that are related to graphical application development.

 

Creating a Project

A computer application, also called an application, also called a computer program, also called a program, is a series of instructions that present messages and choices to a person, also called a user. This interaction allows the user to partially control the computer, including "telling" the computer what to do, when, and how. You, as the programmer, create instructions that allow a user to interact with the computer. The instructions are created in plain English using a language called (Basic or in this case) Visual Basic.

To create a project, you can display the New Project dialog box, select Visual Basic Projects, select the type of project, give it a name, specify its directory, and click OK.

 

Writing Code

The instructions used in a Visual Basic project are created in a normal, text-based, computer file. These instructions are also referred to as code. Besides being a regular text file, this file has the extension .vb (some other flavors of Visual Basic use other extensions, such as .vbs). A file that carries normal Visual Basic code is also called a module. There are two primary ways you can get a module depending on how you create your application:

  • You can use Notepad, type your code, save the file with a .vb extension, and then add it to your application
  • Probably the fastest way to get a module consists of using Microsoft Visual Studio .NET. To do this, on the main menu, you can click Project -> Add Module

If you create your application using Microsoft Visual Studio .NET, there are two main ways you can get a module. To create a module independent of any other object, on the main menu, you can click Project -> Add New Item..., select Module, give a name to the file, and click Open. If you create a project using a wizard and get a form, a module is automatically associated with it and it is used to carry the instructions of the form. On this site, we will use Visual Studio .NET to create our applications.

To indicate that a module contains code, the section that contains code starts with the Module keyword followed by a name for the module, and ends with the expression End module

 

Compiling and Executing a Project

As mentioned already, the instructions created for a Visual Basic project are written in plain English in a language easily recognizable to the human eye. To compile and execute a Visual Basic .NET project in one step, on the main menu, you can click Debug -> Start Without Debugging. Although there are other techniques or details in compiling (or debugging) and executing a project, for now, this is the only technique we will use until further notice.

 

Practical LearningPractical Learning: Executing a Project

  1. To execute the application, on the main menu, click Build -> Build Solution

  2. To execute the application, on the Standard toolbar, click the Start button

  3. After viewing the application, close it

 

Opening a Project

As opposed to creating a new project, you can open a project that either you or someone else created. To open an existing project, on the main menu, you can click File -> Open -> Project... You can also click File -> Open Solution on the main menu. Alternatively, you can display the Start Page and click Open Open. In all cases, the action would display the Open Project dialog box. This allows you to select a Visual Project and open it.

When opening a project, if the application was created using Visual Basic 6.0, a wizard would guide you to upgrade the project.

 

Copyright © 2004-2008 FunctionX, Inc. Next