Record MM It

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 102

KARPAGAM ACADEMY OF HIGHER EDUCATION

(Deemed to be university)

(Established Under section 3 of UGC Act

1956)

COIMBATORE-
641021

UNIT II
The VB .Net Language: The VB .Net Language – Variables- declaring
variables, Data type of variables, forcing variables declarations, scope &
lifetime of a variable, constants, arrays, types of arrays, control array,
Structure programming – Modularity – Information hiding – abstraction
– events – subroutines and functions – message box – input box. Control

Introduction to Visual Basic.NET

Visual Basic .NET is an object-oriented computer programming


language that can be viewed as an evolution of the classic Visual Basic
(VB), which is implemented on the
.NET Framework. VB.Net provides the easiest, most productive language
and tool for rapidly building Windows and Web applications. Visual
Basic .NET comes with enhanced visual designers, increased application
performance, and a powerful integrated development environment
(IDE). It also supports creation of applications for wireless, Internet-
enabled hand-held devices. The following are the difference between
traditional Visual basic 6.0 and Visual basic.Net

S.No Visual Basic 6.0 Visual Basic.Net

1 It is a object based language It is a object oriented


programming language
2 It does not support Inheritance As it is object oriented, it supports all oops
concepts such as inheritance

3 Visual basic is a VB.Net supports disconnected architecture


connected architecture

4 There is no support for Threading It supports Multithreading

5 VB 6.0 does not provide support It supports Exception handling, which is an


for Exception handling added advantage
Table Difference between visual basic
6.0 and VB.Net

These are the major difference between these two languages. The next

section details about the powerful features of Visual basic.Net.


Features of Visual Basic.Net
The integrated development environment (IDE) of Visual Studio has
definitely changed with the arrival of .NET technology. Due to these
changes, Visual basic too has some changes such as Property pages are
replaced by property grid displays, Objects replaces variant data type
and the addition of Designers. These changes make the application very
simple for the developers. This sections provides some of the significant
features of the latest version of Visual basic.

1.Simplified Deployment

With Visual Basic .NET we can build applications more rapidly and
deploy and maintain them with efficiency. Visual Basic .NET 2003
and .NET Framework 1.1 makes "DLL Hell" a thing of the past. Side-by-
side versioning enables multiple versions of the same component to live
safely on the same machine so that applications can use a specific
version of a component. XCOPY-deployment and Web auto-download of
Windows- based applications combine the simplicity of Web page
deployment and maintenance with the power of rich, responsive
Windows-based applications.

2.Powerful Windows-based Applications

Visual Basic .NET comes with features such as a powerful new forms
designer, an in- place menu editor, and automatic control anchoring and
docking. Visual Basic .NET delivers new productivity features for
building more robust applications easily and quickly. With an improved
integrated development environment (IDE) and a significantly reduced
startup time, Visual Basic .NET offers fast, automatic formatting of code
as you type, improved IntelliSense, an enhanced object browser and
XML designer, and much more.

3.Building Web-based Applications


With Visual Basic .NET we can create Web applications using the shared
Web Forms Designer and the familiar "drag and drop" feature. You can
double-click and write code to respond to events. Visual Basic .NET
2003 comes with an enhanced HTML Editor for working with complex
Web pages. We can also use IntelliSense technology and tag completion,
or choose the WYSIWYG editor for visual authoring of interactive Web
applications.

4.Simplified Data Access


You can tackle any data access scenario easily with ADO.NET and ADO
data access. The flexibility of ADO.NET enables data binding to any
database, as well as classes, collections, and arrays, and provides true
XML representation of data. Seamless access to ADO enables simple data
access for connected data binding scenarios. Using ADO.NET, Visual
Basic .NET can gain high-speed access to MS SQL Server, Oracle, DB2,
Microsoft Access, and more.

5.Improved Coding
You can code faster and more effectively. A multitude of enhancements
to the code editor, including enhanced IntelliSense, smart listing of code
for greater readability and a background compiler for real-time
notification of syntax errors transforms into a rapid application
development (RAD) coding machine.

6.Direct Access to the Platform

Visual Basic developers can have full access to the capabilities available
in .NET Framework 1.1. Developers can easily program system services
including the event log, performance counters and file system. The new
Windows Service project template enables to build real Microsoft
Windows NT Services. Programming against Windows Services and
creating new Windows Services is not available in Visual Basic .NET
Standard, it requires Visual Studio 2003 Professional, or higher.

Variable and Data type


Every programming language needs some ways to organize the data
that is used in the user programs. The input which is given by the user
should be stored temporarily and to be processed by the program
where ever the data is required. Data type and variables are used for
organizing user data. Data type in a programming language describes
that what type of data a variable can hold and variables are used to
store the data temporarily until the data is used by the program.
1 Character set

Character set is nothing but the set of characters allowed and supported
in the programming language. Generally a program is a collection of
instructions, which contains group of characters. Only a limited set of
characters is allowed to write instructions in the program.
S.No Character Set Contents
1 Alphabets A- Z or a - z
2 Digits 0–9
3 Special + -*/ % . , : ;„ “| !\ ~ > < = ( ) { }[] #
Characters &^_ ?

2 Identifiers

An identifier is nothing but the name that is used for naming the
variables, Objects etc. In VB.NET, the identifier must begin with either a
letter or underscore ('_'). If an identifier begins with an underscore, it
must contain at least one other valid identifier character to
disambiguate it from a line continuation. Regular identifiers may not
match keywords, but escaped identifiers can match with keywords. An
escaped identifier is an identifier delimited by square brackets. Escaped
identifiers follow the same rules as regular identifiers except that they
may match keywords and may not have type characters. Although
Visual Basic .NET is not case sensitive, the case of identifiers is
preserved when applications are compiled. When using Visual
Basic .NET components from case- sensitive languages, the caller must
use the appropriate case.

3 Keywords

Keywords are nothing but the words that have some pre-defined
meaning. We It is impossible to use these words as identifiers of a
program. In Visual Basic.Net the keywords are reserved and it is even
impossible to use then as name of subroutines. The Keywords in Visual
Basic.Net are shown below.

S.No Keyword Usage


1 And Boolean operator
2 AndAlso Boolean operator
3 Ansi Used in the declare statement
4 Append Used as a symbolic constant
5 As Used in the variable declaration statement
6 Assembly Attribute specifier
7 Binary Option Compare statement
8 Boolean Variable declaration
9 Byte Variable declaration
10 Byval Argument lists
4 Variable and Rules
An identifier is used to identify and store some value. If the value of the
identifier is changed during the execution of the program, then the
identifier is known as variable. When the variable holds numeric data, it
is called as numeric variable and when it holds character(s) it is called
as Character/String variable. To name a variable in Visual Basic 2010,
you have to follow a set of rules.

1. It must be less than 255 characters


2. No spacing is allowed
3. It must not begin with a number
4. Period is not permitted

Examples of valid and invalid variable names are displayed in Table

Valid Variable Name Invalid Variable Name


Name Name of student
Student_name 1name
Student123 Student-name
Number1, number2 Number 1

5 Declaring Variables
Before using a variable in the program, it must be declared. The
declaration of variable tells the compiler about the type of data to be
held by the variable and the memory to be reserved for it and to store
the initial value in it. Variables are normally declared in the general
section of the codes' windows using the Dim statement. Dim is a
keyword. Dim stands for Dimension. The format is as follows:

