FEDT VB.
NET
FRONT END DESIGN TOOL
USING
VB .NET
UNIT - 2
PRESENTATION BY:
ANKIT VERMA
(IT DEPARTMENT)
ANKIT VERMA ASS T. PROFESSOR
.NET IDE
28-11-2014 ANKIT VERMA 2
Elements Of IDE
Windows Form Designer
Add control to form, arrange them & add code.
Properties Window
Lists properties associated with control.
Solution Explorer
Display solution name, project name, form name, fields etc.
Tool Box
Provide controls like form, data, components, toolbar, menu etc.
Object Browser
Shows the members of object
28-11-2014 ANKIT VERMA 3
Elements Of IDE
Task List Window
List of errors in source code.
Server Explorer
Database connectivity, display tables, views, connections etc.
Dynamic Help
Context sensitive help.
Class View
Display Classes , methods, properties etc.
Code & Text Editor Window
Allow to enter and edit code
28-11-2014 ANKIT VERMA 4
STEPS OF WRITING
APPLICATION IN .NET
28-11-2014 ANKIT VERMA 5
Steps Of Writing Application In .NET
Start Visual Studio 2010
28-11-2014 ANKIT VERMA 6
Steps Of Writing Application In .NET
File New Project Select Language VB.NET
Choose Console or Window Application
Provide
Project Name
28-11-2014 ANKIT VERMA 7
Steps Of Writing Application In .NET
28-11-2014 ANKIT VERMA 8
Steps Of Writing Application In .NET
28-11-2014 ANKIT VERMA 9
Steps Of Writing Application In .NET
Write Code of program to be made.
Save Code by click File Save All
Press F5 & Run
28-11-2014 ANKIT VERMA 10
PROJECT TEMPLATE
28-11-2014 ANKIT VERMA 11
Project Templates
Window Application
Create application with window interface.
Class Library
Create classes to use in other application.
Console Application
Create command line application.
Window Control Library
Create control for applications.
Empty Project
Creating local application.
28-11-2014 ANKIT VERMA 12
Project Templates
Window Service
Create window service.
28-11-2014 ANKIT VERMA 13
VB Terms
Design Time
Environment where application being developed.
Run Time
Execution of application.
Forms
Basic element for creating user interface for application.
Controls
Manipulate information.
Properties
Control characteristics like color, caption, size etc.
28-11-2014 ANKIT VERMA 14
VB Terms
Methods
Actions that can be performed by object
Events
Action recognized by form or control.
Generated by user, OS or application.
28-11-2014 ANKIT VERMA 15
FEATURES OF VB.NET
28-11-2014 ANKIT VERMA 16
Features Of VB.NET
Simple
Consistency
Garbage Collection
Object Orientation
Type Safety
Thread Support
Structured Exceptional Handling
Powerful, Flexible, Simplified Data Access
COM Interoperability
28-11-2014 ANKIT VERMA 17
VB vs VB.NET
28-11-2014 ANKIT VERMA 18
Similarities Between VB & VB.NET
Both Are Not Case Sensitive.
Both Support Windows & Web Based Application.
Both Are Provided With IntelliSense Feature.
28-11-2014 ANKIT VERMA 19
Difference Between VB & VB.NET
VB .NET VB
Object Oriented Object Based
Data Type Declaration Required Not Strongly Typed
Structured Exception Handling Not Structured
Namespace To Organize Classes Not Supported
Automatic Garbage Collection Not Supported
ADO .NET For DB Connectivity DAO, RDO & ADO
Multithreading Not Supported
Console Applications Are Allowed Not Allowed
New Data Type Like Char, Short & Decimal Not Supported
Variable Can Declare In Same Line Not Allowed
Dim a As Integer = 10
Object Data Type Variant Data Type
28-11-2014 ANKIT VERMA 20
Difference Between VB & VB.NET
VB .NET VB
Fixed Length String Not Allowed Allowed
Array Index Start With O Only Array Index Can Be Changed
Set Keyword Not Supported Set Keyword Used To Assign Object
Variables
Passing By Value Is Default For Calling Pass By Reference
Procedure
Default Properties Of Controls Not Allowed
Allowed
Return Keyword Used To Return Values name = return value Is Used
Optional Argument Must Be Specified Not Necessary
With Default Value
28-11-2014 ANKIT VERMA 21
DATA TYPE
28-11-2014 ANKIT VERMA 22
Data Types Supported In VB.NET
Number Data Types Character Data Type
Byte Char
Short String
Integer
Long
Single Other Data Type
Double
Boolean
Decimal
Date
User Defined Data Type
e.g. Structure
28-11-2014 ANKIT VERMA 23
VARIABLES
28-11-2014 ANKIT VERMA 24
Variables
These Are Area In Memory Referred By Name Or
Identifier During Program Execution.
Dim a As Integer = 10
Dim b As Double = 14.01
Multiple Declaration Is Allowed.
Dim x , y As Integer
Constant
Value not change during execution of code.
Const a = 45
Identifier
Building block of programming language.
28-11-2014 ANKIT VERMA 25
Scope Of Variables
Block Scope
If block
Procedure Scope
Function
Module
Class variable accessed by all functions
Namespace Scope
Inside namespace
Shadowing
Same variable name in two procedures.
Scope only in module & accessed as FunctionName.Variable
28-11-2014 ANKIT VERMA 26
Access Control
Public
Private
Protected
Friend
Protected Friend
28-11-2014 ANKIT VERMA 27
OPERATORS
28-11-2014 ANKIT VERMA 28
Arithmetic Operator
OPRATOR OPERATION
+ Addition
- Subtraction
* Multiplication
/ Float Division
\ Integer Division
^ Exponentiation
Mod Remainder
28-11-2014 ANKIT VERMA 29
Comparison Operator
OPRATOR OPERATION
< Less Than
> Greater Than
= Equality Checking
<> Not Equal To
28-11-2014 ANKIT VERMA 30
Assignment Operator
OPRATOR OPERATION
= Assignment
+= Addition With Assignment
-= Subtraction With Assignment
*= Multiplication With Assignment
/= Floating Division With Assignment
\= Integer Division With Assignment
^= Exponentiation With Assignment
<= Less Than Equal To
>= Greater Than Equal To
28-11-2014 ANKIT VERMA 31
Logical Operator
OPRATOR OPERATION
AND Return True, If Both Operands True
OR Return True, If One or Both Operands True
NOT Return True, If Reverse Logical Value Of Operand
XOR Return False, If Both Operands Either True Or False
28-11-2014 ANKIT VERMA 32
CONTROL STRUCTURE
28-11-2014 ANKIT VERMA 33
Control Structure
Program Executes The Statement One After Other.
Control Structure Change The Flow OF Execution Of
These Statements.
Control Structure Are Classified Into Three Groups:
1) Decision Making / Conditional Statements
2) Looping
3) Other Statements
28-11-2014 ANKIT VERMA 34
1) Decision Making /
Conditional Statements
28-11-2014 ANKIT VERMA 35
1) Decision Making / Conditional Statements
According To Value Of Variable, Control Flow Can Be
Changed For The Execution.
Two Statements Of This Category:
If – Else
Select Case
28-11-2014 ANKIT VERMA 36
1) Decision Making : If - Else
Syntax:
If <condition> Then
[statement]
ElseIf <condition> Then
[statement]
Else
[statement]
EndIf
28-11-2014 ANKIT VERMA 37
1) Decision Making : If - Else
Example 1:
28-11-2014 ANKIT VERMA 38
1) Decision Making : If - Else
Example 2:
28-11-2014 ANKIT VERMA 39
1) Decision Making : Select Case
Syntax:
Select Case <expression>
Case Value
[statement]
Case Value
[statement]
Case Else
[statement]
End Select
28-11-2014 ANKIT VERMA 40
1) Decision Making : Select Case
Example:
28-11-2014 ANKIT VERMA 41
2) Looping
28-11-2014 ANKIT VERMA 42
2) Looping
Execute Statements Repeatedly & Quickly.
Three Statements Of This Category:
Do Loop
While Loop
For Loop
28-11-2014 ANKIT VERMA 43
2) Looping : Do Loop
Syntax:
Do While <condition>
[statement]
Loop
(OR)
Do Until <condition>
[statement]
Loop
NOTE: Do Until loop executes only if statement is False.
28-11-2014 ANKIT VERMA 44
2) Looping : Do Loop
Example (Do While):
28-11-2014 ANKIT VERMA 45
2) Looping : Do Loop
Example (Do Until):
28-11-2014 ANKIT VERMA 46
2) Looping : While
Syntax:
While <condition>
[statement]
End While
28-11-2014 ANKIT VERMA 47
2) Looping : While
Example:
28-11-2014 ANKIT VERMA 48
2) Looping : For
Syntax:
For index = start To end Step 1
[statement]
Next
28-11-2014 ANKIT VERMA 49
2) Looping : For
Example:
28-11-2014 ANKIT VERMA 50
3) Other Statements
28-11-2014 ANKIT VERMA 51
3) Other Statements
Exit
Used to exit from loop
GOTO
Transfer the control to specified label
Stop
Return the program into break mode
End
Terminate the program
Return
Used in function to return the value to the calling method
28-11-2014 ANKIT VERMA 52
3) Other Statement : GoTo , Exit
Example:
28-11-2014 ANKIT VERMA 53
3) Other Statement : Stop, End
Example:
28-11-2014 ANKIT VERMA 54
DATA STRUCTURE
28-11-2014 ANKIT VERMA 55
Data Structure In VB .NET
DS is a way of storing & organizing data in computer,
so that it can be used efficiently.
Different kind of DS are suited for different kind of
applications.
Some DS are highly specialized for specific tasks.
Various DS Are:
Array
Array Lists
Enumeration
28-11-2014 ANKIT VERMA 56
1) Array
28-11-2014 ANKIT VERMA 57
1) Array
Array can hold collection of values of same type.
Element
Variable in an array is called Element.
Array has name & its elements can be accessed by
Index or Subscript.
Array can be single, double or multi dimension.
Lower Bound (LB) of all dimension array start with O.
Array is reference type.
Types of Array:
Static Array
Dynamic Array
28-11-2014 ANKIT VERMA 58
1) Array : Static Array
Size of Static Array remain same even at runtime.
If Array is declared as Object type, we can store
different types of Data Type.
Syntax:
Dim a(5) As Integer
Dim b(3,5) As String
Dim c( ) As Single = {10.1 , 24.7}
Dim d(3) As Object
28-11-2014 ANKIT VERMA 59
1) Array : Static Array
Example:
28-11-2014 ANKIT VERMA 60
1) Array : Dynamic Array
Size of Dynamic Array changes during execution.
Used when you don’t know the size of Array.
Size of Array not provided during declaration.
Redim
After declaration no one change the data type .
Preserve
Preserve data without losing when dimension of array change.
28-11-2014 ANKIT VERMA 61
1) Array : Dynamic Array
Syntax:
Dim a( ) As String
Redim a(5)
Dim b( , ) As Integer
Redim b(3,2)
ReDim Preserve b(3,4)
28-11-2014 ANKIT VERMA 62
1) Array : Dynamic Array
Example:
Value Not Lost After
Dimension Change
Because Of Preserve
28-11-2014 ANKIT VERMA 63
1) Array : Functions Of Array
Ubound (arrayname)
Determine upper bound of array.
Lbound (arrayname)
Determine lower bound of array.
28-11-2014 ANKIT VERMA 64
2) Array Lists
28-11-2014 ANKIT VERMA 65
2) Array Lists
Flexible Data Structure.
List can Grow & Shrink dynamically.
Contain list of values, on which we can perform
operations like Add, Delete etc.
28-11-2014 ANKIT VERMA 66
2) Array Lists : Properties & Functions
Add
Add an item.
Insert
Insert an item at specified position.
Remove
Remove an item.
RemoveAt
Remove an item from specified position.
Sort
Sort items.
Count
Count the number of elements.
28-11-2014 ANKIT VERMA 67
2) Array Lists
Example 1:
28-11-2014 ANKIT VERMA 68
2) Array Lists
Example 2:
28-11-2014 ANKIT VERMA 69
2) Array Lists
Example 2 (Output):
28-11-2014 ANKIT VERMA 70
3) Enumerations
28-11-2014 ANKIT VERMA 71
3) Enumerations
Enumeration is set of related constants that define a
value type, where each constant is known as member
of Enumeration.
Work for many constant of same type.
It set object properties & specify values that are passed
to methods.
Syntax:
[access modifier] Enum name
<Member List>
End Enum
28-11-2014 ANKIT VERMA 72
3) Enumerations
Example:
28-11-2014 ANKIT VERMA 73
PREDEFINED FUNCTIONS
28-11-2014 ANKIT VERMA 74
1) MsgBox Function
28-11-2014 ANKIT VERMA 75
1) MsgBox Function
Produce pop-up message box.
Prompt user to click on command button before he
can continues.
This function return the result values.
28-11-2014 ANKIT VERMA 76
1) MsgBox Function
Msg=MsgBox(Prompt, Style Value, Title)
Prompt
It is message of 1024 (approx.) characters , be displayed to user.
Style
Denote the style & type of buttons to display in message box.
Values
MsgBoxStyle.YesNoCancel
MsgBoxStyle.YesNo
MsgBoxStyle.OkOnly (Default)
MsgBoxStyle.OkCancel
MsgBoxStyle.Exclamation
Title denotes the string displayed in title bar.
28-11-2014 ANKIT VERMA 77
1) MsgBox Function
Result Values Can Be
MsgboxResult.ok
MsgboxResult.cancel
MsgboxResult.abort
MsgboxResult.retry
MsgboxResult.ignore
MsgboxResult.yes
MsgboxResult.no
28-11-2014 ANKIT VERMA 78
1) MsgBox Function
Example:
28-11-2014 ANKIT VERMA 79
2) InputBox Function
28-11-2014 ANKIT VERMA 80
2) InputBox Function
InputBox () function will display a message box where user
enter value or text.
Return value of function is string type.
Msg=InputBox(Prompt, Title, default_text, x-position,y-position)
Prompt
String expression displayed in dialog box.
Title
String expression displayed in title bar.
Default Text
Default response when user not provide input.
X, Y Position
Indicate the appearance if input box in screen.
28-11-2014 ANKIT VERMA 81
2) InputBox Function
Syntax:
28-11-2014 ANKIT VERMA 82
3) Other Function
28-11-2014 ANKIT VERMA 83
3) Other Function
FUNCTION USE
Strcomp Comparison for two strings
Lcase Convert String into Lower case
Ucase Convert String into Upper case
Rtrim Remove trailing spaces
Ltrim Remove leading spaces
Trim Remove both leading & trailing spaces
Mid Return specific number of character
Asc Return ASCII code of first letter in a string
Chr Return character of given ASCII code
Now Return current system date time
28-11-2014 ANKIT VERMA 84
COMMENTS
28-11-2014 ANKIT VERMA 85
Comments
Comments are explanatory notes included in program
code following a single quotation mark (‘).
Single Line Comment
Provide single quotation mark (‘) before line.
Multiple Line Comment
Select multiple lines, whom you want to make comment.
Click Menu Edit Advance Comment Selection
or
Press Ctrl +K, Ctrl +C
28-11-2014 ANKIT VERMA 86
PROCEDURES & FUNCTIONS
28-11-2014 ANKIT VERMA 87
Procedures & Functions
They are group of related commands that perform
certain tasks and also called subprogram.
Used for repeated task.
Modular & easy to maintain.
Easy to debug
Any changes to code, you have to make changes only in
procedures, not every place of code.
Subprograms can be invoked from calling block.
Control transfer to procedure & after execution, return
back to calling procedure.
28-11-2014 ANKIT VERMA 88
Procedures & Functions
Argument which is passed can be variable, constant or
expression.
You can write the procedure in module, class module
and form module.
Procedure of class module support OOP concept.
There are four types of procedure:
Sub Procedure
Function Procedure
Event Procedure
Invoked according to action associated with controls.
Property Procedure
28-11-2014 ANKIT VERMA 89
1) Sub Procedure
28-11-2014 ANKIT VERMA 90
1) Sub Procedure
Sub Procedure can not return value.
Parentheses are not optional in VB .NET
Even no parameters still procedure enclosed using
empty parentheses.
For calling, procedure name followed by parameters.
Syntax:
[Access Specifier] sub Name (Arg As DataType, …)
<Statement>
End Sub
28-11-2014 ANKIT VERMA 91
1) Sub Procedure
Example:
28-11-2014 ANKIT VERMA 92
1) Sub Procedure
Example:
28-11-2014 ANKIT VERMA 93
2) Function Procedure
28-11-2014 ANKIT VERMA 94
2) Function Procedure
Return a value back to calling program.
Function can return values in two ways:
Using Return statement
Assign value to function name, like VB
If return data type is not mentioned, Object type will
be default one.
Function can also called same as procedure.
Syntax:
[Access Specifier] Function Name (Arg As DataType, …) [As DataType]
<Statement>
End Sub
28-11-2014 ANKIT VERMA 95
2) Function Procedure
Example:
28-11-2014 ANKIT VERMA 96
3) Event Procedure
28-11-2014 ANKIT VERMA 97
3) Event Procedure
Events are actions associate with object.
Foam Load
Button Click
Mouse Click
Events can be raised by user action, by system or by
code itself.
User can write code to handle events, called event
handling procedures.
By these procedures, we can call the sub or function
procedures, called implicitly.
28-11-2014 ANKIT VERMA 98
PARAMETER PASSING
28-11-2014 ANKIT VERMA 99
Passing Parameter
Code in a procedure needs some information about the
state of the program to do the job.
These are passed to procedures as arguments.
There are two ways:
Pass By Value
Pass By Reference
28-11-2014 ANKIT VERMA 100
1) Pass By Value
Default mode of passing arguments.
Copy of argument is passed to the procedure.
Any change in value never affect the original variable,
but only affect the copy.
ByVal keyword is used explicitly, otherwise compiler
automatically inserts this keyword.
Syntax:
Public Sub disp (ByVal a As Integer)
<statements>
End Sub
28-11-2014 ANKIT VERMA 101
2) Pass By Reference
Address of argument is passed to procedure.
Procedure can change its value permanently.
Procedure have full access to argument.
ByRef keyword is used.
Syntax:
Public Sub disp (ByRef a As Integer)
<statements>
End Sub
28-11-2014 ANKIT VERMA 102
3) Optional Argument
Optional argument is passed to provide some optional
argument with default value.
If we not pass value of argument, default value will be
substituted.
28-11-2014 ANKIT VERMA 103
4) Named Argument
Argument data type can’t be changed when we pass the
arguments to procedure.
Using Named Argument, we can pass the value by
providing Argument Name followed by colon, an equal
sign and argument value.
Arguments can be passed in any order.
28-11-2014 ANKIT VERMA 104
CREATING & USING
NAMESPACE
28-11-2014 ANKIT VERMA 105
Creating & Using Namespace
Namespace allows you to create your own namespaces
for holding classes.
By default classes are created in root namespace that is
based on your project name.
Syntax:
Namespace <namespace name>
Class <class name>
Members
End Class
End Namespace
28-11-2014 ANKIT VERMA 106
Creating & Using Namespace
Creating:
Using
28-11-2014 ANKIT VERMA 107
THANKYOU
DOUBTS
PRESENTATION BY:
ANKIT VERMA
(IT DEPARTMENT)
ANKIT VERMA ASS T. PROFESSOR