Wednesday, February 25, 2009

Content of Visual Basic

Introduction to Visual Basic

History of Visual Basic
VISUAL BASIC is evolved from the earlier DOS version called BASIC. BASIC means "Beginners Allpurpose Symbolic Instruction Code". It has been around for more than 35 years. BASIC was further developed as Visual Basic to make it compatible with today's environment. Microsoft created the enhanced version of BASIC, called visual basic.
The bottom line of the enhancement is that VISUAL BASIC can create Windows programs whereas BASIC could only create DOS programs. It means that BASIC programming is done in a text-only environment and VISUAL BASIC programming is done in a graphical environment.

Graphical User Interface

Graphical User Interface
VISUAL BASIC makes use of GRAPHICAL USER INTERFACE (GUI) for creating robust and powerful applications.
A simple GUI looks like this:
GUI given above shows graphical interaction between user and system. That is why a GUI is an effective mean of making your application user friendly and is the key to creating successful applications.
GUI becomes very popular because users can easily identify things with the help of graphics. The main advantage of using GUI is that user can interact with application using common sense. Even a laymen user can learn GUI applications easily.

Getting started with visual basic

Getting started with visual basic
This module will tell us , how to open the Visual Basic software, about the interface of Visual Basic , so that we'll versed with its looks and feel.

Visual Basic Integrated Development Environment(IDE)

Visual Basic Integrated Development Environment(IDE)
VISUAL BASIC IDE (INTEGRATED DEVELOPMENT ENVIRONMENT ) is the environment in which its program are written and executed. IDE stands for Integrated Development Environment. IDE is a term commonly used to describe the interface and environment for creating your application. It is called IDE because you can access all of the development tools that you need for developing an application.

VISUAL BASIC IDE contains different components. These components are:
Tool Bar
It provides quick access to commonly used commands in the programming environment. You click a button on the toolbar to carry out the action represented by that button. The Standard toolbar is displayed when you start Visual Basic. You can change toolbar settings by selecting Toolbars option form View menu.
Toolbar can be removed from beneath of the menu bar, if you click on the Left Edge and drag it away from the menu bar.
For Animated Presentation Click Here
Form Designer
Form objects are the basic building blocks of Visual Basic application.It is the actual window with which a user interacts at the start of application. Forms have their own properties, events, and methods with which you can control their appearance and behavior. Properties, events, and methods of a form will be explained further in tutorial.
The Form Window is central to developing Visual Basic applications.It is the window where you draw your application
Tool Box
The Toolbox is a long box with many different icons on it. It is the selection menu for controls (objects) used in your application. To work in Visual Basic we've to know about its tools so that we can make different forms, projects and how to edit them. we'll learn all these things in this module.
For Animated Presentation Click Here
Property Window
Properties Window is used to establish initial property values for objects (Like Form etc.). The drop-down box at the top of the window lists all objects in the current form.Two views are available: Alphabetic and Categorized. Given box shows the available properties for currently selected object:
If you are not getting property window on IDE then click on Project Explorer option from view menu. Or, Use key F4 or Alt+V+W for displaying property window.
Project Explorer
Project Explorer Window displays a list of all forms used in making up your application. You can also obtain a view of the Form or Code windows (window containing the actual Basic coding) from Project Explorer window.
If you are not viewing Project Explorer on IDE then click on Project Explorer option from the view menu. OR, Use Ctrl+R for displaying Project Explorer Window.
Menu Bar
It is a horizontal strip that appears across the top of the screen and contains the names of menus.Menu Bar lists the menus that you can use in the active window.
You can modify the menu bar using the Commands tab of the Customize dialog box. For that go to the View menu ,then select Toolbars. Now Click on the customize option. OR, You can use key combination Alt+V+T+C for that.
A window will appear like the figure given below:
A list of options will be displayed .A user can make a selection in order to perform a selected action. Suppose if you want to animate menu options then click on the options in above figure. OR, Use key combination Alt+V+T+C+O for animation.
Form Layout Window
Form Layout Window shows where (upon program execution) your form will be displayed relative to your monitor's screen:
Click on to the Form Layout window option from view menu for displaying above window. OR, Use Key Combination Alt+V+F for that. It allows you to visually position your forms .
All forms will be displayed whenyou place your cursor over a form. Press the mouse button,and drag it where you want the position of your form.