Dim Variable Name As Data Type

Some of the valid variables are as follows


Dim i as integer // Integer variable
declaration Dim name as string //
String variable declaration
Dim x, y as integer // Two variables are used in
the same declaration Dim x as double // Real variable
declaration
Dim doDate As Date // Date is a special data type for Date function

It is possible to combine two or more variables in a single statement.

The variables names can be separated by using a comma as shown in


the above statement. There are two
possible formats are available for declaring string such as one for the
variable-length string and another for the fixed-length string. For the
variable-length string, just use the same format as shown above.
However, for the fixed-length string the total number of characters
should be specified at the declaration time. The format for fixed length
string is

Dim VariableName as String * n


Where n defines the total number of string that a string can hold.
Private Sub Button1_Click (ByVal sender As System.Object,ByVal e_
As System.EventArgs) Handles Button1.Click
Dim i, j, k As
Integer i =
20
j = 20
k=i+j
TextBox1.Text = k
Dim a, b, c As
String a = "
Welcome"
b = " To "
c = "Visual Basic"
TextBox2.Text = a + b +
c
End Sub

In the above example, The variable C produces the output string


“Welcome to Visual Basic”. Here + symbol denotes Concatenation
operator.

6 Variable initialization

After declaring various variables using the Dim statements, it is possible


to assign values to those variables. The general format of an assignment
is
Variable=Expression

The variable can be a declared variable or a control property value. The


expression could be a mathematical expression, a number, a string, a
Boolean value (true or false) and etc. The following are some examples:

Number1 = 100
Number2 =
Number1-45
Username = “AnandKumar”
Button1.Visible = True
Label4.Caption =
textbox1.Text Number3 = Val
(Textbox1..Text)

7 New and Nothing Keyword

The New is a Keyword which is used to create the instance of the class.
Unlike value types, such as Integer and Double, objects are reference
types, and it should be created explicitly before using them in the
program. It is also possible to create an instance of the form as well as
all the controls. For example Button is control and the class for button is
Button. So the instance can be created in such a way as shown below

Dim Button1 As System.Windows.Forms.Button


Dim Button2 As New
System.Windows.Forms.Button() Dim frm As New
System.Windows.Forms.Form1()

In the above statements, the first statement declares an object variable


that can contain a reference to a button object. However, the variable
Button1 contains the value nothing until you assign an object of type
Button to it. The second statement also defines a variable that can
contain a button object, but the New keyword creates a button object
and assigns it to the variable Button2. Both forms and controls are
actually classes; the New keyword can be used to create new instances
of these items as needed.

The Nothing keyword represents the default value of any data type.
Assigning Nothing to a variable sets it to the default value for its
declared type. If that type contains variable members, they are all set to
their default values. The following example uses the Nothing keyword

Private Sub Button1_Click (ByVal sender As System.Object, ByVal e_ As


System.EventArgs) Handles Button1.Click
Dim i as
integer Dim
s as Boolean
i=Nothing //sets i to 0
s= Nothing //sets s to False
End Sub

8 Implicit and Explicit declarations


There are two ways to declare the variables for the program. They
are implicit declarationand Explicitdeclaration. In the
implicit declaration, Visual basic
automatically create the variable for the user application. Implicit
declaration means that Visual Basic automatically creates a variant for
each identifier it recognizes as a variable in an application
The second approach to declaring variable is to explicitly declare
them with one of the following keywords Dim, Static, Private, and
Public. The choice of keyword has a profound effect on the variable‟s
scope within the application and determines where the variable can be
used in the program
Dim VariableName as
DataType Static
VariableName as
DataType Private
VariableName as
DataType Public
VariableName as
DataType
Visual Basic.Net reserves the amount of memory required to hold the
variable as soon as the declaration statement is executed. After a
variable is declared, it is not possible to change its data type, although it
is quite easy to convert the value of a variable and assign the converted
value to another variable

9. Scope of Variable

The scope of a variable referred to as accessibility of a variable. It


includes the information about the variable such as where the variable
can be read from and/or written to, and the variable's lifetime, or how
long it stays in memory.. Variables can be declared in four different
locations in the programs as shown in the following table.

S.No Location Usage


1 Block
If the variable is declared within a control statement such as an
If
statement, then that variable's scope is only until the end of the
block. The lifetime is until the procedure ends.
2 Procedure
If the variable is declared within a procedure, but outside of any
If statement, then the scope is until the End Sub or End
Function.
The lifetime of the variable is until the procedures ends
3 Module/Class
Variables can be declared outside of any procedure, but it must
be within a Class…End Class or Module…End Module
statement.
The scope is any procedure within this module. The lifetime
for a variable defined within a class is until the object is
cleaned up by
the garbage collector. The lifetime for a variable defined within
a module is until the program ends.
4 Project
It is possible to declare a Public variable within a Module…End
Module statement, and that variable's scope will be any
procedure or method within the project. The lifetime of the
variable will be
until the program ends.

Table Scope of the variables

There are many different ways you can declare variables. Variables can
be declared with any one of the scope such as public, private, protected,
friend and protected friend. If the variable is declared as public then the
variable will be available anywhere in or outside of the project. If it is
declared as private then it is visible only within the block where it is
declared. When the variable is declared as protected then it can be used
in the class where defined and within any inherited class. When used
with friend it can only be accessed by code in the same
project/assembly. If the variable is declared as protected friend then it
has the combination of protected and friend.

10 Data Types

Before writing any program we have to decide the variables that are
going to be used in the program, the purpose of the variable and type of
data it should. Visual Basic classifies the information mentioned above
into two major data types such as numeric data types and the non-
numeric data types.

1 Numeric Data Types

Numeric data types are types of data that consist of numbers, which can
be computed mathematically with various standard operators such as
addition, Subtraction, multiplication and division. Some of the examples
of numeric data types are height, weight, student marks, class strength,
monthly bills, fees etc. In Visual basic, numeric data are divided into 7
types, depending on the range of values they can store. Calculations that
only involve round figures or data that don't need precision can use
Integer or Long integer in the computation. Programs that require high
precision calculation need to use Single and Double decision data types,
they are also called floating point numbers. For currency calculation,
currency data types can be used. Lastly, if even more precision is
requires performing calculations that involve a many decimal points,
decimal data types can be used.
S.No Data Type Size Range of Values
1 Byte 1 byte 0 to 255
2 Integer 2 bytes -32,768 to 32,767
3 Long 4 bytes -2,147,483,648 to 2,147,483,648
4 -3.402823E+38 to -1.401298E-45 for negative
Single 4 bytes
values
1.401298E-45 to 3.402823E+38 for positive values.
5 -1.79769313486232e+308 to -
Double 8 bytes 4.94065645841247E-
324 for negative values 4.94065645841247E-324 to
1.79769313486232e+308 for positive values.
6 -922,337,203,685,477.5808 to
Currency 8 bytes 922,337,203,685,477.5807
7 +/- 79,228,162,514,264,337,593,543,950,335 if no
decimal is use +/-
Decimal 12 bytes
7.9228162514264337593543950335 (28
decimal
places).

2 Non-numeric Data Types


Nonnumeric data types are data that cannot be manipulated
mathematically using standard arithmetic operators. The non-numeric
data comprises text or string data types, the Date data types, the
Boolean data types that store only two values (true or false), Object data
type and Variant data type .

