Monday, June 22, 2009

Visual Basic Notes

Introduction To Visual Basic
Visual Basic:
Visual Basic is a tool that allows you to develop windows (Graphical User Interface-GUI) applications. Visual Basic is event-driven language, which means that the code remains idle unless called upon to respond to some event (button pressing, menu selection, mouse clicking,………….). When an event is detected, the code corresponding to that event is executed.
Features of Visual Basic (VB):
Visual Basic provides the following powerful features.
o Full of objects-----you draw on the application form
o Response to mouse and keyboard actions
o Lots of icons and pictures for your use in application.
o Clip board and printer access
o Full Array of mathematical, String handling, and graphics functions
o Can handle fixed and dynamic variable and control arrays
o Sequential and random access file support
o ActiveX support
o Powerful database access tools
o Useful debugger and error-handling facilities
VB ENVIRONMENT
IDE (Integrated Development Environment)
The Visual Basic IDE is a complete application development environment. The IDE allows you to design, develop and edit an application, debug it for possible errors and the run it to see the output. All these facilities are available in the VB IDE.
The VB IDE consists of the following commonly used components or tools.
1. Title Bar
2. Menu Bar
3. Tool Bar
4. Form Window
5. Toolbox
6. Properties Window
7. Form Layout Window
8. Project Explorer Window
9. Immediate window
Now we explain these components briefly.
1. Title Bar:
The title bar indicates the project name, the current Visual Basic operating mode, and the current form. The title bar appears at the top most of VB IDE.
ii) Menu Bar:
The menu bar has drop-down menus from which you control the operation of the Visual Basic environment. The menu bar consists of menus like File, Edit, View, Project, Debug, and Run etc.
iii) Tool Bar:
The tool bar has buttons that provide shortcuts to some of the menu options like Add Project, New Form, and Save project etc.
iv) Form Window:
The Form Window is the central point to developing Visual Basic applications. It is the place where you draw you application.
v) Tool Box:
The Tool Box is the selection menu for controls used in your application. The Tool Box contains a set of controls like label, command buttons, text boxes, list boxes, option buttons and so on.
vi) Properties Window:
The Properties Window is a set of properties or characteristics that will be assigned to various control objects during designing. These properties include control object name, appearance, back color, caption, size of control and so on.
vii) Form Layout Window:
The Form Layout Window shows where your application form will be displayed relative to your monitor’s screen when the program is executed.
viii) Project Window:
The project window displays a list of all forms and modules. These forms and modules make a Visual Basic application. The project window also contains a view of the form or code windows containing the actual basic coding.
ix) Immediate Window:
The Immediate Window is a small output window. The immediate window allows you to check simple calculations easily and immediately.
You can enable it by using the short cut key Ctrl+G. The immediate window is for testing simple calculations like print 2+3, the immediate window will display the output is 5.
BASIC CONTROLS
Some of the Visual Basic controls are:
1. Check Boxes
2. Option Buttons
3. Frames
4. Command Buttons
5. Labels
6. Text Boxes
7. List Boxes
8. Combo Boxes
9. Picture Boxes
10. Drive List Boxes
11. Directory List Box
12. File List Box
Now we explain them one by one as follow
i) Check Boxes:
Check Boxes provide a way to make choices from a list of values. Some, all, or none of the choices in a group may be selected.
Check Box Properties:
The following are the properties of Check Box
Caption………. Identifying text next to box
Font. …………Sets font type, style, size
Values…………Indicates if Unchecked (0, Vbunchecked),
Checked (1, Vbchecked)
Check Box Events:
Click………Triggered when a box is clicked. Value property is automatically changed by Visual Basic
Option Buttons

Option Buttons provide the capability to make a single choice from a list of values. Hence option buttons work as a group, only one of which can a have a True (or selected) value.
Option Buttons Properties:
The following are the properties of Check Box
Caption………. Identifying text next to button
Font. …………Sets font type, style, size
Values…………Indicates if selected (True),or not (False) One button in a group of
option buttons should always be initialized to True at design time.
Option Buttons Box Events:
Click………Triggered when a button is clicked. Value property is automatically changed by
Visual Basic.
Frames + Command Buttons
Frames provide a way of grouping related controls on a form. To group controls in a frame, you first draw the frame. Then the associated controls must be drawn in the frame. This allows you to move the frame and controls together. And once a control is drawn within a frame, it can be copied and pasted to create a control array within the frame.
FRAME PROPERTIES:
Caption………. Title information at the top of frame
Font. …………Sets font type, style, size
iv- Command Buttons: Command Button is the most widely used control of the Control box.
Command Button Properties:
The following are the properties of Command button
Appearance……Selects 3-D or flat appearance
Caption………. text to be displayed on button
Font. …………Sets font type, style, size
Command Button Events:
Click………Triggered when button is clicked.
Label Box + Text Box
v- Label Boxes:
A label box is a control that you use to display a text that user can’t enter directly.
Label Properties:
The following are the properties of Label box.
Alignment……… Aligns caption within the border.
Appearance……Selects 3-D or flat appearance
Caption………. text to be displayed on button
Font. …………Sets font type, style, size
Label box Events:
Click………Triggered when label is clicked.
Dbclick…..Triggered when label is double-clicked.
vi- Text Box:
A Text Box is used to display information entered at design time, by a user at run time, or assigned within code. The displayed text may be edited.
Text Box Properties:
The following are the properties of text box.
Appearance……Selects 3-D or flat appearance
Caption………. text to be displayed on button
Font. …………Sets font type, style, size
Border Style……Determines type of border.
MultiLine……..Specifies whether text box displays single
line or multiple lines.
Text box Events:
Change………Triggered every time the text box property changes.
KeyPress…..Triggered when a key is pressed.
List Box + Combo Box
List Boxes:
A List Box displays a list of items from which the user can select one or more items.
List Box Properties:
The following are the properties of list box.
Appearance……Selects 3-D or flat appearance
List………. Array of items in list box.
Sorted.……True means items are selected, otherwise
items appear as added.
ListCount…. Number of items in list.
Text……….Text of most recently selected items.
List box Events:
Click……Triggered when an item in list is clicked.
Dbclick…Triggered when an item in list is double- clicked.
vii- Combo Box:
The combo box is similar to the list box. The differences are a combo box includes a textbox on top of a list box and only allows selection of one item.
Combo Box Properties:
The following are the properties of Combo box.
Appearance……Selects 3-D or flat appearance
List………. Array of items in list box portion.
Sorted.……True means items are selected, otherwise
items appear as added.
ListCount…. Number of items in list.
Text……….Text of most recently selected items.
Combo box Events:
Click……Triggered when an item in list is clicked.
Dbclick…Triggered when an item in list is double- clicked.
Picture Boxes
The picture box allows you to place graphics information on a form.
It is best suited for dynamic environments. For example, when doing animation.
Picture box Properties:
The following are the properties of Picture box.
AutoSize……if True, box adjusts its size to fit the displayed graphic.
Font……. Sets the font size, style, and size of picture.
Picture….. Sets the graphics file to display in the picture box.
Picture box Events:
Click……Triggered when a picture box is clicked.
Dbclick…Triggered when a picture box is double-clicked.
Drive List Box + Directory List Box
The Drive List Box control allows a user to select a valid disk drive at run- time. It displays the available drives in a drop-down combo box. No code is needed to load a drive list box.
Drive List Properties:
Drive……..Contains the name of the currently selected drive.
Drive List Events:
Change……Triggered when the user/program changes the drive selection.
xi- Directory List Box:
The Directory List Box control displays an ordered, hierarchical list of user’s disk directories and sub directories.
Directory List Box Properties:
Path……..Contains the current directory path.
Directory List Box Events:
Change……Triggered when the directory selection is changed.
xii- File List Box:
The File List Box control locates and lists files in the directory specified by its path property at run-time.
File List Box Properties:
FileName……..Contains the currently selected file name.
Path……….Contains the current directory path.
File List Box Events:
Dbclick…Triggered when an item in list is double-clicked.
Basic Concepts of Visual Basic
Variables
Variables are used by Visual Basic to hold information needed by an application. A variable has to be declared before using it in an application.
General syntax for declaring a variable is as follow
Dim variblename As datatype
Where variablename is any valid name of variable, and datatype show the type of the data that will be stored in the variblename.
Variable Declaration
There are 3 ways for a variable to be declared.
1. Default.
2. Implicit
3. Explicit
i. Default Declaration
If variables are not implicitly or explicitly declared. They are assigned the variant type of default. The variant data type is a special type used by VB that may contain numeric, string or double/float data.
A variable can be declared using the default declaration as
Dim Var1, Var2
Var1=”Ali”
Var2=300
Here Var1 & Var2 are the variables of type varient. Var1 holds the string data
“Ali” & Var2 holds the numeric data 300.
Note that in the default declaration the As datatype part is optional, the datatype is the variant by default.
ii. Implicit declaration
To implicitly declare a variable, use the corresponding suffix. For example
Name$=”Ali Khan” creates a sting variable
While
Marks%=300 creates a Integer variable
Different variblenames have different suffix for datatypes as shown in the following table.
Data Type Suffix Example
String $ Name$=”Ali”
Integer % Marks%= 300
Long & Distance&=654
String (Floating) ! Age!=20.5
Double # Average# = 345.67435
Currency @ Price@ =$20
Date None Dob=01-03-1976
Object None Mybutton = Picture
Name None Var1=500
iii. Explicit Declaration
The general syntax for explicit declaration is as follow
Dim Variable as Data type
e.g. Dim myname As String
Dim Marks As Integer
Dim Average As Double
Now assigning values to these variables, we have
myname = “Ali”
Marks= “300”
Average= 35.667
Rules for naming variables
The following are the rules for naming variables.
o A variable name must begin with letter.
o A variable name must not exceed 40 characters.
o A variable name must be unique in its scope.
o Reserved words are not allowed.
o No blank spaces are allowed in variable name.
Types of Variables
There are six main types of variables.
1. Numeric
2. String
3. Boolean
4. Date
5. Variant
6. Object.
Now we explain them one by one briefly as follow.
1. Numeric
Numeric variables are used to store numbers in Visual Basic. Numeric data types include:
1. Integer Variable
It can be declared as follow
Dim SNo As Integer.
1. Long Integer
It can be declared as follow
Dim Distance as Long
1. Double Variable
It can be declared as follow
Dim area as double
1. Currency Variable
It can be declared as follow