Application Of Visual Basic

Application Of Visual Basic
Visual Basic is the most sophisticated tool for developing commercial applications .Various information system are implementing in VISUAL BASIC today,these are as follows:
Various information system are implementing in VISUAL BASIC today,these are as follows:
MIS(Management Information System),
EIS(employee Information System),
Inventory control,
ERP(Enterprise Resource Planning),
Web application,
Library Management System Etc.
VISUAL BASIC is mostly used in application programming. VISUAL BASIC provides easy to use connectivity with database that is why most of database related software are being developed in VISUAL BASIC today.
A simple VISUAL BASIC application works like given in fig:

Data types and modules

Data Types
Visual Basic supports different types of data types according to the needs of program or application
You can say that attribute of a variable that determines what kind of data it can hold is known as Datatype.
By Default Visual Basic supports the variant data type.Declaring a variable variant indicates that it can support all types of data types.Mainly Visual Basic supports the following datatypes:
Table of Data Types
Data Types Storage (in bytes) Prefix Example
Byte 8 Byt bytVar
Boolean 1 Bln blnNum
Integer 2 int intCount
Long; 4 lng lngNumbers
Single 4 sng sngAverage
Double 8 dbl dblMarks
Date 8 dte dteNext
Object 4 obj ObjMywork Avgs
String According to the length of string str strNames
Variant 16 vnt vntTotal

Variables

Variables
Any programming language requires to store values temporarily for different purposes like calculations Adding, multiplying etc.Visual Basic gives the need for variables. You can think of variable, a place in memory of computer for an unknown value.
For example when you call someone, then you call him /her by name, like that every variable has name.
Variable name is the word which you use to refer to the values that the variable contains.
VARIABLES:- Naming convention
There are different rules for assigning names to variables ,these are as follows:
A variable name must begin with a letter.
For example:
6date - Invalid variable name
date6 - valid name
Two variables must not contain the same name.
It can not contain a dot or space.
For example:
Num2 - Valid variable name
Num.2 - Not Valid
Num 2 - Not Valid
A variable name must not exceed 255 chracters.
A variable name must not contain any special characters like %, $ , * , & ,! ,@ etc.
For example:
@num, num$r are not valid variable names.
Variable:-Declaring
The term declaring a variable means that the memory is allocated .This memory will be referred by a name decided by the programmer.The specific data type decides the amount of memory allocated.
You can declare a variable with a Dim statement by giving a name for the variable according to rules of naming conventions.
Syntax: Dim variablename as Datatype
Example: Dim a as integer
In above example 'a' is variable name and integer is the data type.
Rules for declaring variables:
(i) Declaring a variable using the word Public makes it available throughout the program.
(ii) Declaring a variable using the word Static keeps it's value preserve until a procedure ends.
(iii) Declaring a variable in the declaration section of the form makes it available to all procedures in that module.
For example:
Let us consider the variable 'var1 '. An integer variable 'var1' is declared. At the same time memory is allocated for the variable.
The variable is given value 20 during the running state of the program. This value is stored in the given memory location.
This process is shown in figure:

Constants

Constants
Constants as the name suggests , never change during the execution of program.They remain same throughout the program execution.
When the user wants a value that never changes, a constant can be declared and created.
The syntax for declaring a constant is:
(Public|Private) Const constantname (As type) = expression
The const statement can be declared as:
Public const pie as single=3.14

Modules

Modules
A module is a set of functions and a set of data members.Code in Visual Basic is stored in the form of Modules. Collection of general procedures, variable declarations, and constant definitions used by application is known as module.
Mainly Visual Basic supports 3 types of modules:
(1) Form module
(2) Standard Module
(3) Class Module
Form module
Form modules provide the user interface to the application. They contain controls and properties of the forms. They have the extension .FRM.
Their declaration is private by default, therefore each form has a single form module associated with it.
Standard Module
As we go further in developing the application than there may be common code for execution of several form.
For avoiding the duplication of code, a separate module containing the code is implemented.
This is called as standard module. A standard module (.BAS) contains only code. It contains extension .BAS.
Class Module
A class module (.CLS) is used to create objects (forms etc.). It can be called from procedures within your application.
Class modules (.CLS filename Extension) are writing code in class modules can create the building blocks of object oriented programming in Visual Basic.New objects.
Each module contains different elements, these are:
Declaration
It includes constant and procedures.
Procedures
Sub function or property procedures that contain pieces of code that can be executed as a unit. It avoids code repetition.