S.No Data Type Size Range of Values


1 String(fixed Length of
1 to 65,400 characters
length) string
2 String(variable Length +
0 to 2 billion characters
length) 10 bytes
3 Date 8 bytes January 1, 100 to December 31, 9999
4 Boolean 2 bytes True or False
5 Object 4 bytes Any embedded object
6 Variant(numeric) 16 bytes Any value as large as Double
7 Length+22
Variant(text) Same as variable-length string
bytes
Operators in VB.NET
Operators are symbols (characters or keywords) that specify operations
to be performed on one or two operands. Operators that take one
operand are called unary operators. Operators that take two operands
are called binary operators. Unary Visual basic supports many
operators that are described in the following sections.

1. Arithmetic Operators
2. Relational Operators
3. concatenation Operators
4. Bitwise Operators
5. Logical Operators
6. Unary Operators

1 Arithmetic Operators

The arithmetic operators perform the standard arithmetic operations


on numeric values Computer performs mathematical calculations much
faster than humans. However, computer itself will not be able to
perform any mathematical calculations without receiving instructions
from the user. It is necessary to instruct the computer to perform
mathematical calculations such as addition, subtraction, multiplication,
division and other kinds of arithmetic operations. In order for VB2010
to carry out arithmetic calculations, we need to write code that involves
the use of various arithmetic operators. The VB2010 arithmetic
operators are very similar to the normal arithmetic operators, only with
slight variations. The plus and minus operators are the same while the
multiplication operator use the * symbol and the division operator use
the / symbol. The list of VB2010 arithmetic operators are given below.

S.No Operator Function Example


1 + Addition 5+2=7
2 -- Subtraction 8-1=7
3 ^ Exponential 2^4=16
4 * Multiplication 4*4=16
5 / Division 12/4=3
Modulus (return the 17 Mod 4=1 165 mod
6 Mod remainder
10=5
from an integer division)
7 \ Integer Division (discards the 19\4=4
decimal places)

2. Relational Operators

The relational operators perform some comparison between two


operands and return a Boolean value indicating whether the operands
satisfy the comparison. The relational operators supported by Visual
Basic .NET are:

S.No Operators Usage


1 = Equality
2 <> Inequality
3 < Less than
4 > Greater than
5 >= Greater than or equal to
6 <= Less than or equal to
7 TypeOf...Is To check the instance of the class
8 Is To Check the reference of the object.
9 Like To check the patterns of operands

The operators such as equality, inequality, less than Greater then,


Greater then or equal to and less than or equal to are almost used in
every programming languages. The TypeOf...Is operator is defined to
take a reference as its first parameter and the name of a type as its
second parameter. The result is True if the reference refers to an object
that is type-compatible with the given type-name; False if the reference
is Nothing or if it refers to an object that is not type-compatible with the
given type name. Use the TypeOf...Is operator to determine whether a
given object is an instance of a given class, is an instance of a class that is
derived from a given class or exposes a given interface. The Is operator
is defined for all reference types. The result is true if the references refer
to the same object; false if not.

3 Concatenation Operators
Concatenation operators are used to concatenate multiple strings into a
single string. There are two concatenation operators available in visual
basic as shown in the table below.

S.No Operators Usage


1 + String Concatenation
2 & String Concatenation
4 Logical / Bitwise Operators

The logical operators compare Boolean expressions and return a


Boolean result. In short, logical operators are expressions which return
a true or false result over a conditional expression. The table below
summarizes them:

S.No Operators Usage


1 Not Negation
2 And Conjunction
3 AndAlso Conjunction
4 Or Disjunction
5 OrElse Disjunction
6 Xor Disjunction

5 Unary Operators
Operators that take one operand are called unary operators. VB.Net
provides the set of unary operators as shown the table below.

S.No Operator
s
1 Unary Plus (+)
2 Unary Minus(-)
3 Not (Logical)
4 AddressOf

The unary plus operator takes any numeric operand. It's not of much
practical use because the value of the operation is equal to the value of
the operand. The unary minus operator takes any numeric operand
(except as noted later). The value of the operation is the negative of the
value of the operand. In other words, the result is calculated by
subtracting the operand from zero. If the operand type is Short, Integer,
or Long, and the value of the operand is the maximum negative value for
that type, then applying the unary minus operator will cause a
ystem.OverflowException error, as in the following code fragment. The
logical negation operator takes a Boolean operand. The result is the
logical negation of the operand. That is, if the operand is False, the result
of the operation is true, and vice versa The AddressOf operator returns
a reference to a method. The Unary
Constants
If the value of the variable is not changed during the execution of the
program, then the variable is called as constant. For example, take a
students information of a class, student-name is a variable, because it
will changes to all the students. But the class-name is a constant and it
will not be changed for the particular class students. The syntax for
declaring constant is

Const Constant Name As Data Type = Value

Constants are different from variables in the sense that their values do
not change during the running of the program. The format to declare a
constant is

Example

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Const I as integer=10
Dim j as integer = 20
I=i+1
J=j+2
Textbox1.tex
t=I
Textbox2.tex
t=j End Sub

In this example i=i+1 is impossible, since i is declared as constant


which should not be changed during the execution of the program.

Arrays
A variable is used to store the value which may be used for further
reference. In a simple variable only one value can be stored at a time So
how to store multiple values in the single variable?. The solution is
Arrays. Array is a collection of elements or data items All the elements
must be same data type and they are stored in consecutive memory
locations. It is a programming constructs that store data and allow user
to access them by numeric index or subscript. Arrays in Visual
Basic .NET inherit from the Array class in the System namespace. All
arrays in VB are zero based, meaning, the index of the first element is
zero and they are numbered sequentially. The user must specify the
number of array elements by indicating the upper limit or size of the
array. The upper limit is the number that specifies the index of the last
element of the array. Arrays are declared using Dim, ReDim, Static,
Private, Public and Protected keywords. An array can have one
dimension or more than one (multidimensional arrays). The
dimensionality of an array refers to the number of subscripts used to
identify an individual element. In Visual Basic the user can specify up to
32 dimensions. Arrays do not have fixed size in Visual Basic. The syntax
for declaring an array is

Dim|Public|Private ArrayName(Subscript) As DataType

ArrayName is the name of the array. Subscript is the dimensions of the


array. DataType is any valid data type. Dim, Public, and Private declare
the array and its scope. Using Dim in a procedure will make the array
only available from within that procedure. Using it in the General
Declarations section will make it available to all procedures in that
module. Private has the same effect and should be used only at the
modular level. Using Public will make the array available throughout the
project. Let us see a simple example by creating an array of size 5 to
store student names.

Dim student (4) as


String
student(0)=”Anil”
student(1)=”Binoy”
student(0)=”Cheem
a”
student(0)=”Dhoni”
student(0)=”Farkha
t”

Array is created with name as student. Size of the array is five. First
name is stored in index of 0, second in 1 and so on. To retrieve the
elements from the array the index can be used as shown below.

MessageBox..Show(student(0))

When the statement is executed, message box will appear that displays
the first name from the array student. Instead of message box textbox
can be used to display the result with the following code

TextBox1.text = student (1)

Program to store the student name in the array and to print the name in
message box.

Private Sub Button1_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim student(4) As
String student(0) =