Dim Price As currency
1. String
String Variables are used to store the string/text data e.g. a studentname or address
It can be declared as follow
Dim myname As String

1. Boolean
The Boolean variable store either true or false value. It can be declared as follow
Dim Check as Boolean
To initialize the check
Check = True or Check = 5
Both hold true values in Check.
1. Date
The date variables are used to store both date and time. It can be declared as follow
Dime DOB as Date
To initialize it, we have
e.g DOB = “01-02-2000”
DOB = “3:30:30 am”
v. Variant
The variant variable is the most flexible data type of Visual Basic variables,
because it can accommodate other date types. A variant variable can be
declared as
Dim Var1 as Variant
Dim Var 2 as Variant
Var1 = “Ali”
Var2 = 300
If variant variable holds string value, Visual Basic treats it as string.
If variant variable holds Inter value VB treats it as Integer.
Note: It is important to note that when a variable is used without declaring it, then the default type of that variable will be variant.
e.g. Dim Var1
Dim Var2
Var1 = “Ali”
Var2 = 300
The Var1 & Var2 are now considered by default as variant (as above)
vi.Object:
An object type variable refers to any one of Visual Basic object controls in tool box. An Object variable can be declared as
Dim Var1 as command Button
To initialize it
Set Var1=Command1
Now the following have the same purpose
Command1.caption = “Save”
Or Var1.caption.”Save”
Scope(Visibility) And Life Time Of Variables
To explicitly declare a variable, you first determine its scope. There are four levels of scope.
1. Procedure Level
2. Procedure Level, Static
3. Form and module Level
4. Global Level
Now we explain each one of them briefly.
1. PROCEDURE LEVEL:
Within a procedure, variables are declared with the Dim statement as
Dim mysno As Integer
Dim myname As String
Dim myage As Double
Procedure level variables declared in this manner do not retain their values once a procedure terminates. So the scope and lifetime of a procedure level variable is limited to the lifetime of a procedure.
II) PROCEDURE LEVEL, STATIC:
To make a procedure level variable retains its value upon exiting the procedure, replace the Dim keyword with Static as follow
Static mysno As Integer
Static myname As String
Static myage As Double
III)FORM AND MODULE LEVEL
Form level variables retain their values and are available to all the procedures within that form(module). Form level variables are declared in the declaration part of the general object in the form’s(module’s) code window. The Dim keyword is used as follow
Dim mysno As Integer
Dim myname As String
Dim myage As Double
IV) GLOBAL LEVEL:
Global variables retain their values and are available to all the procedures within an application. Module level variables are declared in the declaration part of the general object of a module’s code window. The Global keyword is used as follow
Global mysno As Integer
Global myname As String
Global myage As Double
EXAMPLE OF VARIABLE SCOPE:
Module1

Procedure Routine 1 has access to X, Y and A (does not retain values upon termination)
Procedure Routine 2 has access to X, Y and B (retains values)
Procedure Routine 3 has access to X, Z and A (does not retain values upon termination)
Operators
Operators are the words or symbols, which cause a program to perform some action on data.
Types of Operators
Visual Basic supports the following three types of operators.
1. Arithmetic operators
2. Relational operators
3. Logical operators
Now we explain them one by one briefly.
1. Arithmetic operators.
Visual Basic supports the following arithmetic operators.
Operators Purpose

+ To add numbers
_ To subtract numbers
* To multiply numbers
/ To divide numbers (Real)
\ To divide numbers (integer)
^ To find exponentiation of numbers
Mod To find the remainder of numbers when divided Program Example1: Using the + operator
Option Explicit
Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer

Sub form1_activate( )
Number1=10
Number2=4
Result=Number1+ Number2
Print Result
End Sub
OUTPUT: 14
Program Example2: Using the - operator
Option Explicit
Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer
Sub form1_activate( )
Number1=10
Number2=4
Result=Number1- Number2
Print Result
End Sub
OUTPUT: 6
Program Example3: Using the * operator

Option Explicit

Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer

Sub form1_activate( )
Number1=10
Number2=4
Result=Number1* Number2
Print Result

End Sub
OUTPUT:40
Program Example4: Using the / operator (Real Division)
Option Explicit

Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer

Sub form1_activate( )
Number1=10
Number2=4
Result=Number1/ Number2
Print Result

End Sub
OUTPUT: 2.5
Program Example5: using the \ operator (Integer Division)

Option Explicit

Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer

Sub form1_activate( )
Number1=10
Number2=4
Result=Number1\ Number2
Print Result
End Sub
OUTPUT: 2
Program Example6: Using the ^ operator
Option Explicit
Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer

Sub form1_activate( )
Number1=2
Number2=3
Result=Number1^ Number2
Print Result
End Sub
OUTPUT:( 2 ) 3= 8
Program Example7: Using the Mod operator

Option Explicit

Dim Number1 As Integer
Dim Number2 As Integer
Dim Result As Integer

Sub form1_activate( )
Number1=5
Number2=3
Result=Number1 Mod Number2
Print Result
End Sub
OUTPUT: 2 (Remaider, when divieded 5 by 3)
OR
A single Visual Basic Program that uses all the above Arithmetic
Operators.
Program Example: Using the +,-,*,/, \,^, and Mod operators

Option Explicit

Dim Number1 As Integer
Dim Number2 As Integer
Dim Add As Integer
Dim Sub As Integer
Dim Mul As Integer
Dim Div1 As double
Dim Div2 As Integer
Dim Exp As Integer
Dim Rem As Integer

Sub form1_activate( )
Number1=5
Number2=2
Add=Number1+ Number2
Sub= Number1- Number2
Mul= Number1* Number2
Div1= Number1/ Number2
Div2= Number1\ Number2
Exp= Number1^ Number2
Rem= Number1 Mod Number2

Print Add
Print Sub
Print Mul
Print Div1
Print Div2
Print Exp
Print Rem
End Sub
OUTPUT: 7
OUTPUT: 3
OUTPUT: 10
OUTPUT: 2.5
OUTPUT: 2
OUTPUT: 25
OUTPUT: 1
OR
A VB program that contains a Form and three text boxes and one command button Add, when the Add button is clicked the numbers in the two text boxes is added and the result displays in the third text box Result.
We write the following code in the click event of command button Add for the above program.
Sub command1_Click( )
Text3.Text= Val (Text1.Text) +Val (Text2.Text)
End Sub
OR
Write the above program using variables in the option explicit
Option Explicit

Dim Number1 As Integer
Dim Number2 As Integer
Dim Add As Integer
Dim Sub As Integer
Dim Mul As Integer
Dim Div1 As double
Dim Div2 As Integer
Dim Exp As Integer
Dim Rem As Integer

Sub form1_activate( )
Number1=Val ( Text1.Text)
Number2=Val (Text2.Text)
Add=Number1+ Number2
Sub= Number1- Number2
Mul= Number1* Number2
Div1= Number1/ Number2
Div2= Number1\ Number2
Exp= Number1^ Number2
Rem= Number1 Mod Number2