operaters

Arithmetic Operators
Arithmetic operators are used for mathematical expressions.
The given table shows various arithmetic operators and their description:
Operators Symbol Description of Symbol
Subtraction - Subtracts two operands (val1-val2)
Addition + Adds two operands (val1-val2)
Multiplication * Multiply two operands (val1*val2)
Division / Divides 2 operands (val1/val2)
Negation ~ Negates the operand
Modulo Mod Gives the remainder after division (Val1 mod Val2)
String Concatenation & Concatenates two strings (val1 & val2)
Exponentiation ^ Raises the first operands to the power of second operand (val1^val2)

Logical Operators

Logical Operators
These are also known as Boolean operators.Boolean operators are used in the conditions where condition can be true or false case.
Basically logical operators are used to form logical expressions that represent true or false conditions.
For Example:
The 'Or' operator returns the result when only one operands is true.
The given table summarizes various logical operators and their description:
Operators Description of Symbol
Not Return the negative of two expressions.
And Returns true only when both conditions are true.
Or Returns true when only one condition is true.
Imp Returns false only when 1st operand is true and 2nd is false.
Eqv Returns true only when both conditions are true.
Xor Return true only if both operands are of opposite sign.

Relational Operators

Relational Operators
There are six relational/Comparison operators used in testing expressions.
They are >= (greater than or equal to), <= (Less than or equal to), < (less than), > (greater than), <> (Not equal to).
Comparison operators are used to compare two expressions.They are also known as relational operators.

The table below contains a list of operators used in Visual Basic:
Operators Function
< First expression is less than second.
<= First expression is less than or equal to second.
> First expression is greater than second.
>= First expression is greater than or equal to second.
<> First expression is not equal to second.
= First expression is equal to second.

Arrays

Introduction of Array
An array is the collection of similar data types.The individual elements of an array is identified by using an index.
Each index number in an array is allocated individual memory space. Hence users declare arrays of larger size than required.
Array helps in creating smaller and simpler code in many situation.You can setup loops that deal efficiently with any number of cases by using the index number.
A loop is used to execute a group of statements repeatedly, based on a condition.

Declaration Of Array

Declaration Of Array
Syntax:
Dim arrayname(number) as Datatype
Example:
Dim total(10) as integer

Here total is name of array ,10 is no of elements in the array & integer is the data type.Number 10 included in the parenthesis is the upper limit of the array.
The above declaration creates an array with index numbers ranging from 0 to 9.
If you want to specify lower limit ,then the parenthesis should include both the lower and upper limit along with the 'To' keyword.
An example is shown below
Dim num(1 To 5) As integer
In above statement, an array of 5 element is declared but with the index numbers ranging from 1 to 5.
Mainly Visual Basic supports 2 types of Array:
Fixed-Size array:
The size of array always remains the same.
Dynamic array:
The size of array can be changed at run time.

Conditional statement and loop structure

If...Then..Statement

If...Then..Statement
The If...Then statement is used to evaluate whether a condition is True or False.
You can use If…Then block to execute one or more statements conditionally.
Syntax:
If <condition> Then
[statements]
Else
[else statements]
End If
Example:
if a>5 Then a=a+10
Here condition is that 'a' should be greater than 5 and if it is true then 'a' should be incremented by 10.
:-The condition is usually a comparison, but it can be any expression that evaluates to a numeric value.
[Statements] :- One or more statements separated by colons; executed if condition is True.
Note that:
1.A single line of If…Then does not use End If statement.
Syntax:-
If condition Then statement.
But if you use this in more than one line ,then syntax will be If…Then…End If.
2.If anything other than a comment appears after Then on the same line, the statement is treated as a single line If statement.
3.A block If statement must be the first statement on a line. The block If must end with an End If statement.
4.When a If condition is tested ,then If condition is True, the statements following Then are executed,otherwise not.