"Anil" student(1) =
"Binoy"
student(2) = "Cheema"
student(3) = "Dhoni"
student(4) = "Farkhat"
MessageBox.Show(stude
nt(0))
End Sub

It is possible to declare an array without specifying the number of


elements. The user must provide values for each element when
initializing the array.

Dim Test () as Integer


Test=New Integer ()
{1,2,3,4,5}

It is possible to change the size of an array after creating them. The


ReDim statement assigns a completely new array object to the specified
array variable. ReDim statement is used to change the number of
elements in an array.

Dim Myarray(5) as
Integer ReDim
Myarray(10) as Integer

When the Redim statement is used to reinitialize the array, all the data
contained in the array will be lost. If the user wants to preserve existing
data when reinitializing an array then Preserve keyword should be used
as shown below.

Dim Myarray(5) as Integer


ReDim Preserve Myarray(10) as integer

Program to store different states in India using array and displaying


them using message box. Write the following code in the form load
event.
Private Sub Form1_Load(ByVal sender As System.
Object, ByVal e As System.EventArgs)_
Handles MyBase.Load
Dim states (5) as
String Dim counter as
Integer
States(0)=”Andra
Pradesh”
States(1)=”Madhya
Pradesh”
States(2)=”Kerala”
States(3)=”Tamil Nadu”
States(4)=”Andra
Pradesh”
States(5)=”Hmachal
Pradesh” For counter = 0
to states.count-1
MessageBox.Show(states(co
unter)) Next
End Sub

Example Program to store different states in India using array and


displaying them using ListBox. Write the following code in the button click
event.
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim states(5) As
String Dim counter As
Integer states(0) =
"Andra Pradesh"
states(1) = "Madhya
Pradesh" states(2) =
"Kerala"
states(3) = "Tamil Nadu"
states(4) = "Andra
Pradesh" states(5) =
"Hmachal Pradesh"
For counter = 0 To states.Count - 1
ListBox1.Items.Add(states(coun
ter)) Next
End Sub

2 Multi Dimensional Arrays


A multidimensional array is also known as array of arrays. A
multidimensional array is the one in which each element of the array is
an array itself. It is similar to tables of a database where each row is the
collection of other secondary columns. If the secondary elements do not
contain a collection of other elements, it is called a 2-dimensional array,
the most common type of multidimensional array, otherwise it is called
an n-dimensional array where n is the depth of the chain of arrays.

There are two kinds of multidimensional arrays supported by the .NET


framework: Rectangular arrays and Jagged arrays.

a) Rectangular arrays
Rectangular arrays may be single-dimensional or multidimensional but
always have a rectangular shape. Rectangular means that the length of
each sub array in the same dimension is the same length. Array types
are reference types, so the declaration of an array variable merely sets
aside space for the reference to the array. Array instances are actually
created via array initializes and array creation expressions

Dim rectArray(4, 2) As Integer


Dim rectArray(,) As Integer = {{1, 2, 3}, {12, 13, 14}, {11, 10, 9}}
Example
Program to create Rectangular array and print the array using console
application of Visual Basic.Net
Public Sub RectangularArray()
For i As Integer = 0 To
rect.GetUpperBound(0) For j As
Integer = 0 To rect.GetUpperBound(1)
Console.Write(rect(i, j) &
ControlChars.Tab) Next
Console.WriteLi
ne() Next
End Sub

In the above example the rectangular array called rectarray is declared.


It consists of 6 rows starting from 0 to 5 and 6 columns starting from 0
to 5. The next line of code simply prints the content of the array to the
console.

Note: The elements of the array are not explicitly initialized. So all the
elements by default will be 0 of Integer type.

b) Jagged Arrays

Jagged Array is an array of arrays in which the length of each array can
differ. A Very good example for Jagged arrays is creating a table in which
the number of columns differ in each row. Say, if row1 has 3 columns,
row2 has 3 columns then row3 can have 4 columns, row4 can have 5
columns and so on. The following code demonstrates jagged arrays. It is
the another type of multidimensional array.

Dim colors(2)() as String