Print Add
Print Sub
Print Mul
Print Div1
Print Div2
Print Exp
Print Rem
End Sub
2- Relational Operators/ Comparison Operators
Visual Basic supports six comparison operators.
Operator Purpose
< Less than
> Greater than
< = Less than or Equal to
> = Greater than or Equal to
= Equal to
< > Not Equal to
3- Logical Operators
There are three logical operators used by Visual Basic.
They are as follow
Operator Purpose

AND The expression with AND operator returns
True value if operators on both sides of AND operator are true otherwise return false.

OR The expression with OR operator returns
True value if at least one operator on both sides of OR operator is true otherwise return false.

NOT The NOT operator is used for negation purpose.
COMMENTS (REMARKS)
Remarks are used to make a program more readable and understandable.
The remarks are ignored by compiler and interpreter.

HOW TO ADD REMARKS:
If you place ‘ (single quote) at the start of a line or Rem keyword at the start of a Visual Basic statement, then the statement will become a remark and will ignored by the compiler.
For Example:
This is a simple program to test remarks.
Rem This is a simple program to test remarks.
The above both the two lines are equivalent and represent remarks.
Concatenation of Strings:
For concatenation of strings Visual Basic use the & symbol or + symbol.
For Example: Suppose we have two strings s1, s2 to be concatenated
and assigned to a third string s3.
S1=”Hello”
S2=”Boys”
S3=S1+S2
Now s3 will have the value ”Hello Boys”
SELECTION STRUCTURE STATEMENTS
Decision making statements of Visual Basic consists of the following:
1. If-Then
2. If-Then-Else
3. Select statement
Now we explain them one by one as follow
1. If –Then:
If-Then statement is used to perform an action if the condition is true, otherwise it skips the action.
General Synatx:
If condition Then statement End if
OR If condition Then
Statement
End if
Program Example1:
Start Visual Basic with standard, Exe file, Place a command button on the form, and write the following code in click event.
Dim I As Integer
Dim J As Integer
I=20
J=10
If (I>J) Then
Print “Large Number is=”,I
End if
OUTPUT: Large Number is=20
Program Example2: Now we modify the above program.
Suppose now the if condition is false, so the it will display nothing.
Dim I As Integer
Dim J As Integer
I=10
J=20
If (I>J) Then
Print “Large Number is=”,I
End if
OUTPUT: (No output as the test condition is false now)
Program Example 3: The above program that will check the condition on the data entered from keyboard by a user.
Dim I As Integer
Dim J As Integer
I=InputBox(“Enter a value for I”)
J= InputBox(“Enter a value for J”)
If (I>J) Then
Print “Large Number is=”,I
End if
OUTPUT: …………
Here the output will depend on the values of I
and j.
1. If-Then-Else:
If-Then-Else statement is used to perform one action if the condition is true, otherwise perform another action in case the condition is false.
General Synatx:

If condition Then
Statement1
Else
Statement 2
End if
EXPLAINATION: Here statement1 is executed if the condition is true, if the condition is false then the statement2 is executed. The following program will explain this statement.
Program Example1: Start Visual Basic with standard Exe file, Place a command button on the form, and write the following code in click event.
(This program finds the maximum value of two values)

Dim I As Integer
Dim J As Integer
I=10
J=20
If (I>J) Then
Print “Larger Number is=”,I
Else
Print “ Larger Number is=”, J
End if
OUTPUT: Larger Number is=20
1. Nested If-Then-Else/ Nested Selection Structure:
When one If-Then-Else statement is the part of another If-Then-Else statement, then it is called Nested If-Then-Else Statement.
Nested If-Then-Else structure is used to handle multiple choices.
General Synatx:

If condition1 Then
Statement1
Else
If condition2 Then
Statement2
………………………
………………………
Else
If condition n Then
Statement n

End if
End if
End if


Program Example: Start Visual Basic with standard Exe file, Place a command button on the form, and write the following code in click event
(This program finds the largest/maximum value of three values)
Dim I As Integer
Dim J As Integer
Dim K As Integer
I=5
J=6
K=7
If I>J AND I>K Then
Print “Largest Number is=”,I
Else
If J>I AND J>K Then
Print “Largest Number is=”,J
Else
If K>J AND K>I Then
Print “Largest Number is=”,K
End if
End if
End if
OUTPUT: Largest Number is=7
SELECT CASE STATEMENT:
Like Nested If-Then-Else structure, the select case statement is also multiple selection structure. But it can handle multiple choices more efficiently.
General Syntax:
Select case Expression
Case Expression1
Statement1
Case Expression2
Statement2
………………………
………………………
Case Expression n
Statement n
Case Else
Statement
End Select
Note: Here the expression may be numeric or string expression.
Program Example1: Start Visual Basic with standard Exe file, Place a command button on the form, and write the following code in click event
Dim choice As Integer
Choice=InputBox(“Enter a number”)
Select case choice
Case 1,2,3
Print “Choice is in the range of 1……3”
Case 4,5,6
Print “Choice is in the range of 4…6”
Case 7,9,10
Print “Choice is in the range of 7…10”

Case Else
Print “ Invalid Choice”
End Select
Program Example2: Start Visual Basic with standard
Exe file, Place a command button
on the form, and write the
following code in click event
Dim month As string
month=InputBox(“Enter a month name of the year”)
Select case month
Case “March”, “April”, “May”
Print “Pleasant Season”
Case “June”, “July”, “August”
Print “Very hot Season”
Case “September”, “October”,“November”
Print “Normal Season”
Case “December”, “January”, “February”
Print “Very Cold Season”

Case Else
Print “ Invalid month of the year”
End Select
LOOPS
Loop: When a single statement or more statements are to be executed again and again, then we
use loop.
Types of Loops: Visual Basic supports three types of loops. They include
1. For -Next Loop
2. While-Wend Loop
3. Do-Loop
Now we explain them one by one as follow.
1. For Next Loop: For-Next Loop is used in a situation where we know in advance how many times a loop body has to be executed. For-loop is used for repetition of the loop body for a fixed number of times.

General Syntax:
The general syntax used for the For-Loop is as follow
For counter variable=Start value to End value [step n]
Loop body
Next counter variable
Where counter variable shows any numeric value. The startvalue represents the initial value of the countervarible. Endvalue represents the final value of the countervariable. The loop body consists of one or more statements that will be executed again and again.
The step value shows the change in increment. By default, the increment of countervariable is 1.
However, you can change it by change in stepvalue.
The keyword Next followed by countervariable is there to compare the countervariable (after stepvalue) with the Endvalue.
PROGRAM EXAMPLE-1:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Numbers from 1 to 10)
Dim I as integer

For I=1 To 10
Print I
Next I
To run this program, Press F5 and click the command button ,you will see the output as follow.
OUTPUT: 1
2
3
4
5
6
7
8
9
10
PROGRAM EXAMPLE-2:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Odd Numbers from 1 to 10)
Dim I as integer
For I=1 To 10 step 2
Print I
Next I
To run this program, Press F5 and click the command button , you will see the output as follow.
OUTPUT: 1
3
5
7
9
PROGRAM EXAMPLE-3:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button. (This program displays Numbers from 1 to 10 in descending order)
Dim I as integer

For I=10 To 1 step -1
Print I
Next I
To run this program, Press F5 and click the command button ,you will see the output as follow.
OUTPUT: 10
9
8
7
6
5
4
3
2
1
2- WHILE-WEND Loop.
The while wend loop is used in a situation where we do not know in advance how many times the loop body has to be executed.
General syntax
While codition
Loop body
Wend
Explaination: The While-wend loop starts with the keyword while followed by a test Condition. If the test condition is true, the loop body will be executed otherwise not. The loop body consists of statements that will be executed again and again. Then there is the keywords wend which finalizes the while wends statement.
PROGRAM EXAMPLE-1:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Numbers from 1 to 10)

Dim I as integer
I=1
While I <= 10
Print I
I=I+1
Wend
To run this program, Press F5 and click the command button , you will see the output as follow.
OUTPUT: 1
2
3
4
5
6
7
8
9
10
PROGRAM EXAMPLE-2:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Odd Numbers from 1 to 10)
Dim I as integer
I=1
While I<=10
Print I
I=I+2
Wend
To run this program, Press F5 and click the command button, you will see the output as follow.
OUTPUT: 1
3
5
7
9
PROGRAM EXAMPLE-3:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Numbers from 1 to 10 in
descending order)
Dim I as integer
I=10
While I >=1
Print I
I=I-1
Wend To run this program, Press F5 and click the command button , you will see the output as follow.
OUTPUT: 10
9
8
7
6
5
4
3
2
1
3-Do-Loop
Do-Loop is another type of loop. It is like while wend loop which is used to execute the loop body for an undermined number of times. It is post-test loop unlike the for-next and do while loops which are pre-test loops. Here the loop body must be executed at least once before the test condition is checked. If the test condition is true, the loop body will be executed for the next time otherwise not.
General Syntax
Do
Loop body
Loop While testcondition
OR