If...Then..Else Statement

If...Then..Else Statement
It conditionally executes a group of statements depending upon value of the expression.
If...Then…Else block is used to define several blocks of statements ,in order to execute one block.
Syntax:
If then
[statements]
Else if Then
[else if statement] . . .
Else
[elsestatement]
End If
Example:
If a<10 class="textbold">then
a=a+10
elseif a>15 then
a=a-10
else
a=100
end if
Note that:
1.Both Else and ElseIf statements are optional. You can have any number of ElseIf statements as you want in an If block. But no ElseIf statement can appear after the Else.
2.Block If statements can be nested. Nested means a block contained within one another.
3.In fact If…Then is just a special case of If…then…Else.
4.If none of ElseIf statement is True ,then the statement following Else will execute.

Select Case Statement

Select Case Statement
It is just as the alternative of If…Then…Else statement.It executes one statement in several groups of statements.
A Select Case provides the same functionality as the If…then…Else statement but it makes the code more efficient and readable
A Select Case works with a single test expression.
Value of the statements will be dependent on test expression.
Syntax:
Select Case testexpression
[Case expression1
[statements-n]] . . .
[Case expression2
[statements-n]]
.
.
Case Else
Statement..n
End Select
Any numeric or string expression.
Statement executes if Testexpression matches any part of expressionlist.
Example:
The following example describes the use of the Select Case statement-
Dim num as integer
Dim a(10) as integer
'Calculations containing num
Note "'" Indicates the Comment Line
Select Case num

Case 1 a(1)=num
Case 2 a(2)=num
Case 3 a(3)=num
Case else a(1)=num
End Select
Num is declared as integer variable here and a(10) is declared as an array of ten elements.
Select Case checks values of num, according to that it executes the corresponding case statement.
Note that:
1.Value of the statement will be dependent on expression.
2.The Case Else clause is used to indicate the elsestatements to be executed if no match is found between the testexpression and an expressionlist
3.Select Case statements can be nested.
4.Each nested Select Case statement must have a matching End Select statement.

Do...Loop Structure

Do...Loop Structure
Do…loop is used to execute a block of statements for indefinite number of times. There are several variations of Do...Loop statement.
Each variation evaluates a numeric condition to determine whether to continue execution or not.
Syntax:
Do While
statements…
Loop
Note that:
1.When Visual Basic executes Do While loop, it first tests condition.
2.If condition is False (zero), it skips past all the statements.
3.If it's True (nonzero), Visual Basic executes the statements and then goes back to the Do While statement and tests the condition again.
Example:
Do While count<=5
count = count + 1
Loop
Here loop increments the value of count until it becomes equal or less than 5.
Another variation of Do...Loop statement executes the statement first and then tests condition after each execution. This variation guarantees at least one execution of statements.
Syntax:
Do
Loop While

For...Next Structure

For...Next Structure
For...Next loop is used when you know how many times you want to execute loop.But in case of Do While it is not the case.
Do While is used when you do not know how many times you want to execute that particular loop/Condition.
Syntax:
For counter = start To end [Step increment]
statements
Next [counter]
The arguments counter, start, end, and increment are all numeric.
In executing the For loop, Visual Basic:
1. Sets counter equal to start.
2. Tests to see if counter is greater than end. If so, Visual Basic exits the loop.
3. Executes the statements.
4. Increments counter by 1 or as it's specified.
5. Repeats steps 2 through 4.
Example:
Dim A(40) as Integer
For i = 0 To 40 step 1
A(i)=i
Next
Print A(9)
Here index values are stored in array a(40).Then it prints the value of a(9).

Procedure