colors(0)=New String(){"Red","blue","Green"}
colors(1)=New String()
{"Yellow","Purple","Green","Violet"}
colors(2)=New String(){"Red","Black","White","Grey","Aqua"}
Example
Program to demonstrate Jagged Array. The result is display using
console application. Public Class MyClass
Public Shared Sub Main()
Dim JaggedArray As Integer()() = New Integer(3)
() {} JaggedArray(0) = New Integer(2) {}
JaggedArray(1) = New
Integer(1) {} JaggedArray(2)
= New Integer(4) {}
JaggedArray(3) = New
Integer(3) {}
Console.WriteLine("Enter the numbers for
Jagged Array") For i As Integer = 0 To
JaggedArray.Length - 1
For x As Integer = 0 To
JaggedArray(i).Length - 1 Dim st As
[String] = Console.ReadLine()
Dim num As Integer =
Int32.Parse(st) JaggedArray(i)
(x) = num
Nex
t Next
Console.WriteLine("")
Console.WriteLine("Printing the
Elements") For x As Integer = 0 To
JaggedArray.Length - 1
For y As Integer = 0 To JaggedArray(x).Length -
1 Console.Write(JaggedArray(x)(y))
Console.Write(vbNullChar)
Next
Console.WriteLine("
")
Next
Console.ReadLi
ne()
End
Sub End
Class
Output Window
Dynamic Arrays

A dynamic array is an array which is used to specify the size at the


run time. So the programmer can fix the size based upon the
requirement .It allows the user to keep the number of elements in
the array unspecified at the declaration time. Moreover, once
declared, the number of elements can be altered later based on the
requirement. It is an advantage over the static array. The wastage of
memory space can be eliminated. Dim statement with empty
parentheses can be used to declare a dynamic array. Dynamic arrays
can be dimensioned or redimensioned as you need them with the
ReDim statement. Preserve keyword can be used to preserve the
data in an existing array when the user change the size of the last
dimension.
Dim DynaStrings() As
String ReDim
DynaStrings(10)
DynaStrings(0) = "String
0" ReDim
DynaStrings(100)
DynaStrings(50) =
"String 50"

The upper bound of an array can be identified using the UBound


function, which makes it easy to loop over all the elements in an array
using a For loop There are some limitations on dynamic arrays such as
 The dynamic part of the array must be of unpacked nature. A packed array
can not be dynamic.
 The unpacked (and dynamic) part of the array must be one dimensional.
More than one dimension is not allowed for dynamic arrays.
Control Arrays

Control Arrays are arrays of controls sharing a common event handler.


That is, you need to write code for only one event, which can handle
other controls' events.
For example if you consider an application like calculator, where on the
click event of the buttons from 0 to 9, you want to append the text to the
visible text. So when you write code for all individual buttons, it is a
time consuming process. Because we need the same peace of code for all
these buttons, we can create one event handler to handle the events
raised by all these buttons.
In Visual Basic 6, this was fairly simple. You have to copy and paste the

control and confirm „Yes‟ when asked, whether to create a control


array. You can see the first control
automatically gets an index of zero and the following controls get the
index incremented by one from the last control. And if you double click
on the buttons, you can see all these controls have same event handler,
however you can notice a new argument, which is passed to the click
event, named Index. This index property is the one, which will tell you
which button is clicked (If you want to know, which one clicked). To
create this while runtime, you can copy one control at design time and
use this button to create other buttons. You can load a control and
remove a control dynamically in VB6.
In Dot net the creation of control arrays are easier than the previous
versions and are not created by copying and pasting, instead simply add
the control events to the Handles list. You can give any name to this
procedure.
Example

Private Sub ClickButton(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles


Button1.Click, _ Button2.Click, Button3.Enter
Dim btn As Button
btn = CType(sender,
Button)
MsgBox(btn.Text)
End Sub
In the above example ClickButton procedure is handling the click event
of Button1 and Button2, whereas Enter event of the Button3. In order to
check the control that is pressed, you need to convert the sender to the
respective type. The CType function converts it into a button type, so
that you can access the attributes of the event raised by the control.

Handling Mouse Events in the Form


All Windows applications are event-driven. For example, nothing
happens in Word until you click on a button, select a menu option, or
type some text. Each of these actions is an event. We can handle mouse
events such as mouse pointer movements in Forms. The mouse events
supported by VB .NET are as follows:
 MouseDown: This event happens when the mouse pointer is over the
form/control and is pressed
 MouseEnter: This event happens when the mouse pointer enters the
form/control MouseUp: This event happens when the mouse pointer is over
the form/control and the mouse button is released
 MouseLeave: This event happens when the mouse pointer leaves the
form/control
 MouseMove: This event happens when the mouse pointer is moved over the
form/control
 MouseWheel: This event happens when the mouse wheel moves while the
form/control has focus
 MouseHover: This event happens when the mouse pointer hovers over the
form/control

The properties of the MouseEventArgs objects that can be passed to the


mouse event handler are as follows:

Button: Specifies that the mouse button was pressed


Clicks: Specifies number of times the mouse button is
pressed and released X: The X-coordinate of the mouse click
Y: The Y-coordinate of the mouse click
Delta: Specifies a count of the number of detents (rotation of mouse
wheel) the mouse wheel has rotated

VB.NET String Class


(i) The Len Function:

The length function returns an integer value which is the length of a


phrase or a sentence, including the empty spaces. The format is
Len (“Phrase”)
or example, Len (VisualBasic) = 11 and Len (welcome to VB tutorial) = 22
The Len function can also return the number of digits or memory
locations of a number that is stored in the computer. For example,
Private sub
Form_Activate ( ) X=sqr
(16)
Y=123
4
Z#=10
#
Print Len(x), Len(y), and Len (z)
End Sub
will produce the output 1, 4 , 8. The reason why the last value is 8 is
because z# is a double precision number and so it is allocated more
memory spaces.
(ii) The Right Function
The Right function extracts the right portion of a phrase. The format is
Right (“Phrase”, n)
Where n is the starting position from the right of the phrase where the
portion of the phrase is going to be extracted. For example,
Right(“Visual Basic”, 4) =
asic (iii)The Left Function
The Left$ function extract the left portion of a phrase. The format is
Left(“Phrase”, n)
Where n is the starting position from the left of the phase where the
portion of the phrase is going to be extracted. For example,
Left (“Visual Basic”, 4) = Visu
(iv) The Ltrim Function
The Ltrim function trims the empty spaces of the left portion of the
phrase. The format is
Ltrim(“Phrase”)
.For example,
Ltrim (“ Visual Basic”, 4)= Visual basic
(v)The Rtrim Function

The Rtrim function trims the empty spaces of the right portion of the
phrase. The format is
Rtrim(“Phrase”)
.For
example,
Rtrim (“Visual Basic ”, 4) = Visual basic
(vi) The Trim function
The Ttrim function trims the empty spaces on both side of the phrase. The
format is
Trim(“Phrase”)
.For example,
Trim (“ Visual Basic ”) = Visual basic
(viii) The Mid Function

The Mid function extracts a substring from the original phrase or string.
It takes the following format:
Mid(phrase, position, n)
Where position is the starting position of the phrase from which the
extraction process will start and n is the number of characters to be
extracted. For example,
Mid(“Visual Basic”, 3, 6) = ual Bas
(ix) The InStr function

The InStr function looks for a phrase that is embedded within the
original phrase and returns the starting position of the embedded
phrase. The format is
Instr (n, original phase, embedded phrase)
Where n is the position where the Instr function will begin to look for
the embedded phrase. For example
Instr(1, “Visual Basic”,” Basic”)=8
(x) The Ucase and the Lcase functions

The Ucase function converts all the characters of a string to capital


letters. On the other hand, the Lcase function converts all the characters
of a string to small letters. For example,
Ucase(“Visual Basic”) =VISUAL BASiC
Lcase(“Visual Basic”) =visual basic
(xi) The Str and Val functions

The Str is the function that converts a number to a string while the Val
function converts a string to a number. The two functions are important
when we need to perform mathematical operations.
(xii) The Chr and the Asc functions

The Chr function returns the string that corresponds to an ASCII

code while the Asc function converts an ASCII character or symbol to


the corresponding ASCII
code. ASCII stands for “American Standard Code for Information
Interchange”. Altogether there are 255 ASCII codes and as many ASCII
characters. Some of the characters may not be displayed as they may
represent some actions such as the pressing of a key or produce a beep
sound. The format of the Chr function is
Chr(charcode)
and the format of the Asc function is
Asc(Character)
The following are some examples:
Chr(65)=A, Chr(122)=z, Chr(37)=% , Asc(“B”)=66, Asc(“&”)=38

Subroutines and Functions

A Procedure is a unit of code outside of the main execution code. But it


can be executed by an invoking statement in the main execution code.
There are 3 aspects about procedures:
1. Defining a procedure.
2. Invoking a procedure.
3. Exchanging data between the main execution code and a procedure.

VB offers two types of procedures:


1. Function Procedure - A procedure that returns a value explicitly.

Defining and Invoking Function Procedures


A "Function" statement defines a function procedure with the following
syntax:
Function
function_name(argument_list)
statement_block
function_name =
return_value End Function
where "function_name" is the name of the function, "argument_list" a
list of variables
used to pass data into and/or out of the function, and "return_value" is
the value to be
returned explicitly to the invoking statements. Of course,
"argument_list" is optional.
Assigning the return value to the function name is also optional. If not
given, default value will be returned to the invoking statements. But
this is not recommended.
Invoking a function procedure is simple, no need of any special
... function_name(argument_list) ...
This will cause the system to:
 Stop evaluating the expression.
 Map data or variables based on the argument list.
 Execute the entire statement block defined inside the function.
 Take the value returned in the function name.
 Continue to evaluate the expression.

If you want terminate a function procedure early, you can use the "Exit"
statement:
MsgBox() Function
Msgbox () function displays a message in a dialog box, waits for the user
to click a button, and returns an Integer indicating which button is
clicked by the user. Its syntax is MsgBox(prompt [, buttons] [, title])

The description of arguments in the function is as follows:

 Prompt Required. It is a string expression that will appear as the message in


the dialog box.
 Buttons Optional. It is a numerical expression that sums the values used to
specify the number and type of buttons to display, the icon style to use, the
identity of the default button, and the modality of the message box. The
default value for buttons is 0 when this argument is omitted.
 Title Optional. It is a string expression that will appear in the title bar of the
dialog box. The application name is placed in the title bar when this
argument is omitted.

The key buttons settings are:


The Return Values can be one of the values in the list below:

An example of the MsgBox () function is as follows:


Response = Msgbox (“No real roots exist”,
VBYesNo, _ “Example”)
If response = vbYes
then Exit Sub
End if
The MsgBox() function asks the user to respond by clicking on the Yes or
No button. If the user clicks the Yes button, the value of 6 (or VbYes) will
be returned and assigned to the variable response. The next statement
will check if the return value is VBYes. If it is VBYes, then the program
executes the Exit Sub statement and exits the procedure.
The InputBox( ) Function
The InputBox( ) function will display a message box where the user can
enter a value or a message in the form of text. The format is

myMessage=InputBox(Prompt, Title, default_text, x-position, y-


position)
myMessage is a variant data type but typically it is declared as string,
which accept the message input by the users.
The arguments are explained as follows:

 Prompt - The message displayed normally as a question asked.


 Title - The title of the Input Box.
 default-text - The default text that appears in the input field where users can
use it as his intended input or he may change to the message he wish to key
in.
 x-position and y-position - the position or the coordinate of the input box.

Example
Private Sub OK_Click()

Dim userMsg As String


userMsg = InputBox("What is your message?", "Message Entry
Form", "Enter your messge here", 500, 700)
If userMsg <> "" Then
message.Caption =
userMsg Else
message.Caption = "No
Message" End If

End Sub
When a user click the OK button, the input box as shown in Figure 10.5
will appear. After user entering the message and click OK, the message
will be displayed on the caption, if he click Cancel, "No message" will be
displayed.

Controlling Structures

Normally the statements of a program will executed sequentially, one by


one from the main ( ) function. Using the control statements can alter
the sequence of execution. These statements also can be used to take
some decisions, repeating the process number of times etc. To
effectively control the VB2008 program flows, if control structure can
be used together with the conditional operators and logical operators.

Decision Making Statements

The conditional control statements are used to check some condition


and then transfer the control based on the condition result. There are
few control statements available and they are
1. If.....Then statement
2. If....Then.....Else
3. If....Then.....Else If
4. Select Case

If Then Statement
This is the simplest control structure which asks the computer to
perform a certain action specified by the VB expression if the condition
is true. However, when the condition is false, no action will be
performed. The general format for the if...then.. Statement is

If condition
Then
Statements
End If
Program to check whether the given number is greater than 50 or
not
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim number1 As
Integer number1 =
TextBox1.Text If
number1 > 50 Then
Msgbox” The number is greater than
50” End If
End
Sub
End
Sub
This program displays the message box if the condition is satisfied. If the
user enters the number smaller then 50 then the user will not receive
any output. This indicates that if only the condition is satisfied then the
statement will be executed. It is the drawback of simple If statement.

If....Then...Else Statement

If Then statement that is used above is not very useful in programming


and it does not
provide choices for the users. In order to provide a choice, If....Then. Else
Statement can
be used. This control structure will ask the computer to perform a
certain action specified by the VB expression if the condition is true.
And when the condition is false an alternative action will be executed.
The general format for the if...then.. Else statement is

If condition
Then
Statement
(1)
Else
Statement
(2) End If

The above program can be rewritten with the use of If Then


Else Statement Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim number1 As
Integer number1 =
TextBox1.Text If
number1 > 50 Then
Msgbox” The number is greater than
50” Else
Msgbox “ The number is smaller than 50”
End If
End Sub
End Sub

In the previous program, when user inputs the value smaller than 50
then no output will be displayed. But in this program, even if the input is
smaller than 50 the message box will be displayed as “The number is
smaller than 50”. This is possible only with the use If Then else
statement.

If....Then...Else If Statement
If there are more than two alternative choices, using jus If....Then. Else
statement will
not be enough. In order to provide more choices, we can use the If....Then.
ElseIf
Statement. The general format for the if...then.. Else
statement is If condition Then
Statement (1)
ElseIf condition
Then
Statement
(2) ElseIf
condition Then
Statement (3).
.
.
.
Else
Statement (n)
End If

This is a program to print the Grade of a student based on the average of


marks. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Mark As
Integer Dim Grade
as String Mark =
TextBox1.Text If
Mark >=80 Then
Grade="A"
ElseIf Mark>=60 and Mark<80 then
Grade="B"
ElseIf Mark>=40 and Mark<60 then
Grade="C"
Else
Grade="D"
End If
End Sub
Select Case Statement
Another way to control the program flow is to use the Select Case
control structure. The Select Case control structure is slightly different
from the If....Else If control structure. The main difference is that the
Select Case control structure only make decision on one expression or
dimension, while the If ...Else If statement control structure may
evaluate only one expression, each If....Else If statement may also
compute entirely different dimensions. Select Case is preferred when
there exist many different conditions because using If...Then..ElseIf
statements might become too messy. The syntax for select case
structure is shown below.

Select Case test


expression Case
expression list 1
Block of one or more
statements Case expression
list 2
Block of one or more
Statements Case expression list
3
Block of one or more
statements Case expression
list 4
.
Case Else
Block of one or more VB
Statements End Select

In the select case statement it is possible to use the IS Keyword


along with the comparison operators For Example

Select Case
mark Case
Is >= 85
Textbox1.Text= "Excellence

It is possible to use Select Case statement with numbers, as well, and the
To word comes in very handy here. If you were checking a variable to
see if the number that was in the variable fell within a certain range, you
could use something like this:
Select Case
mark Case 0
to 40
Textbox1.Text = "Fail"

Here, a variable called mark is being tested. It's being checked to see if it
falls between certain values. If it does, then a message box is displayed.
Looping Structures
The simple statements that had discussed in the previous section are
used to execute the statements only once. If suppose a programmer
needs to execute the same statements multiple times. Then some other
statement should be used. The solution for this is a looping statement. .
For example, to print the string “Visual basic” five times. The same
statement should be used five times in the coding. But, imagine if the no.
of time increases to print 1000 times or N times. By using the looping
statements a statement or set of statements can be executed repeatedly.
Visual Basic 2010 allows a procedure to be repeated as many
times as long as the processor and memory could support. This is
generally called looping. In Visual Basic 2010, different looping
statements are available such as Do Loop, For Loops etc.
Do Looping Statements
Looping is a very useful feature of Visual Basic because it makes repetitive
works easier.
Do Loop statements provide a way to continue iterating while one
or more conditions are true? Many types of Do Loops exists in
Visual Basic.Net such as
1. Do…While Statement
2. Do…Loop While Statement
3. Do…Until Statement
4. Do…Loop Until

Do… While Statement


The Do loop executes a block of statements either until a condition
becomes true or while a condition remains true. The condition can
be tested at the beginning or at the end of each iteration. If the test
is performed at the end of each iteration, the block of statements
is guaranteed to execute at least once. The Do loop can also be
written without any conditions, in which case it executes
repeatedly until and unless an Exit Do statement is executed
within the body of the loop. The general form of Do…While
Statement is

Do while condition
Block of one or more
statements Loop

Program to demonstrate the use of Do while Loop


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim counter as
Integer Counter
=1
Do while counter <=100
TextBox1.Text=count
er Counter +=1
Loop
End Sub

This program prints the numbers from 1 to 100 in the textbox. Once it
reach 100, the loop terminates.

Do…Loop While Statement


It is another format of Do statement. Here the statements are executed
while the condition is satisfied. The format is given below.
Do
Block of one or more
statements Loop While
condition

Program to demonstrate the use of Do Loop While statement.


The code that is used in the previous example is rewritten here
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Counter=1
Do
TextBox1.Text=count
er counter+=1
Loop While counter>100
End Sub

Do Until Statement
Another format of Do Loops is Do ... Until statement. There is no much
difference between the two looping statements. The format is given
below
Do Until condition
Block of one or more
statements Loop

Program to demonstrate the use of Do Until statement.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Do Until number
> 5 MsgBox
number
number = number + 1
Loop

End Sub

The above program displays the numbers from 1 to 5 in the message


box when user clicks the button that is placed in the form.

Do Loop Until Statement


The format for this
statement is Do
Block of one or more
statements Loop Until
condition

Program to demonstrate the use of Do Loop Until statement


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Do
MsgBox number
number = number + 1
Loop Until number >=
5 End Sub

For Loop Statement

If the programmer wants to execute a block of statements to certain


number of times in VB.NET program, then For Loop can be used. The
For loop requires the user to provide a top index, a bottom index, and
also allows an optional step. The For loop is a powerful and expressive
way to iterate through numbers.

For…Next Statement
The For loop executes a block of statements a specified number of times.
The number of iterations is controlled by a loop variable, which is
initialized to a certain value by the For statement, then is incremented
for each iteration of the loop. The statements in the body of the loop are
repeatedly executed until the loop variable exceeds a given upper
bound.
For variable = expression To expression [ Step
expression ] Statements
Next [ variable_list ]
The loop variable can be of any numeric type. The variable is set
equal to the value of the first expression before entering the first
iteration of the loop body. Prior to executing each iteration of the loop,
the loop variable is compared with the value of the second expression. If
the value of the loop variable is greater than the expression (or less than
the expression if the step expression is negative), the loop exits and
execution continues with the first statement following the Next
statement
The step expression is a numeric value that is added to the loop
variable between loop iterations. If the Step clause is omitted, the step
expression is taken to be 1. The Next statement marks the end of the
loop body. The Next keyword can either appear by itself in the
statement or be followed by the name of the loop variable. If For
statements are nested, a single Next statement can terminate the bodies
of multiple loops. For example:

Program to print the numbers from 1 to 10 using For Loop

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim i as
Integer For
i=1 to 10
Msgbox i
Next
End Sub

This program will print the numbers from 1 to 10 in the message box.

Program to print the numbers from 1 to 100 using For Loop


and Step Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim i , sum As
Integer For ir=1 to
100 step 10
sum+=i
Msgbox
sum Next
End Sub
The program will calculate the sum of the numbers as
follows: sum=0+10+20+30+40+......

For…Each…Next Statement
The For Each statement is similar to the For statement, except that the
loop variable need not be numeric, and successive iterations do not
increment the loop variable. Instead, the loop variable takes successive
values from a collection of values. Here is the syntax
For Each variable In
expression Statements
Next [ variable ]

The loop variable can be of any type. The expression must be a


reference to an object that exposes the IEnumerable interface

Program to print the numbers from 1 to 100 using For Loop


and Step Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim d As Integer
For d = 1 To100 step
10 Textbox1.Text= d
Next d
End Sub
Possible Questions
Unit II

Part –B (2 Marks)

1. What is variable? What are the rule to be followed to define the variable.
2. What is Operator? List out its types.
3. Define Array. List out its types.
4. Write a note on message box. Give the example
5. Differentiate Entry control loop and Exit control loop.
6. Differentiate Message Box and Input Box.

Part –C (6 Marks)
1. Explain the different data types with example
2. Explain different operators in Vb.Net with example
3. What is an array? Explain its types
4. Explain message and input box with example
5. Explain different control flow statements by giving example
DEPARTMENT OF COMPUTER
TECHNOLOGY

REG.NO :
CLASS : II -
BSC IT
SEMESTER : IV
SUBJECT : MULTIMEDIA AND ITS APPLICATION
CODE : 18ITU514B

JULY 20 – DEC 20
KARPAGAM ACADEMY OF HIGHER EDUCATION
(Deemed to be university)
(Established Under section 3 of UGC Act 1956)
COIMBATORE-641021

DEPARTMENT OF COMPUTER
TECHNOLOGY CERTIFICATE
This is to certify
that this is a bona-fide record work done by
doing III- B.Sc. Information
Technology for the Practical Examination
in MULTIMEDIA AND ITS APPLICATIONS–
PRACTICAL held on

Staff-in-charge Head of the Department


(Internal Examiner) (External Examiner)
INDEX

S.No. Date Name of the Experiment Page No. Staff Sign

1. 07.09.2020 Shape Animation

2. 21.09.2020 Rain Animation

3. 24.09.2020 Subtracting The Shape

4. 19.10.2020 Dreamy Effect.

5. 22.10.2020 Fractal Effect

6. 02.11.2020 Transparent Glass Lettering

7. 23.11.2020
Bouncing Ball

8. 09.12.2020 Smoky Effect

9. 10.12.2020 Text Portrait

10. 11.12.2020 Bokeh Effect


Ex.No:1

DATE:07.09.2020 SHAPE ANIMATION

AIM :

To change a shape from one shape to another shape.

ALGORITHM :

STEP 1 : Start the process.

STEP 2 : Select Canvas->properties and click Time and Change End time as 2s
and close the dialog box.

STEP 3 : Drag a shape into the window keeping the time as 0f.

STEP 4 : Enable the man and set time as 48f.

STEP 5 : Drag and modify the shape into another shape.

STEP 6 : At the end click play button.

STEP 7 : Stop the process.


OUTPUT :

RESULT:

The above program has been executed successfully and the output is
verified.
Ex.No:2

DATE:21.09.2020 RAIN ANIMATION

AIM :

To create a rain animation using picture.

ALGORITHM :

STEP 1 : For unnatural and gloomy effect use cartoon filter (filter-Artistic-
cartoon).

STEP 2 : Add a new layer make it transparent fill the transparent layer with
random noise (filter-noise-Hurl Make sure randomize is checked) make it
gray scale, use layer-colors, Desaturate).

STEP 3 : Apply a blur filter (filter>blur>Motion Blur) leave it as linear and


adjust the length and angle to 34,121.

STEP 4 : Change the layer mode for the noise layer to screen and adjust its
color levels as shown (tools>color tools > levels to 109)

STEP 5 : Duplicate the base photo and for each duplicate repeat the previous
steps by adding a transparent layer, fill it with noise apply between and
motion blur desaturate, change the mode to screen, adjust levels

STEP 6 : Merge down the noise layer to their photo background to get the
final frames in the animation.

STEP 7 : Preview the end result (filter>animation>play back).


RESULT:

The above program has been executed successfully and the


output is verified.
Ex.No:3

OUTPUT :
DATE:24.09.2020 SUBTRACTING THE SHAPE

AIM :

To Subtract the shape using synfig studio.

ALGORITHM :

STEP 1 : Start the process.

STEP 2 : Choose the canvas and select properties.

STEP 3 : Drag the rectangle and circle shape into the screen.

STEP 4 : Move the circle and re-arrange the circle region

STEP 5 : change the circle outline’s blend method as into and change width as
3p

STEP 6 : Change circle regions’s blend method as alpha over

STEP 7 : Stop the process.


Ex.No:4

OUTPUT :
DATE:19.10.2020 DREAMY EFFECT

AIM :

To create a dreamy effect .

ALGORITHM :

STEP 1 : Open an image and create a new layer and change the name as mono.

STEP 2 : Place the original picture at the top and the mono layer at the
bottom.

STEP 3 : Select mono layer and select colors >components>channel Mixer


and change Red as 122, green as 101 and blue as 200.

STEP 4 : Select mono layer and select Filter>blur>Gaussian blur and change
horizontal as 15 and vertical as 15.

STEP 5 : Select Picture layer and set opacity as 60.

STEP 6 : Select mono layer and goto color>colorize and change the value of
hue to 253.

STEP 7: Click the original picture layer and create a duplicate layer. Repeat
steps from 3 to 9.

STEP 8 : Click the original layer and create a duplicate layer.Repeat steps from
3 to 8.
RESULT:
STEP 9: Merge down the mono layers to get the final effects of animation.
The above program has been executed successfully and the
STEP 10 : Preview the end result (filters>animation>playback).
output is verified.
STEP 11 : Click play button.
Ex.No:5

OUTPUT :
DATE:22.10.2020 FRACTAL EFFECT

AIM :

To create a tree shape using IFS fractal.

ALGORITHM :

STEP 1 : Start the process.

STEP 2 : Open a new image .

STEP 3 : Select filters menu and then select render >nature>IFS fractal.

STEP 4 : Using different options draw a leaf shape

STEP 5 : Using a color transformation change the color of the leaf.

STEP 6 : Display the output.

STEP 7 : Stop the process.

RESULT:

The above program has been executed successfully and the


output is verified.
Ex.No:6

OUTPUT :
DATE:02.11.2020 TRANSPARENT GLASS LETTERING

AIM :

To create a transparent glass lettering using gimp

ALGORITHM :

STEP 1 : Create a new file


STEP 2 : Select your text layer and sets its opacity to 60%. Now select the text
layer and click on your text, then click layer>Text to path.
STEP 3 : Select your text layer, then click Layer>Layer to image Size. Now add
drop shadow (Filters>Light and shadow>Drop Shadow). I set my offsets to 2
,blur radius to 20,color to black<opacity to 80 and unchecked allow resizing.
STEP 4 : Create a new layer. Them select Select> From Path (Shift +V). This
will create a selection around your text. Now Select>Feather at 10px. Then
pick a light, yellowish color and bucket fill your selection. Next,Select>Shrink
by about 2px. Delete this selection by pressing the delete key on your
keyboard (or Edit>Cut). Set the layer mode to screen ad set the opacity to
50%.
STEP 5 : Create another layer . Select your path again (Shift +v),then select
>shrink by about 8px.Now Select>Feather by 10px. Fill your selection with
black and set the layer mode to overlay at 100%.
STEP 6 : Create a new layer . Select your path again (Shift +V). Now choose
the Ellipse select tool and set the mode to intersect. Make a big selection over
the top half of your text.
RESULT:
STEP 7 : Set your foreground color to white. Now select the gradient tool, set
the shape to radial and gradient to “FG to Transparent”. Fill in your selection,
dragging from Thethe top-left of your first
above program letterexecuted
has been to the lower-right of your
successfully last
and the
latter. Set the layer mode to overlay at 50% .
output is verified.
Ex.No:7

OUTPUT :
DATE:23.11.2020 BOUNCING BALL

AIM :

To create a bouncing ball effect using a synfig studio.

ALGORITHM :

STEP 1 : Open a synfig Studio.

STEP 2 : Using a rectangle create a steps.

STEP 3 : Using a circle shape create a ball.

STEP 4 : Using a move tool move the circle through the rectangle.

STEP 5 : After setting the timing to 0f play the animation.

RESULT:

The above program has been executed successfully and the


output is verified.
OUTPUT :
Ex.No:8

DATE:09.12.2020 SMOKY EFFECT

AIM:

To create a smoky effect using GIMP.

ALGORITHM:

STEP 1: Open GIMP.

STEP 2: Click new in the file menu.

STEP 3: Choose paintbrush tool and draw the straight line.

STEP 4: Click filters menu and click the Blur -> Gaussian Blur and change
horizontal and vertical as 35

STEP 5: Click the filters menu and choose distorts-> Iwarp and change to
smoky effect, swirl CCW, move-> shrink.

STEP 6: Stop the process.

RESULT:

The above program has been executed successfully and the


output is verified.
Ex.No:9

OUTPUT :
DATE:10.12.2020 TEXT PORTRAIT

AIM:

To create a text portrait using GIMP.

ALGORITHM:

STEP 1: Open GIMP.

STEP 2: click open in the file menu and place the image.

STEP 3: Create the duplicate layer.

STEP 4: Select the duplicate layer. In that choose the edit option and fill with
FG color.

STEP 5: Graph the text tool. click it on the screen and change the text color as
white.

STEP 6: select the text layer and right click on it. Add layer mask with full
opacity.

STEP 7: copy the last layer and select the text layer in the small white box and
paste the layer.

STEP 8: Right click on the floating selecting layer and choose the Anchor
layer.

STEP 9: Select the text layer and choose the rectangular select tool and click
the text , goto edit and fill with FG color.
RESULT:
STEP 10: Choose levels in the colorstool and change the input levels 11, 1, 29,
213. The above program has been executed successfully and the
output is verified.
RESULT:

The above program has been executed successfully and the


output is verified.
Ex.No:10

OUTPUT :
DATE:11.12.2020 BOKEH EFFECT

AIM:

To create a bokeh effect using GIMP.

ALGORITHM:

STEP 1: Open GIMP.

STEP 2: click new in the file menu. change the FG color as Black and click the
bucket tool and fill it on the screen.

STEP 3:Click the ellipse tool and create a new layer and name it as Bokeh.
Draw the ellipse and fill it with white color.

STEP 4: create a duplicate layer in the layer menu. Click the Bokeh layer and
right click on the ellipse and choose clear in the edit option.

STEP 5: select the duplicate layer and change opacity as 50.

STEP 6: click ellipse tool and select merge down in the layer menu.

STEP 7: create a new layer and drag with ellipse tool and fill it with white
color.

STEP 8: Select alpha to selection in the transparency in the layer menu and
select shrink as 1 px.
STEP 9: create a duplicate layer in the layer menu. Click the bokeh 1 layer and
click the ellipse in the screen and right click on it and choose clear in the edit
option.

STEP 10: click the merge down in the layer menu. Click the bokeh layer .
Choose Gaussian blur in blur and change the horizontal and vertical as 40

STEP 11: click the bokeh layer and create a duplicate layer and drag the
ellipse.

STEP 12: Click the 1st duplicate layer and create the another duplicate layer
and drag the ellipse.

STEP 13: Click the 2nd duplicate layer and create the another duplicate layer
and drag the ellipse.

STEP 14: : Click the 3rd duplicate layer and create the another duplicate layer
and drag the ellipse

STEP 15: : Click the 4th duplicate layer and create the another duplicate layer
and drag the ellipse

STEP 16: click the gradient tool and go to mergedown in the layer menu upto
background layer.

STEP 17: Double click the gradient tool and fill saturation spectrum and
change the mode as overlay.

STEP 18: Using Gradient tool, drag the screen as half rectangle.
OUTPUT :

RESULT:

The above program has been executed successfully and the


output is verified.

You might also like