Do [{While |until} condition ]
Loop body
Loop
PROGRAM EXAMPLE-1:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Numbers from 1 to 10)
Dim I as integer
I=1
Do
Print I
I=I+1
Loop While I <= 10

To run this program, Press F5 and you will see the output as follow.

OUTPUT: 1
2
3
4
5
6
7
8
9
10
PROGRAM EXAMPLE-2:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Odd Numbers from 1 to 10)
Dim I as integer
I=1
Do
Print I
I=I+2
Loop While I<=10
To run this program, Press F5 and click the command button ,you will see the output as follow.
OUTPUT: 1
3
5
7
9
PROGRAM EXAMPLE-3:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
(This program displays Numbers from 1 to 10 in descending order)
Dim I as integer

I=10
Do
Print I
I=I-1
Loop While I >=1
To run this program, Press F5 and you will see the output as follow.
OUTPUT: 10
9
8
7
6
5
4
3
2
1
NESTED LOOP:
When one loop statement (For-Next, While-Wend or Do-Loop) is used within the body of another loop statement, then it is called nested loop.
In Visual Basic Nesting process can be done at many levels (For within For, For within Do-Loop or While wend loop).
PROGRAM EXAMPLE-1:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
Dim I as integer
Dim j as integer
Print “ I “, “ j “
For I=1 To 3
For j=1 To 3
Print I, J
Next I, J
To run this program, Press F5 and click the command button , you will see the output as follow.
OUTPUT: I J
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
PROGRAM EXAMPLE-2:
Open Visual Basic with a Standard Exe file with a command button and write the following code in the click event of the button.
Dim I as integer
Dim j as integer
Print “ I “, “ j “
For I=1 To 3
j=1
Do while j<=3
Print I, J
J=j+1
Loop
i=i+1
Next I
To run this program, Press F5 and click the command button , you will see the output as follow.

OUTPUT: I J

1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Difference among For-next, While-wend & Do-loop?
The For-Next Loop and While Wend loop are pre-test loops which means that in these loops first of all the test condition is checked if it is true, the loop body is executed otherwise not.
On the other hand, the do-loop is post-test loop in which the loop body is executed at least once after that the test condition is checked if it is true the loop body is executed for the next time.
Which loop is much better?
In real world most of the applications require the use of For-Next loop where we know in advance how many times a loop body has to be executed.. However, there are some situations where one does not know in advance that how many times a loop body has to executed like a hospital system where one does not know in the start of the day how many patients will be treated in the hospital to day.
OR
An air reservation system, where one does not know how many passengers will travel to day by a particular air reservation system to Dubai or London.
For these situations we either use While-wend loop or Do-loop.
Still it is a matter of taste, which loop you like you can use it.
Arrays
An array is a group of variables, which can store a group of homogeneous data items. An array is used to store multiple values.
Types of Array
There are mainly two types of Arrays.
1. One Dimensional Array.
2. Multi dimensional Array/Two dimensional Array.
Now we explain each one in more detail with examples.
i. One Dimensional Array

A one-Dimensional Array is used to store the data in vector from or list. For one- dimensional Array a single subscript (index) is used.
We use for-next loop to access each element of one-dimensional array.
Declaration of one dimensional array.
An array must be declared before using it in the program. The following syntax is used for declaration of one-dimensional array.
Dim ArrayName (Size) as Data type
e.g Dim a(3) as integer
Where a is the name of array, and 3 is the size of A i.e. the number of elements. Hence the above array will store four elements starting for index 0 to 3
The memory representation of the above array “a” is as follow.

0 1 2 3
In visual Basic, the index number of the first element may be other than zero.
e.g. Dim b(-2 to 2) as Integer

-2 -1 0 1 2
Program Example: Start Visual Basic with New Standard Exe Project.Place a command button on the from & Write the following code for the click event.
Dim a(4) as Integer
Dim I as Integer
For I=0 to 4
A (I)= InputBox(“Enter elements to array”)
Next I
Print “The array elements are”
For I = 0 to 4
Print A(I)
Next I
( ii ) Two Dimensional Array
A two dimensional Array is used to represent the data in a matrix form or tabular from.
For two-dimensional array, two sub scripts are used i.e. one is to generate the rows & the other to generate the columns.
We use nested for-next loop for the two dimensional array.
Declaration of Two-Dimensional Array

The general syntax is as follow
Dim Array name (Size, Size) as datatype
e.g. Dim a(2,2) As Integer
This declaration of two-dimensional Array “a” has three row and three columns
Program Example:- Start visual Basic with Standard Exe Project. Place a command button on the form and write the following code for its click events.
Dim a (2,2) As Integer
Dim r As Integer
Dim C as Integer
For C = 0 to 2
A (r , c) = Inputbox (“Enter Array elements”)
Next c,r
Print “The Array Elements are”
For r = 0 to 2
For c =0 to 2
Print a (r, c)
Next c, r

OUTPUT:
Now Press F5 to run the project and click the button. All values of the dimensional array will be displayed on the form.
Other types of array
Besides the one-dimensional and two-dimensional arrays, there are also other types of arrays which include:
(i) Variant Array
(ii) Dynamic Array
(iii) Control Array
Now we explain each one briefly as follow
i. Variant Array
It the type of Array is not defined at the time of declaration, then the default type will be variant. Such type of Array is called variant Array.
Declaration of variant Array
A variant Array can be declared as
Dim ArrayName (Size)
e.g. Dim b (4)
Here b is a variant Array of five elements
ii. Dynamic Array:
An array whose size can be changed is called dynamic array.
Declaration of Dynamic Array
A dynamic array can be declared as follow
Dim C ( ) as Integer
Before using array C, you must define its scope by using Redim statement as
Redim C (4)
Redim is also used to change the size of array.
e.g. Redim C (10)
When Redim statement is used with dynamic array then the previous stored data is lost (Redim resets all values as empty or Zero).
To stop the loss of data, the keyword preserve is used with Redim Statement as follow
Redim Preserve C(10)
Program Example:- Start visual Basic with Standard Exe Project. Place a command button on the form and write the following code for its click events.
Dim C ( ) as Integer
Redim C (4) as Integer, I as Integer
For I = 0 to 4
C (I) = InputBox ( “Enter the numbers”)
Next I
For I = 0 to 4
Print C (I)
Next I
Control Array
(iii) Control Array
When a visual basic application requires a group of option buttons or check boxes on the form, it is a good idea to use the control array. A control array is a group of controls that all have the same name. All controls in an array must be of the same class. An advantage of using a control array, rather then independent controls, is that the controls share one click event, you can use a case structure to determine which button or box is selected. The number inside the parentheses is called index and is used to refer to the specific control within the array. All subsequent controls given the same name will automatically have an index attached.
COLLECTION:
A collection is an alternate form of the array. The elements of array are accessed by using index number, but the elements of a collection are accessed by using key (unique for each element) as well as index number.
Declaration of Collection
A collection must be declared before using it in the program
General syntax for Collection Declaration is as follow
Dim Collectionname AS New Collection
e.g. Dim CityName AS New Collection
Methods of Collection:
A collection has the following four methods used
1. Add
2. Remove
3. Item
4. Count
Now we explain these methods as follow
1. Add( ):
The Add( ) method is used to add new elements into the collection.
The general syntax of Add ( ) method is as follow
Collectionname.Add value, key, Beforekey, Afterkey
e.g. CityName.Add “Peshawar”, “Key2”, “Key1”
Here the key2 is the key, and key1 is the beforekey.
You can use either the Before key or Afterkey.
ii) Remove ( ):
The Remove( ) method is used to remove or delete an element from the
collection.
The general syntax of Remove ( ) method is as follow
Collectionname.Remove(index)
Collectionname.Remove(key)
e.g. CityName.Remove(2)
CityName.Remove(“key2”)
1. Item( ):
The Item( ) method is used to view/display the elements of a collection.
The general syntax of Remove ( ) method is as follow
Collectionname.Item (index)
Collectionname.Item (key)
e.g. CityName.Item(1)
CityName.Item(“key2”)
1. Count:
The count method is used to return the total number of elements in the collection.The general syntax of Remove ( ) method is as follow
Collectionname.count
e.g. CityName.count
Program Example: Start Visual Basic with standard Exe file, place six command buttons on the form and set the properties for these controls as follow.
Control name Property Value
Form Window state 2-maximized
Command1 Caption Enter CityName in Collection
Command2 Caption Count Total elements in Collection
Command3 Caption Remove an item in Collection
Command4 Caption View an item of Collection
Command5 Caption View all elements of Collection
Command6 Caption View elements of collection using key
‘General Section
Dim CityName As New Collection
Dim C As Integer
Sub Form1_load ( )
C=0
End Sub
Sub command1_click ( )
Dim Cname As String
Cname=InputBox(“Enter new collection”)
CityName.Add Cname,”Key”+Cstr( C )
C=C+1
End Sub
Sub command2_click ( )
Print “Total Elements in Cityname=”CityName.Count
End Sub
Sub command3_click ( )
On Error Resume Next
Dim index as string
Index=InputBox (“Enter index to delete element”)
If index<1 or index>cityname.count then
MsgBox(“Invlaid Index number”)
Else
CityName.Remove(Val(index))
End if
End Sub
Sub command4_click ( )
On Error Resume Next
Dim index as string
Index=InputBox(“Enter index to delete element”)
If index= “ “ Then
Exit sub
End if
If index<1 or index>cityname.count then
MsgBox(“Invlaid Index number”)
Else
CityName.Item(Val(index))
End if
End Sub
Sub command5_click ( )
For each Cname in CityName
Print Cname
Next
End Sub
Sub command6_click ( )
On Error Goto Lab1
Dim key as string
key=InputBox(“Enter key to delete element”)
If key= “ “ Then
Exit sub
End if
If (CityName.count>1) then
Print CityName.Item(Key)
Else
Print “No Element Exists”
End if
Exit sub
Lab1:
MsgBox (“Key invalid”)
End Sub