Sub Procedures
A Sub procedure is a block of code that is executed in response to an event.
By breaking the code in a module into Sub procedures, it becomes much easier to find or modify the code in your application.
Syntax:
[Private|Public][Static]Sub procedurename (arguments)
statements
End Sub
Each time when procedure is called, the statements between Sub and End Sub are executed. Sub procedures can be placed in standard modules, class modules, and form modules.
Sub procedures are by default Public in all modules, that means they can be called from anywhere in application.
Note that:
Sub Procedures are the procedures that do not return a value.
The arguments for a procedure are like a variable declaration.
Event Procedures
When an object in Visual Basic recognizes that an event has occurred then it automatically invokes event procedure
That event procedure will use procedure name corresponding to that event.
Syntax:
Private Sub Form_eventname (arguments)
statements
End Sub
CmdSave_Click():-Here Click is an event and CmdSave_Click() is the procedure associated with it.
Syntax for a Control Event:
Private Sub Control_Eventname(arguments)
Statements Block
End sub
Syntax for a Form Event:
Private Sub Form_eventname(arguments)
Statements Block
End sub
Example:
Private Sub Form_Load().
This is the main event procedure for a form .When a form is loaded in application then this procedure is called first.
General Procedures
A general procedure tells the application how to perform a specific task. Once a general procedure is defined, it must be specifically invoked by the application.
General procedure remains idle until called upon to respond to events caused by the user or by system.
For Animated Presentation Click Here
Why create general procedures?
One reason is that several different event procedures might need the same task repeatedly.
A good programming strategy is to put common statements in a separate procedure (a general procedure). An event procedure calls that general procedure.
This eliminates the need to duplicate code and also makes the application easier to maintain.
Example:
Suppose you display some message after each event code execution then you will use event procedure.
For adding procedure to your application follow the steps given below:
(1) Go to Tools menu and select Add Procedure form. Or, Use key combination Alt+T+P.
The window will be shown like this:
(2) Write name of procedure Display in the name Box and select type Sub according to figure given above.
(3) Write code for display() after Clicking OK in the previous Step.The code Window will display like this:
(4) Now call procedure in any event associated your application.
( Calling Procedure display() )

Function Procedures

Function Procedures
Function Procedures return values. you can use Function statement to write your own Function procedures.

Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments.
Syntax:
[Private|Public][Static]Function procedurename (arguments) [As type]
statements
End Function
Note that:
1.You call a function by including the function procedure name and arguments on the right side of a larger statement or expression (returnvalue = function()).
2.Function procedures have data types, just as variables. This determines the type of the return value.
3.You return a value by assigning it to the procedurename itself.
Example:
Public function Addition(a,b)
Addition=a+b
End Function
Here Function addition is declared .It takes two arguments and then add these two values. It returns sum of two values.

Property Procedures

Property Procedures
Property procedures are the procedures that return values and also assign values to the property of objects.
Visual Basic provides three kinds of property procedures, as described in the following table.
Procedure Procedure
Property Get Returns the value of a property.
Property Let ets the value of a property.
Property Set Sets the value of an object property.
Property procedures are defined in class modules.
Note that:
If you need to perform a task each time then you need to use a property procedure. Once it is defined, it executes automatically without needing an explicit call each time.

Functions

Visual Basic Functions
A function is a preprogrammed calculation .It can be carried out on request from any point in a Visual Basic program.
A function takes one or more arguments and returns a single value and it can be included in an expression.
Argument:
It is a value on which a function or procedure operates.
For example, in the Visual Basic statement Str(10),
number 10 is the argument.
Visual Basic includes built-in functions like Sqr, Cos or Chr etc.We are discussing some of them here:
(1) Sqr()
Returns a Double specifying the square root of a number.
Syntax
Sqr(number)
(2) ABS()
Returns the absolute, positive value of the given numeric expression.
Syntax
ABS(numeric_expression)

