Wal Mart Online → Best Selection
WM468X60_ko_static.gif

Last Modified:
9-15-2010

Home


Visual Basic

Introduction to VB.NET

.NET Framework

VS2008 IDE

How VB is Compiled

Start Visual Studio


Windows Form App


Save Your Work

VB OOP Programming

Visual Basic Code


Exit Code


Button Event Code

Coding Recommendations

If/Then/Else

Error List Window

Comment Syntax

Help Window

Language Essentianl

Built-In Data Types


Declare Variables

Declare Constants

Code Arithmetic Expressions

Assignment Statements

Operator Precedence

Type Casting


Math Class

String Declaration

Conversion Functions

Conversion Methods

Formatting Functions

String Formatting


Variable Scope

Enumerations

Nullable Types


Loop Constructs

For Next Loop

Do While Loop


Do Until Loop

Do...Loop-While

Do...Loop-Until


Exit Do | Exit For

Do...Loop


Nested Loops


Arrays

Array Declaration


Rnd( ) Function

Listbox Control


KeyPressEventArgs


Parallel Arrays

Key Event Args


Dynamic Arrays

Redimension Array

Set Breakpoint

Start Debugger


ReDim Preserve


MultiDimensional Arrays

DataGridView Control


Length and Sort Methods


Structures

Pad Right

Split Method

IsNumeric Function


Multiform Projects


Add Form To Project

Form Object Methods

Form Show Method

ShowDialog Method

Form Close Method

Form Accept Button

Multiform Project Example


ASP.NET Web Programming

Create Data Source


Configure Access Data Source


Add Product Class


Extract Local Database Data

Order PageLoad VB Code

Add New Web Page


Set Start Page

Display Cart Aspx Code

Display Cart Design View

Sorted List Definition

VB.NET Session State


Create CartItem Class

GetCartContents Function


Add To Cart Event Handler

Remove Cart Item Event


Clear Cart Event Handler



Save Your Work!!

It is recommended that you save your work at frequent intervals by executing the File → Save All option from the File Menu as indicated in the diagram below:

File Save All

Figure VB-19: Visual Basic File → Save All


The first time that you perform a File → Save All operation, Windows will notice that there is no previously saved copy of the project. This will give you the opportunity to save your project under a different name or in a different location. This is especially useful when you are making a copy of a previously written program that you would like to start as a new project. By selecting the Browse button, you may make changes as you deem appropriate. At this time, however, for simplicity, we are going to keep all the default values as Windows as selected them for us. Press Save as indicated in the diagram below:

Save Project

Figure VB-20: Visual Basic Save Project Dialog Box


At this point we have written no code in our Visual Basic project. So, if we were to "Run" this program there should be no errors and the program should execute and terminate "smoothly". To test this out, Press the Green Triangle Start Debuggin located in the Visual Basic Toolbar as indicated in the diagram below:

Start Debugging

Figure VB-21: Visual Basic Start Debugging


Theoretically, all should go well, and a new copy of our Invoice Total Form should display. This will be what to expect if our startup code has no errors. The diagram below shows the Invoice Total Form at Runtime with none of the controls activated:

Invoice Total At Runtime

Figure VB-22: Visual Basic Invoice Total Form At Runtime - No Code


Introduction to Visual Basic Object Oriented Programming

Whether you realize it or not, you are using object-oriented programming as you design a Windows form with Visual Studio's Form Designer. That's because each control on a form is an object, and the form itself is an object. These objects are derived from classes that are part of the .NET Class Library.

When you start a new project from the Windows Application template, you are actually creating a new class that inherits the characteristics of the Form. The Form, in turn, is part of the .NET Class Library. Later when you run the form, you are actually creating an instance of your form class, and this instance is known as an object.

Similarly, when you add a control to a form, you are actually adding a control object to the form. Each control is an instance of a specific class. For example, a text box control is an object that is an instance of a specific class. For example, a TextBox control is an object that is an instance of the TextBox class. Similarly, a label control is an object that is an instance of the Label class. This process of creating an object from a class can be called instantiation.

As you progress through this guide, you will become more familiar with classes and objects because Visual Basic is an object-oriented language. Later we will actually create classes. At that point, we can start to understand what is happening as we work with classes and objects. For now, we will just get comfortable with the terms and concepts and understand that a lot is going on behind the scenes, and we will begin to understand those processes as we progress through this guide.

To help illustrate this concept observe the following diagram:

Form Only

Class and Object Concepts

  • Object: Self-Combined unit that combines code and data.
    • Examples: Forms and Controls.
  • Class: Code that defines the characteristics of the object.
    • A Class is a template for the object.
      • TextBox Icon in Toolbox is a class.
      • TextBox becomes an object as we set the properties.
  • Instance of a class: When the class icon becomes an object.
  • One or more instances can be created from a class.
    • Each TextBox on our Form is an instance of the TextBox class.
    • Each TextBox shares characteristics (class) but they are unique (object).

Property, Method and Event Concepts

  • Property: Defines the characteristics of an object and the data associated with it.
  • Method: Operations the object can perform.
  • Event: Signal sent by the object to the program telling that something has happened.
    • Examples: Mouse Move, Mouse Key Press, Keyboard Key Press
  • Members: Properties, Methods and Events of an object.
  • When two or more instances of an object are instantiated (created) from the same class, they all have the same properties, methods and posssible events. However, the values that we assigned to each object were slightly different.

Objects and Forms

  • When you use the Visual Basic Form Designer, Visual Studio automatically generates Visual Basic code that creates a new class based on the Form class. Then when you run the project, a form object is instantiated from the new class.
  • When you add a control to a form. Visual Studio automatically generates Visual Basic code in the class for the Form that instantiates a control object from the appropriate class and set's the control's default properties. When you move and size a control, Visual Studio automatically sets the properties that specify the location and size of the control.

Figure VB-23: Visual Basic Class, Object, Property, Method and Event Concepts


Adding Code to the Invoice Total Form

Make sure that the Invoice Total program has been terminated by pressing the Red 'X' Red X at the top right of the form. Select the Form1.vb[Design]* tab and double-click on the Exit button as indicated in the diagram below:

Double Click Exit

Figure VB-24: Select Visual Basic Form1 Design and double-click Exit Button


Double-Clicking the Button will bring up the source code window. To view the source code for the
Exit button press the Button Below:



Help Support this site


Thank you


Web Developers
Software Developers