Information Technology

What is Data? Explain different types of data and what is information?
Data is a plural form of the Latin word Datum. The collection of fact and figure is called Data OR any thing in raw form e.g. Name, Address, Number, Phone Number, Roll No etc.

Types of data
There are three types of data
i. Alphabetic data type:- It consist letter from A-Z capital or
from a-z small letter. e.g Abid, Peshawar,
Pakistan, Khan
ii. Numeric data type;- It consist of digit from 0-9 e.g 123, 567 etc
iii. Alphanumeric data type:- It consist alphabetic letter as well as
numeric digit. Street no A/10 etc

Q. What is Information?
A. To organize the Data in meaningful upon which people can take necessary decision is called Information. e.g. 2,1,5,4 when sorted it become 1,2,4,5 which is information. Information is the meaningful, processed data, which is relevant and accurate and there by can be used in decision-making. Examples are voucher, bills, fee registration cards or library cards.
Q. Compare Data and Information.
A. Data vs. Information.
We most frequently use the word data and information interchangeably, but still there is big difference between these two terms. The word Data is the plural of Datum and has been taken from Latin language. But it is always used both in plural and singular meanings.
Data is defined as the collection of facts and figures like numbers, characters, letters etc. that is always in a raw form and cannot be used directly for any decision-making. However, it can be used for any decision-making. and action taking if processed usefully. It is fact that one-person data may be another person information and vice versa. e.g. 123, ABC, Akbar, Marks etc are example of data. Similarly 12 & 34 is data and if it is processed (i.e. added), it becomes 46. So data can be processed either manually by human or by an electronic machine like computers to get useful information. Data may be numeric, alphabetic or alphanumeric. For example 300 is numeric data Asad Ali is alphabetic and House # 12/A is an example of alphanumeric.
By information we mean the organization of data in meaningful form that is data processed usefully and meaning fully and is ready for decision making and taking actions becomes information. So we say that if data is processed by certain data processing procedures it is transformed into useful data.



e.g. 2,1,5,9,7 Sorted 1,2,5,7,9
Remember that computer is one of the information systems that convert raw data into useful information.
What is Information Technology? Discuss element of IT/ ELEMENTS OF DATA PROCESSING SYSTEM
The merging of computer and communication is called Information Technology. IT is a technology that merges computing with high-speed communication links carrying data, sound, image, graph, and video. Computer and communication are the parents of the information age.
It manages a network of computer. Creating WEB Pages, producing video, selling, buying, and perform any type of business activity on the Internet.
For example telephone, radio equipment and switches used for voice communication. Managing video conferencing etc.
Through Internet, you can communicate with any computer user having an internet connection any where in the world. You can exchange message with him, you can talk to him through computer or phone, you can send any file to him, you can receive any file from him and you can have on-line conversation with him through typing from keyboard. A computer and communication system is made up six elements.
1) People 2) Procedure 3) Data/Information 4) Hardware 5) Software
6) Communication
1-Peoples
It means the users or people who runs and execute the entire data processing task and computer installations or the people who works in the data processing environment. The personnel include System Analysts, Programmers, Data entry operators, and Data processing officers.
2-Procedure
Procedures are rules, policies, and methods for operating computers. The operation of a data processing system requires procedures for use in obtaining and preparing data in order to operate the computer and for distributing the output from the computer. This procedure includes control steps such as actions to be taken to show errors in the data and malfunctioning of the equipment etc.
3-Data
Fact and figure is called data. Data is raw material of IS. Data can take many forms, including Text data, Audio data, video data, voice data graphics and image data.
4-Hardware
Physical parts of computer system. For example input devices, output devices and CPU such as keyboard, Mouse, Memory, mother board, CD-ROM etc.
5-Software
The Software consists of programs whose purpose is to communicate with computer. The Software includes operating system i.e. MS-DOS,PC-DOS,UNIX,,XENIX, and Linux etc. General purpose programs i.e. database packages like FoxPro, Dbase, Java etc.
6-Communication
Data Communication/Telecommunication technologies and network like the internet which is necessary for all types of organization and their computer-based data processing. Telecommunication network consist of computers, communications processor and other device interconnected by communication media and control by communication soft ware.
Data processing system:-
The system that process data and produce information is called Data processing system or Information processing system. The diagrammatic representation of DPS is given below.

* MODEL OF DATA PROCESSING SYSTEM *
EXPLAIN MANUAL AND ELECTRONIC DATA PROCESSING SYSTEM. WHAT IS THE DIFFERENCE BETWEEN THESE TWO?
Conventional Data Processing(CDP)/Manual Data Processing:-
The Conventional Data Processing/Traditional Data Processing system is the manual method of transforming data into information. The human beings themselves collect data, classify and arrange the data, perform manual calculation and hence produce the required output result. It is very simple and inexpensive. Upto the 20th century almost all data processing was done manually. Clerical persons used paper, pen, and pencil to maintain records in offices. Such data processing caused frequently clerical mistakes and hence due to these miss-recorded transactions, the Company record was to be misrepresented. Information was often received too late to serve the organization purposes.

Electronic Data Processing (Computer Based data Processing System)
An Information System that uses Computer and their hardware and software is called Electronic data processing, Computer-Based Data processing or Computer Based Information System. Electronic Data Processing or Computer Based Information System uses Computer hardware and software, the internet and other telecommunication system, network, Computer based data resource management technique and many other information technologies to transform data resources into information products for consumers and business professionals.