Arguments
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category.
Return Types
Returns same type as numeric_expression.
(3) POWER()
Returns value of given expression to the specified power.
Syntax
POWER(numeric_expression, y)
Arguments
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category.
y Is the power to which to raise numeric_expression. y can be an expression of the exact numeric or approximate numeric data type category.
(4) FLOOR ()
Returns largest integer less than or equal to the given numeric expression.
Syntax
FLOOR(numeric_expression)
Arguments
numeric_expression
Is an expression of exact numeric or approximate numeric data type category. Return Types
Returns the same type as numeric_expression.
For Example:
FLOOR(122.45), Return value=122
FLOOR(-123.45) ,Return value=124
(5) Round()
Returns a numeric expression, rounded to the specified length or precision.
Syntax
ROUND (numeric_expression, length)
Arguments
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category.
length Is the precision to which numeric_expression is to be rounded. length must be int.
When length is a positive number, numeric_expression is rounded to the number of decimal places specified by length.
When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.
Return Types
Returns the same type as numeric_expression.
For Example:
Round(123.4545,2) ,Return Value=123.4500
(6) SQUARE()
Returns the square of given expression.
Syntax
SQUARE(float_expression)
Arguments
float_expression
Is an expression of type float.
Return Types
float
(7) PI ()
Returns the constant value of PI.
Syntax
PI()
Return Types
float
(8) SIGN ()
Returns the positive (+1), zero (0), or negative (-1) sign of the given expression.
Syntax
SIGN(numeric_expression)
Arguments
numeric_expression
Is an expression of the exact numeric or approximate numeric data type category.
Return Types
Float
(9) LOG10 ()
Returns the base-10 logarithm of the given float expression.
Syntax
LOG10(float_expression)
Arguments
float_expression
Is an expression of the float data type.
Return Types
Float
(10) RAND ()
Returns a random float value between 0 and 1.
Syntax
RAND([seed])
Arguments
seed
Is an integer expression (int) giving the starting value.
Return Types
float
Methods

Methods are associated with objects, and define the actions they carryout for their object.

For Example:

The methods of your radio are on, off, volume control etc, Which give you control on your radio.Each Method performs a particular action. Method is an action that an object is capable of performing.

For example:

list boxes have methods called AddItem, RemoveItem and Clear, for maintaining list contents.

Syntax for Calling Method

Syntax for Calling Method
Objectname-Method
Here objectname specifies the name of an object, and Method specifies the name of a method.
Example:
Form1.Print "Hello World"
Here Form1 is form name , and method Print is called to print the String "Hello World" to form.
There are different methods associated with different controls.Methods are useful because they hide the details of how an action is performed.
The programmer just needs to call the method ,how the action is performed it is not his or her headache.
Note That:
Put a dot after the name of control then various options will look like in figure.
Methods associated with some commonly used controls:
List Box
It is control that provides a list of items.
Methods of List Box:
1) Additem: This method adds the specified item to the list
2) Removeitem: This method is used to delete an item from the list.
3) SetFocus: Used to make the list box the Current active element.

Combo Box:
A combo box has all the properties exhibited by the text box and list box.
Methods of combo box:
1.Additem: This method will add the specified item to the combo box.
2.Remove Item: This method will delete an item from the combo box.
Option Button:
Option button are used when the user can select one and only one of the multiple options.
Typically,there are no special methods associated with option buttons.A method associated with option
button is:
Move: Moves a control on the form.
Command Button:
The easiest way to allow the user to interact with an application is to provide a button to click.
Visual Basic provides this in form of Command Button.
One method is used with the command button:
Move: Moves a control on the form

Events

Events
A major part of interaction between people in every day life is in the form of events and response.
For Example
When some one knocks at the door, then you open the door.Knocking at door is event and opening the door is response to the event.
In technical words an event is an user action directed at the application

Example Of An Event In An Application

Example Of An Event In An Application
1.Clicking the mouse.
2.Pressing a key on the keyboard.
When you click on a button it is recognized as an event by the button.
A calculator (Provided in your Windows) shown in figure is the perfect example of events and their quick responses.
For Example
Clicking on a number Button will display a particular number in the text Box.Some of events like methods require additional information in the form of arguments.
For Example,
Click event does not requires arguments whereas DragDrop event requires arguments as shown in example:
Public Sub Command1_Click()
Statements
End Sub
Public Sub Commnand1_DragDrop(Source As Control,X as Single,Y As Single)
Statements
End Sub

Working with forms

Form Basics
A form is a window that contains application code and other objects placed on it to create the user interface. Forms may fill the entire screen or have other forms contained with in it.
Note that:
Visual basic initially includes a default form Form1 file in each project.You can change the name and caption of the form to identify the purpose of the form.
Every form has its own properties ,events and methods associated with it.
Here a sample form is shown, VISUAL BASIC gives default name and caption to a form as form1. It is shown in above figure.
Adjusting of height and width is shown in figure below:
Form objects are the basic building blocks of a Visual Basic application. It is actual window with which a user interacts when they run the application.
Forms have their own properties, events and methods with which you can control their appearance and behavior.
Form Properties