Electronic computers complete all data manipulation and file updating electronically rather than mechanically. This increased data processing productivity and reduced its cost. The speed, accuracy and reliability of computers are more than Traditional data processing.
History of Computers: -
The history of Computer is very old, i.e. it goes back to some 500 years BC. The first computing machine was used by the Chinese before 15th century. The name of this machine was Abacus.
However in 1812 an English mathematician from Cambridge University, Mr. Charles Babbage designed a machine called DIFFERENCE ENGINE. This machine was capable of calculating powers of numbers. Babbage also gave the idea of an ANALYTICAL ENGINE, which was supported to be general-purpose machine having the ability to calculate various arithmetic and/or algebraic formulas, store data and print results. He died soon and never converted his dreams into reality.
The analytical engine was not a successful machine but it gave birth to the research in the field of computers.
In 1946, John Mauchly and J.P. Eckert developed an Electronic, Numerical Integrator and Computer (ENIAC) at the Moore school of Engineering and Technology, Pennsylvania USA. This was the first truly successful computer after Mark-I and Mark-II developed at Manchester University. There were three main drawbacks in the ENIAC as follows:
1. It used serial lines for processing.
2. No storage facility was available.
3. It used decimal numbers instead of binary number system.
These problems were successfully overcome with the development of John Von Neumann’s Electronic Discrete Variable Automatic Computer (EDVAC) developed in 1950. It was the first computer capable of doing non-scientific work. Besides, most of today’s computers are based on the working of EDVAC. The development of these machines materialized the existence of computers and they became a commercial entity used in many government organizations. As EDVAC was the first machine that was used by the people for solving their problems, but still it was not a useful machine because it could not solve all the problems of that time. Therefore, efforts were made to develop such a machine, which can solve all our problems. In this connection, the scientists make developments from time to time and improve the previous machine into a latest one. Due to these improvements, we have now Computers, which can solve all types of problems.
different Types of Computer
There are three type of Computer
a) Digital Computers. b) Analog Computers. c) Hybrid Computers.
a) Digital Computers: -
In these Computers, information is represented by variables which having discrete values, i.e. it operates on the inputs that are ON-OFF switching. Digital computers process data, which is in the form of digits. In these Computers all operations take place at a very high speed and produce very accurate and precise results, e.g. Digital computer, Calculators, Digital Watches, etc.
b) Analog Computers: -
These machines process information, which is of, continues nature and which is not discrete or separate. An Analog computer is used for measurement. The speed of analog is fast but not so accurate. Analog computer measure Temperature, Pressure, Current Voltage and Depth etc. These quantities continue in nature and have millions of varieties. OR in other words we can say that in these Computers, information is represented in continues form, e.g.. Automobile Speed Meter, Current, Analog watch, etc.
Differentiate Between Analog and Digital Computers: -
Analog Computers measure while Digital Computers count. Analog Computers are fast but not so accurate, while Digital Computers are fast as well as more accurate.
c) Hybrid Computers: -
Hybrid Computers combine the properties of both Digital Computers and Analog Computers for solving the problems e.g. Hybrid Computers have the speed of Analog Computers and accuracy of Digital Computers. These Computers are used in some specialized applications. e.g. Flight Radar System, National Defense, Hybrid Watches, digital petrol pumps etc.
Explain or discuss Classification of Computer (w.r.t size)
a) Micro Computers. b) Mini Computers. c) Mainframe Computers. d) Super Computers.
a) Mainframe Computers: -
These are the most expensive, largest and fastest Computers, used in large Organizations. Mainframes have the facilities to communicate with large amount of data and support several input and output devices. The cost of typical mainframe is in million rupees and can serve as much as 150 users.
These Computers have Memory of several hundred Mbs, and operate at a speed of measure in nanoseconds. e.g. IBM/360, IBM/3090, etc.
b) Mini Computers: -
These Computers are larger than PCs, both in size and other facilities such as speed, storage capacity, etc. These Computers have the capabilities to serve many Users at one time. They are costly as compared to PCs. Their speeds are rated between 1 and 50 MIPS. E.g. Vax/11730, IBM/8370, etc.
c) Micro Computers
These are also called Personal Computers (PC). These are the most popular digital Computers used in all fields of life. These are small in memory and have less processing capability. These are also called Chip Computers, because its entire circuitry is fabricated on a single chip. The microcomputer of today is equivalent to the main frame of tomorrow. e.g IBM-PC, XT, AT, Compatibles, 286, 386,486, 586, P-I, P-II, P-III, P-IV etc.
d) Super Computers: -
Super Computers are also called “Number Crunchers”, because they are specialized Computers for dealing with numbers, i.e. they are capable of performing over 10 Mega flops (i.e millions floating point operations per second). These Computers are very much expansive. Two families of commercially available Super Computers are the GRAY-1 and Cyber205 built by Illiac-iv. These are specially used in Atomic reactor, defense system of NASA. (USA)
Explain or discuss Classification of Computer w.r.t purpose
We can divide the Computers into the following two types.
a) General Purpose Computers. b) Special purpose Computers.
General Purpose Computers: -
These Computers are used for solving a wide variety of problems in many areas such as Business, Education, Science, etc. General-purpose computers can store large amount of data and that is why most business enterprises use them. These Computers are used for multipurpose. For example, P.C, etc. .
Special purpose Computers: -
These computers support highly specialized data processing activity. These Computers are used for solving problems of some special types. i.e these Computers are used to perform a single and special task e.g. Computers used in the Atomic Energy Commission, Computer used for eye sight etc.
Different generation of computer
Generations of Computers:
Although, the development of Computers is a continuous process, however, it can be categorized into the following generations based on the technology used for the Computer systems.
1.First Generation (1945-1950):-
All the Computers developed in this generation were based on Vacuum-Tubes technology. For example, ENIAC (Electronic Numerical Integrator And Computer), Mark-I, Mark-II etc. The Computers of this generation were very slow, large, and expansive.
2. Second Generation (1950-1959):-
The Computers of this generation were based on Transistor technology(Vacuum tube replace by transistor) and they opened the gateway to the commercial development for sale of computers. The transistors were small in size, fast in operation and less expansive than vacuum tubes. Hence the Computers of this generation were small and less costly. Also the speed of these Computers was high. e.g. , EDVAC, IBM-1401.
3.Third Generation(1960-1969)
The Computers of this generation were based on integrated circuits (ICs) technology (transistor replace by ICs). In early 1960 the electronic technology of solid-state was introduced. The development of integrated circuits (ICs) is called solid-state technology or Small Scale Integration (SSI). The integrated circuits (ICs) are the collection of many electronic devices like transistors on a single chip of silicon. This technology enabled the computers to enter into electronic revolution. Also the Computers of this generation were high in speed, accuracy and less in price. e.g. IBM-360 etc.
4. Fourth Generation(1970-1980)
The Computers of this generation were based on Large Scale Integration (LSI ) (ICs replace by LSI ). In 1970 the technology was enhanced sufficiently to integrate all main functions of a computer using LSI on a single chip called Microprocessor. In this generation Microprocessor was introduced, due to which microcomputers were made. For example, IBM-PC etc.
1. Fifth Generation(AI)(1980-1990)
The rapid progress in computer technology is still continued and active research is going on in different fields of computer technology but there is no well-defined categorization after fourth generation. The reason may be that now the developments are taking place in a variety of fields of computer hardware and software as compared to the previous developments, which mostly took place in the fields of electronics. As a result of that further grouping of computer developments is difficult. However in the field of software a new era has started called AI (artificial intelligence), which is the main field of study including ROBOTICS, COMPUTER VISION, COMPUTER LEARNING etc. Hence the Computers of this generation were based on the principles of AI and also in this generation, Software development was give more importance than Hardware, as a result of which Artificial Intelligence was introduced. e.g. Robotics, Computer Vision etc.
6.Sixth Generation(ANN’S)(Since 1990):-
The Computers of this generation are based on the principles of Artificial Neural Network System (ANNS). As a result, now the Computers can think and decide for solving different problems. e.g. Character recognition etc.
Computer and Its components
Computer is an electronic device, which can accept the data, process the data, and gives the result/information of the process data according to instruction.
A computer is an interrelated combination of components that performs the basic function of input, processing, output, storage, and controlling, thus providing end users with a powerful information-processing tool
Different components of Computer (Input, CPU, Output)?
Main Components of Computer:
There are three basic elements of a computer.
1. Input Unit 2-Processing Unit (CPU) 3-Output Unit
2. Input Unit
The devices through which we enter the data and instructions (Programs) into the computer are called input devices. (e.g. keyboard, Mouse, Scanner etc)
1. Central Processing Unit (CPU)
Central Processing Unit (CPU) is the administrator section of computer. CPU is connected to all input, output and storage devices and controls all the functions of these devices. CPU receives the data from input device; perform processing on data; and then sends the result of the process data to output devices.
The CPU is the collection of three units.
i) Control Unit (CU)
Control Unit is the nerve center of the computer. The control unit direct and coordinate the entire Computer System in carrying out Program instruction. It accept data from input device and send it to the memory. From the memory the data are then transferred to ALU and send the result to the output unit.
ii) Arithmetic and Logic Unit (ALU)
This is the calculation section of Computer. All arithmetic operation like addition subtraction, multiplication and division as well as some logical operation are performed in this section.
iii) Storage Unit (Memory)
The memory of CPU is the place where the computer program and data are stored during processing. The storage unit is often called either main storage or internal storage or primary storage. There are usually two types primary storage.
a)RAM:-
It stands for Random-Access-Memory or read/write Memory because information can either be read from or written to the RAM. This is the memory whose information can be erased or changed. It is temporary memory. Any thing stored in RAM is lost when Computer is switched off.
b)ROM
It stand for Read-Only-Memory. Information can be read from ROM but we can not write information to it. This is the memory whose information can be not changed. The information stored in it can not be lost if we turn off the Computer. ROM is used to store permanent program. This information is available on small pieces of the memory called chips.
3. Output Unit
The devices through which the process information comes to outside world is called output devices. An output device can be used to store, display or print the information. (e.g. monitor, printer, floppy Disks, hard Disks etc

Input & output devices
The device through which we enter the data into the computer is called input device. There are many devices for input. These devices of a digital Computer are responsible for accepting programs and data from the outside world, feeding it to the Computer, and storing it into the Computer memory. These devices work under the control of Microprocessor. Some of the famous Input devices are as below Keyboards, mouse, scanners, microphone, video camera, touch screen, and optical scanning.
1-KEYBOARD:-
It is a very common input device that helps in keying-in the required information into the Computer. Keyboard can be used effectively to Communicate with the Computers but it is very slow input device. The keyboard is just like a typical typewriter in shape but enhanced than that. It consists of normal Alphabetic, numeric, functions, and other special characters or control keys, which are not available in a typewriter.
2-MOUSE:-
A Mouse is a quick input device and is very small in size. Its shape likes to a mouse and is moving very fast on flate surface that is why it is called Mouse. It usually rolls on a small bearing and has two or three buttons on its head. When the User rolls the mouse on a flat surface called mouse pad, the movement guides a pointer on the screen called cursor. As it moves the system recognize that some information are coming in.
3. SCANNER
Scanner is Optical character recognition equipment that can read special-purpose characters and codes. Scanner provides a method of direct input of data from sources documents into a computer system. There are many type of optical reader, but they all use photoelectric devices to scan the characters being read. Reflected light pattern of the data are converted into electronic impulses, which are then accepted as input into the computer system. OCR-based optical scanning systems are used extensively in the credit card billing operations of credit card companies, bank, and oil companies.
4-The Microphone
It is an input device that is used for the input of voice in place of using the keyboard and mouse. Special software is used to convert voice into text. This requires fast processing and a lot of memory and will become more common as the technology improves. The microphone converts audio signals into digital form.
5-Video Cameras
Video cameras is an input device, that is able to capture images of any type data. Most scanners incorporate a special sort of camera made up of Charged-Coupled Devices (CCDs). Each CCD receives light from the image and the light generates an electrical charge. This means that light areas or dots of the image are represented by charged cells and dark areas by uncharged cells.
6-Digital video Camera:
When you take a picture with a digital camera, a digitized image goes straight to a floppy disk, CD-R, or other memory. Once on disk or in memory, it can be loaded to a computer and manipulated. Light received through the lens is converted to digital signals by sensors, rather than stored by chemical change on a film as in a normal camera. The resulting “photograph” can then be stored on a computer and used just like any clipart files. So digital camera is a camera that stores images digitally, rather than recording them on film. Once a picture has been taken, it can be downloading to a computer system, and then manipulated with a graphic program and printed.
Disadvantage :- Digital photos are limited by the amount of memory in the camera.
Advantage:- The big advantage of digital cameras is that making photos is both inexpensive and fast because there is no film processing. Most digital camera used CCDs to capture image, though some of the newer less expensive camera use CMOS chips instead.
OUTPUT DEVICES
The device through which the process information comes to outside world is called output devices. An output device can be used to store, display or print the information. (e.g. monitor, printer, floppy Disks, hard Disks, CD-ROM, SPEAKER etc)
1-Monitors
A TV-like device that is used by the Computer for displaying the information to the outside world is known as CRT or VDU or more simply a Computer Screen. The PCs generates text and/or graphs on the Screen using two components called the Monitor and the Video Adopter Card. The Monitor mainly consists of glass cone, which uses special electron guns to hit the Screen from back towards the cone and thus producing text or graphs with various colors. The Monitor is used how to control the coming rays and the Video Adopter card is used what to display i.e. either text or pictures. Monitors/Screens can be selected on the basis of user requirements. However , Monitor makers provides us with many types in terms of Black & White/Color, Interlaced / Non-Interlaced , High-resolution/Low-resolution, Dot-pitch, Digital or Analog Monitors. Their costs , sizes and video modes also vary with their internal differences.
TYPES OF MONITORS:- There are different types of Monitors that are matched to the different video display mode available for PCs (text, Lo/HI-resolution, graphics etc) . Some of the low-cost Monitors are built specially to work with one or two of the popular video modes while others are more expansive and can support almost anything thrown by the Computer. Since Monitors are available in terms of many aspects. i.e. Interlaced or Non-interlaced, Low resolution or High –resolution etc, therefore especially it is difficult to count and show its types. However keeping all these features in view some of the popular types of Monitors are discuss below.
MONOCHROME MONITOR:-Normally Monochrome is any Monitor that can not display colors. They can be black and white type but they are often available in green colors because green color is easier to eyes. A Monochrome Monitor usually cannot display graphics. But later on some techniques were developed to have the graphics capability in the Monitors, e.g. Hercules Graphics Card (HGC).
Analog Color Monitor:- The Color Monitors with an analog interface are called as ANALOG Color Monitors. The first Color Monitors were introduced with the development of IBM’s Color graphics Adopter (CGA) card. These screen were generally called RGB(Read, Green, and Blue) pixels as they supported these three Colors. The CGA board could create a 320 x 200-pixel display in four Colors. But they were low-resolutions Monitors because the text or graphics were not so much attractive as can be. But they were still popular because they use a digital interface between the CGA display adopter and the Monitor. That is why these are called as Digital Color Monitors.
Digital Color Monitor:- The Color Monitors with digital interface are called as Digital Color Monitors. Its newest versions are VGA (Video graphic Array), EGA(Enhanced Graphic Array) and SVGA (supper VGA) which have more high-resolution and are more enhanced.
Besides all these types there are specialized Monitors for some specific purpose such as Paper-white Displays and Portrait Displays, which are, used for text and word processing purposes only.
2-PRINTERS
Another output device that converts the coded information from the processor into a readable form on paper called HARDCOPY. There are many types of Printers varying in speed and quality. These may be serial Printers, Parallel Printers or Page Printers. Also these may be Solid-font or Dot-matrix Printers. Anyhow the quality of printers depends upon the User requirements. Following are the main types available in market.
1. DOT-MATRIX PRINTER
A dot-matrix printer makes a good low cost general-purpose printout for most of the user needs. They are neither very slow nor very expansive. Although the quality of print is not so best but is sufficient for many purposes. Like other printers, dot matrix also prints one Character at a time from left to right. When it finishes the line, it rolls the paper up one row and starts printing the next row. It just makes lines of dots to make a character.
1. IMPACT PRINTERS
The second most popular printer is the impact printer. They are also called DAISY-WHEEL PRINTER. They produce rather excellent letter-quality printout as compared the dot-matrix printer. They work just like the typewriter and uses a hammer and a wheel to print something on paper. But they are very much noisy and hence are not so popular. Printers other than Impact are called Non-Impact Printers.
c. LASER PRINTERS
The most expansive and quality –bearer printers are the Laser printers, which produce high-quality printout and so are used for desktop publishing and graphics. A Laser printer works on the principles of a Photocopier. Simply a metal drum called TONER is filled with special ink which just sprinkle ink onto the paper and thus prints the character. They are very fast and uses multiple fonts for text and graphics.
Besides them now there are color printers available in both dot matrix as well as Laser printers and all others as well.
3-PLOTTERS
Plotters are an alternative to printers for drafting applications because they are specialized and unbeatable for certain kinds of works. A Plotter is basically a mechanical hand holding a pen. They are mostly used for Engineering and Maps drawing purposes. They curves lines, graphs and making Maps just as the humans do but are more clear , understandable and attractive than hand-made things.
4-SPEAKER
Speaker is an output device. It produce softcopy output. This gives us output in the form of sound. We use speaker to hear any type of sound.
STORAGE DEVICES
Main or Primary Memory or Internal Memory
The Main memory (Primary Memory) of CPU is the place where the computer program and data are stored during processing. This storage unit is often called either main storage or internal storage or primary storage.
There is usually two types primary storage.
a) RAM:-
It stands for Random-Access-Memory or read/write Memory because information can either be read from or written to the RAM. This is the memory whose information can be erased or changed. It is temporary memory. Any thing stored in RAM is lost when computer is switched off.
b) ROM:-
It stands for Read-Only-Memory. Information can be read from ROM but we can’t write information to it. This is the memory whose information cannot be changed. The information stored in it can’t be lost if we turn off the Computer. ROM is used to store permanent program. This information is available on small pieces of the memory called chips.
Secondary or Auxiliary or External Memory (Storage)
The devices of a computer that store information such as software and data permanently are called secondary storage. Disk is a secondary storage device where we can store a large amount of data and from where it can be retrieved. It has different types e.g. Hard Disk, Floppy Disk, CD-ROM, Magnetic Tape, Magnetic Drum
Q. Explain different types of secondary storage devices?
Ans. Types of Secondary Storage Devices:
Following are secondary storage devices.
1-Magnetic Disk
The magnetic Disk is made up of one or more rotating platters, on which data is stored magnetically. It is made up of plastic, coated on both sides with a special magnetic object that is iron oxide. There are two main types of magnetic Disks. i.e. Floppy Disk and Hard Disk.
a-Hard Disk
It made up of one or more rotating Platter, which is encoded with magnetically object that is iron oxide. It is circular metallic plate comparatively thick in size and permanently sealed in completely enclosed. Data are recorded on magnetic disk as a series of magnetic patterns. This is also called fixed disk and use for more storage. It can store a huge amount of data and faster access speeds than floppy diskettes.
b-Floppy Disk
It is a removable plastic Disk. It is not fixed in the computer. It is encoded with magnetically object that is iron oxide. It has less storage capacity than a hard disk. To use a floppy Disk you must have a floppy Disk drive. Letter used for floppy Disk drives are A & B.

Size Density Capacity
5.25 “ Double 360 Kilobytes
5.25 “ High 1.22 Megabytes
3.5 “ Double 720 Kilobytes
3.5 “ High 1.44Megabytes
2-CD-ROM
CD-ROM stands for Compact Disk Read Only Memory. CD-ROM technology uses 12-centmeter (4.7 inch) compact disk similar to those used in stereo music systems. It is the latest invention. It is so called CD-ROM because information can be read only from it but not written to it. A CD-ROM can store up to 840 megabytes of data. Letter CD is usually used for CD-ROM drive. To use a CD-ROM disk you must have a CD-ROM drive.
3-Magnetic Tape
Magnetic tape is a flexible plastic tape, coated on one side with magnetic iron oxide material. It is used when large amount of data are to be processed sequentially. An advantage of magnetic tape is that it is very cheap and economical storage medium but very slow in processing.
4-Magnetic Drum
It is a rotatable cylinder whose surface is coated with a magnetically sensitive iron oxide compound. The surface is divided into a number of tracks, each track having one or more fixed reading and recording heads. Magnetic Drums are commonly used when very fast access and transfer speeds are required. They have one disadvantage that is they cannot be removed from a unit.
Introduction to Software
Software is defined as a written computer program or series of instruction. Software is the name given to the actual program that allows the hardware to perform a useful work. With out software hardware is quite useless. Software is the communication between user and computer. Software is needed to accomplish the input, processing, output, and storage and control activity of Information System. There are two type of Soft ware 1) System software 2) Application Soft ware.
1-System Software
System Software is a group of program that controls all the operation of computer. System Software consists of programs that manage and support a computer system. System software is the type of software relating to the system, which make better & effective utilization of the entire Computing system. It controls all the operations of computer system. It is mostly provided by the manufacturers. The person preparing system software is called System Programmer & the process is called System Programming. For example the development of COMPILER, O.S, and High-level languages come under this category.
For example, Operating System and network management programs. System Software serve as interface between systems network and hardware and the application programs of end users.
There are three types of System Software
1:-System Management programs 2: System Support program 3:-System development programs.
a:- System Management programs:
It manages the hardware, software, networks and data resources of a computer system. Examples of system management programs are operating system, network management program, database management system.
b:-System Support Program:
It supports the operations, management, and users of computer system by providing a variety of support services. For example system utilities, performances monitor.
c:- System Development program:
Program that helps users develop information processing programs and procedures and prepare users programs for computer processing. For example language translator, programming editor, and debuggers, code generator and CASE tools.
2-Application Software:-
Application software is that type of computer software, which is, writes for a specific task, which specifies the user requirement. Or it is program, which is a certain problem oriented and not so general. The person preparing application software is called application programmer.
For example software developed for the PAYROLL of employees and accounts in an organization come under this category.
There are two type application Software
a- General Purpose Software
b- Application Specific Software
a) General-Purpose:-
General Purpose Program is application program that perform common job for end user. For example, word processing programs, spreadsheet programs, database management programs (Ms-Access, Oracle), and graphics programs..
2) Specific Application Program:-
Specific application program is used to support specific application. This type of software perform specific task. Some major categories are
i-Business application program are program that are develop for important business functions or industry requirements. For example program for accounting, marketing, finance, and employee benefits program.
ii-Scientific application programs are program that are develop for scientific and engineering purpose. For example program for scientific analysis, engineering design, and monitor of experiment.
iii-Other application program are other than business and scientific. For example computer application in education, entertainment, music, art, law, and medicine etc. Example are video-game program, entertainment program, etc.
PROGRAM TOOLS
Following are the programming tools for the programmer with the help of which the programmer can write a perfect program. These are
1- Algorithm 2- Flow Chart
ALGORITHM
An algorithm is a finite set of instructions, which accomplishes a particular task.
An algorithm is a finite step-by-step list of well-defined instructions for solving a particular problem.
ALGORITHM NOTATION
The algorithm is a base of not only effective data structure but it is also the base of good programming. Therefore, it is necessary that each algorithm should be written clearly. A complete algorithmic notation is given below.
1) Name of algorithm:
Every algorithm is given a name, written in capital letters.
1. Introductory Comments.
The algorithm name is followed by a brief description of the tasks the algorithm performs. This description gives the name and types of variables used in the algorithm.
1. Steps:
The algorithm is made of a sequence of numbered steps. Each beginning with a phrase enclosed in square brackets which gives an abbreviated description of that step. Following this phrase is an ordered sequence of statements which describe the actions to be executed or tasks to be performed.
1. Comments:
An algorithm step may terminate with a comment enclosed in round parenthesis, which is used to help the reader better understand that step. Comments specify no action and are enclosed only for clarity.
Example of an algorithm:
Algorithm GRADES(M1,M2, M3,M4,Average)
This algorithm reads four marks denoted by M1, M2, M3, M4 and compute the average grade. All variables are assumed to be real]