Many properties of a form affect its physical appearance. The Caption property determines the text that is shown in the form's title bar, the Icon property sets the icon that is displayed when a form is minimized.
The MaxButton and MinButton properties determine whether the form can be maximized or minimized. By changing the BorderStyle property, you can control the resizing behavior of the form.

There are some specific properties of the form and a brief description of some selected properties is given here.

Property window of a form is shown below:


Border Style:
Form can have different types of borders.

The borders are as follows:


Caption:
The title of the window is stored in Caption property.It is shown at top of the form.

Icon:
This property specifies the icon for the window in the upper-left corner of the window.

Mouse Pointer:
This displays the value that indicates the type of mouse pointer.

Max Button:
This property indicates whether the maximize Button should be shown and Maximize choice available in the control box menu.

Min Button:
This property indicates whether the minimize Button should be shown and minimize choice available in the control box menu.

MDI Child:
This property specifies if this window must be shown within a multiple document interface (MDI) window. You will discuss them in detail in further section of tutorial.

Back Color:
Back Color is used to fill the back ground color of the form.

Autoredraw:
Setting AutoRedraw to True always produces normal layering. While using AutoRedraw is the easiest way to layer graphics, applications with large forms may suffer from reduced performance due to the memory demands of Autoredraw.

For Example:
By setting Autoredraw property of form to true ,You print any text at the form.

The Form Events

The Form Events
As objects, forms can perform methods and respond to events.The Resize event of a form is occured whenever a form is resized, either by user interaction or through code. This allows you to perform actions such as moving or resizing controls on a form.
The Activate event occurs whenever a form becomes active form, the Deactivate event occurs when another form or application becomes active. These events are convenient for initializing or finalizing the form'sbehaviour.
OR For writing the code for any from use key combination Alt+V+C.
A form's events are shown below in the figure:
For Writing code of a particular event just click on a particular event ,then the following code window will appear:
Here for example you have clicked the MouseUp event.
Using the unload Event:
The unload event procedure is used to verify that the form should be unloaded.The unload event is occurred when:
1.The Form is unloaded using the Unload statement.
2.The form is closed by either clicking the Close command on the application menu or clicking the close button on application title bar.
Commonly used Form Events:
Activate Form_Activate event is triggered when form becomes the active window.
Click Form_Click event is triggered when user clicks on form.
DblClick Form_DblClick event is triggered when user double-clicks on form.
Load Form_Load event occurs when form is loaded.This is a good place to initialize variables and sets any run-time property.

The Form Methods

The Form Methods
Different methods are used in forms. When you put a dot after name of the form then a popup menu is displayed.
There are different methods for forms .Some of them are describing here.
Show method
Show method is used to display the form object.
For Example to display the form frmStudents,
following code is written:
frmStudents.Show
Hide Method
The Hide method is used to hide a form.
For example to hide a form, following code is written:
frmStudents.Hide
The Cls Method
All text and graphics on the form that were created with Print and graphics methods can be deleted with the Cls method.
Example: frmStudents.Cls
The Refresh Method
Forces a complete repaint of a form.
For example:
form1.Refresh
Use the Refresh method when you want to Completely display one form, while another form loads.
Point Method
Returns the red-green-blue (RGB) color of the specified point on a Form. It returns color as a long integer.
form1.Point(x, y)

Setting Runtime & Design Time Properties

Setting Runtime & Design Time Properties
Visual Basic operates in three modes.
1. Design mode - used to build application.
2. Run mode - used to run the application.
3. Break mode - used for debugging application.
Many properties can be set at either design time or run time. At design time controls are added to the form, their properties are set and code is written. During runtime you examine your program in action, just as the end user will see it.
To set a property at design time , following steps are followed:
1. Select the form or object whose characteristics are to be changed.
2. Activate the properties window.
3. Scroll the property you want to set and select its name.
4. Enter a new setting.
At runtime, property can be changed by a program code.
This is done like this:
For Animated Presentation Click Here
when you run the above application then the form1's backcolor, mouse pointer and Caption will look like figure.