(l) [Input individual marks]
Read (Ml,M2,M3,M4)
2) [Compute average grade]
Average= (M 1+M2+M3+M4)/4
3) [ Output Result]
Write ("Final grade is" , average)
(4) [Finish]
Exit


Flow Chart
Charting:
Charting is a graphical or pictorial means of presenting data. Charting takes the flow of work and makes a picture of it. Charts can be used to illustrate statistical data, locations of desks or equipment, relationships between people and jobs, sequences of events, work flow, organizational structure and planning or implementation schedules.
The primary use of charting is for communication and documentation of the system. Charting is also used during feasibility studies, problems definition understanding the existing system, defining new systems requirements, design, cost comparisons, final report, and implementation.
For example Flow chart, Bubble chart or data flow diagram, Grind chart etc.
Flow charts
A flowchart is a pictorial/graphical presentation of flow of data to solving the problem. A flowchart is a diagrammatic representation of the logic or sequence of steps that solve a problem. Flowchart is tools for the programmer to analyze, organize, and solve a problem. A number of pictorial figures are used to help draw the flow charts. Finally the instructions are coded in one of the programming languages, called a program. The person who writes program are called programmer.
When developing a flow chart the systems analyst (or programmer) should observe the following guidelines:
Flow charts are drawn from the top of a page to the bottom and from left to right.
The activity being flow-charted should be carefully defined and this definition made clear to the reader. Where the activity starts and where it end, should be determined.
Each step of the activity should be describes one-verb descriptions, e.g. prepare statement or file customer statement.
Each step of the activity should keep in its proper sequence.
The scope or range of the activity being flowcharted should be carefully observed. Any branches that leave the activity being charted should not be drawn on that flow chart. A connection symbol should be used and that branched put on separate pages or omitted entirely if it does not pertain to the system.
Use the standard flow-charting symbols.
Type of flowcharts:

A system flow chart show the overall work flow of the system. It is a pictorial description of the sequence of the combined procedures that makes up the system. A system flowchart shows the sequence of physical devices used to solve that problem.


Program Flowchart
This is the pictorial representation of the logic of the program, showing different steps to solve a problem.
Program flowchart symbols

The XYZ Company has found t
hat it can purchase a raw material at a cost of $40.00 per order. The company has a 10% carrying charge on average inventory. They expect to use $20,000 of the raw material within the next year. To determine the economic order quantity (EOQ) by using the formula: EOQ = 2AP/RC Where: A=Annual Cost P=Annual Usage R=Price per order C= Carriage Charges
Draw its system Flowchart and program flowchart.
Two very simple program flowcharts are shown in below figure. The one on the left is program flow chart prepared by a systems analyst to show the detail of procedural operation. The one on ht eight is a programmer to show details of computer program operation. It is noted that the systems analyst into a program flowchart as in below left side figures further expands the systems flowchart in above example. Programmer when expands the detail into program flowchart shown in the below right size figure.
Systems flowchart Program flowchart