8/2/2019 VB.net Basicss
1/61
8/2/2019 VB.net Basicss
2/61
Why should we implementthis new software developerstool?
What language will be THEmost used language?
Is this simply anotherupgrade?
What classes couldincorporate the content of.NET?
8/2/2019 VB.net Basicss
3/61
Easier to UseModernizedMore Powerful than VB 6.0
Higher level of access to systemresources that in the past required theuse of languages like C++
True Object InheritanceGarbage Collection for better memory
management
8/2/2019 VB.net Basicss
4/61
NO!VB.NET omits quite a few forms of
syntax
VB.NET requires a total rewrite ratherthan a simple port of code
VB.NET is not dependent on older
libraries such as VBA runtime and ADO(ActiveX Database Object)
8/2/2019 VB.net Basicss
5/61
The forms engine has been replaced bythe forms engine built into .NET
This new forms engine is called
Windows Forms (or Win Forms forshort)
Win Forms add such features as docking
and opacity
8/2/2019 VB.net Basicss
6/61
In VB6, forms wereclasses, but you rarelytreated them that way
VB .NET shows the codethat instantiates the form
To show additional forms,you must first instantiatethem
8/2/2019 VB.net Basicss
7/61
C# is a new language thatwas designed to be friendlyto programmers who arealready proficient in C or
C++ Either language can be used
to write software that takesfull advantage of the CLRand .NET framework
8/2/2019 VB.net Basicss
8/61
8/2/2019 VB.net Basicss
9/61
Collapsed Regions
Collapsed
Region
Collapsed
Procedure
Class
List
Method ListTabs
8/2/2019 VB.net Basicss
10/61
There have been a number of changes in VB.NET. General changes include: Form changes
Option Strict
Event Handler changes
Default Properties
Calling Subs and Functions
Boolean operators
Using CTRL + Space to finish variables
8/2/2019 VB.net Basicss
11/61
In VB6, forms were classes, but you rarelytreated them that way
VB .NET shows the code that instantiatesthe form
To show additional forms, you must firstinstantiate them
8/2/2019 VB.net Basicss
12/61
The And and Or keywords do not short-circuit in
VB and VB .NET Both sides of an operator are evaluated, even if the first
option invalidates the statementVB .NET adds two short-circuiting Boolean
operators: AndAlso
OrElse
8/2/2019 VB.net Basicss
13/61
Dim x As Integer
x = 0
If x>2 And 5\x > 1 Then ...
This If statement is already false on thex>2 part, but 5\x is still checked becauseAnd does not short-circuit
In this case, 5\xcauses a divide by zero
error
8/2/2019 VB.net Basicss
14/61
Dim x As Integer
x = 0
If x>2 AndAlso 5\x > 1 Then ...
This If statement is already false on thex>2 part, so the AndAlso does not checkthe 5\x portion
The key result: No Error!
8/2/2019 VB.net Basicss
15/61
Firstly the Currency data type is no longerused in VB 6.0 Currency has been replaced with Decimal in
VB.NET
The Currency data type (64 bit) does notprovide sufficient accuracy to avoid roundingerrors, so Decimal (96 bit) was created as itsown data type.
Dim x As Currencyis upgraded to:Dim x As Decimal
8/2/2019 VB.net Basicss
16/61
VB 6.0 - Long variables were stored as 32-bit numbers and Integer variables as 16-bitnumbers
VB.NET - Long variables are stored as 64-bit numbers, Integer variables are storedas 32-bit numbers, and Short variables arestored as 16-bit numbers.
8/2/2019 VB.net Basicss
17/61
Variant data types are changed to Object due
to keeping all the languages more similar.
This is no longer the same as a pointer to anobject.
Dim x As Variant
is upgraded to:
Dim x As Object
8/2/2019 VB.net Basicss
18/61
In VB.BET the option is turned on bydefault for all new projects.
When Option Explicit Off is used (not agood programming style), you can use anyvariable without first declaring it.
8/2/2019 VB.net Basicss
19/61
New Option in VB.NETWhen Option Strict is turned on, the
compiler/editor does not allow implicitconversions from a wider data type to a
narrower one, or between String and numericdata types CInt and CDec convert Limits erroneous numbers or run-time errors
Place the line Option Strict On before the firstline of code
8/2/2019 VB.net Basicss
20/61
It is used to specify the type of value can beassigned for the member.
VB.NET supports two types of data types1.value type
2.Reference typeValue Type:
(a)whenever a data type is designed from structurethen it is to be Value type data type.
b)Variable information and the value will bemaintained at the stack memory.
for ex: public i as integer=10.c)value type datatypes are byte, integer, short, long,
double,decimal,boolean,char,enum etc
8/2/2019 VB.net Basicss
21/61
byte 1 byte Range0 to 255
Unsignedbyte
sbyte 1 byte Range-128 to 127 Signedbyte
Short
(sho)
2 bytes Range
-32768 to 32767
Signed
short
ushort 2 bytes Range0 to 65535
Unsignedshort
8/2/2019 VB.net Basicss
22/61
int(int)
4 bytes Range-2,147,483,647 to2,147,483,647
Signedinteger
uint 4 bytes Range0 to 4,294,967,295
Unsigned
integer
long(lng)
8 bytes Greater than900,000 trillion
Signedlong int
ulong 8 bytes Greater than 18million trillion
Unsignedlong int
8/2/2019 VB.net Basicss
23/61
single
(sng)
4
bytes
Range
A number 6 digits past thedecimal
Float
number
double(dbl)
8bytes
RangeA number 14 digits past thedecimal
Doubleprecision
decimal 8bytes
RangeA number 28 zeros long
Fixedprecision
string (str) N/A Range N/A Unicode
char 2bytes
Range0x0000 to 0xFFFF
Unicodecharacter
Bool (bln) True or False Boolean
8/2/2019 VB.net Basicss
24/61
Reference Data type:
a)whenever the data type is designed from a classdefinition then it is said to be reference type data type.
b)The variable information is maintain in the stackmemory and the value will be maintain in heapmemory.
for ex: public s string=vb.net
c)Reference type data type are string, object,interface, delegate & class.
The default modifier is private.
The default data type is an object.
8/2/2019 VB.net Basicss
25/61
Initialize a variable at declarationDim intMax As Integer = 100IDim decRate As Decimal = 0.08D
Declare multiple variables at onceDim intCount, intNum As Integer
Convert all input to correct data type(Do not use Val function)decSale = CDec(txtSale.Text)
CInt (still rounds to even #)CDecCStr
** CInt and CDec parse some characters like $,commas,()
8/2/2019 VB.net Basicss
26/61
New assignment Operators += = *= /= \= &= decTotal += decSale same as
decTotal=decTotal + decSale
8/2/2019 VB.net Basicss
27/61
String ToUpper and ToLower methods Replace UCase and LCase functions If txtInput.Text.ToUpper = YES
8/2/2019 VB.net Basicss
28/61
VB 6.0 - Arrays can be defined with lowerand upper bounds of any whole number. TheOption Base statement is used to determinethe default lower bound if a range is notspecified in the declaration.
VB.NET- To enable interoperability withother languages, all arrays must have a lowerbound of zero. This makes the Option Basestatement no longer necessary.
Dim a(1 To 10) As Stringis upgraded to:
Dim a(10) As String
8/2/2019 VB.net Basicss
29/61
This is one area that was going to change,but did not
When you declare an array, it starts at zero, and
the element number you use is the Upper Boundof the array
This means that arrays will always be one largerthan the size declared
Dim x(2) As Integer has three elements
8/2/2019 VB.net Basicss
30/61
Garbage Collection
The garbage collector periodicallychecks for unreferenced objectsand releases all memory andsystem resources used by theobjects
VBs garbage collection reclaimsobject space automatically behindthe scenes
For efficiency, VB only runs thegarbage collection feature when:
There are objects to recycle There is a need to recycle them
8/2/2019 VB.net Basicss
31/61
VB 6.0 - While statements are ended with a
WEND statement.
VB.NET - WEND statements are changed to
End While. This improves language
consistency and readability.
While
End While
8/2/2019 VB.net Basicss
32/61
Arrays in VB.NET are classes supportingproperties and methods, making themquite flexible. .Sort
.Reverse
You can sort an array in one line of code!
8/2/2019 VB.net Basicss
33/61
VB 6.0 - Parameters that do not specifyeither ByVal or ByRef default to ByRef
VB.NET - Parameters that do not specify
either ByVal or ByRef default to ByVal.Defaulting to ByVal rather than ByRefeliminates the problem of having aprocedure mistakenly modify a variable
passed in by the caller.
8/2/2019 VB.net Basicss
34/61
VB 6.0 - The GoSub line ... Returnstatement branches to and returns from asubroutine within a procedure.
VB.NET - GoSub...Return is anonstructured programming construct. Itsuse makes programs harder to read andunderstand. Creating separate proceduresthat you can call may provide a morestructured alternative or use casestatements.
8/2/2019 VB.net Basicss
35/61
User Defined Types (UDTs) have beenreplaced with Structures
Structures are far more powerful than
UDTs They support the equivalent of properties and
methods
They are not as powerful as classes
8/2/2019 VB.net Basicss
36/61
VB .NET supports such built-in functionsas FileOpen and Write These functions are found in the
Microsoft.VisualBasic namespaceVB6 code that is upgraded to VB .NET will
use these functionsThe Framework includes a rich namespace
called System.IO
8/2/2019 VB.net Basicss
37/61
System.IO contains a large number ofclasses for handling all types of I/O
There are a variety of major categories of
objects in System.IO These include objects to manage files and
directories, read and write text files, and read andwrite binary streams
8/2/2019 VB.net Basicss
38/61
FileInfo and DirectoryInfo classes
are for such operations as creating,moving, and deleting files and directories
If you use the Open method ofFileInfoto open a file, the returned object is aFileStream
8/2/2019 VB.net Basicss
39/61
The StreamReader and StreamWriter
classes are common ways to perform fileI/O This can read binary and text data
The StringReader and StringWriter aredesigned to read text data
8/2/2019 VB.net Basicss
40/61
VB .NET now supports StructuredException Handling (SEH)On Error Goto is still supported
SEH uses the TryCatchFinallysyntax
Should help reduce spaghetti code
8/2/2019 VB.net Basicss
41/61
Overloading is the ability to have the samemethod, but with different arguments You could fake this in VB6 using ParamArrays
For example, a FindCustomer methodcould accept a customer ID, a customername, or a contact name
8/2/2019 VB.net Basicss
42/61
Finalize will run when the object is cleanedup by the GC
You might want to release resources
explicitly, since you cannot determinewhen Finalize will be called
Use the Dispose design pattern to explicitly
free resources
8/2/2019 VB.net Basicss
43/61
VB .NET allows you to create trulymultithreaded (or free threaded)applications
The Framework includes aSystem.Threading namespace to makeworking with threads easier
You will learn more in Chapter 11,
Multithreaded Applications
8/2/2019 VB.net Basicss
44/61
8/2/2019 VB.net Basicss
45/61
E.g.Module Module
Enum DaysSunday=1Monday=2Tuesday=3
Wednesday=4End Enum
Sub Main()System.Console.WriteLine(Monday is day & Days.Monday)
End SubEnd Module
8/2/2019 VB.net Basicss
46/61
It is used to initialize the members of the class.VB.net supports two types of constructors
1)Instance constructor2)shared constructor
1)Instance constructor:It is used to initialize the instance and shared
members of the class.Syntax:[modifier]Sub new([arginfo])statement(s)....End sub
8/2/2019 VB.net Basicss
47/61
Constructors are blocks of code that runwhen a class is instantiated
Destructors are blocks of code that run
when a class drops out of memoryConstructors can be overloaded to make
them more powerfulDue to garbage collection, you cannot be
assured of when destructors will execute
8/2/2019 VB.net Basicss
48/61
2)Shared members:
It is used to initialize the shared members ofthe class.
syntax:shared sub new()
statements
.
.
end sub
shared constructor will be invoked only once when
the class is definition is loaded
8/2/2019 VB.net Basicss
49/61
Data abstraction or Datahiding:It is used to provide or hide the relavent
information from the user(modifiers are used).
Data encapsulation or Data binding:
it is used to identify the relavent informationand group the together(class or structure should beused)
Polymorphism(many forms):
whenever an entity can change its definitionbased on the arguments values supplied for that entitythen it is said to be supporting.
8/2/2019 VB.net Basicss
50/61
Inheritance:
It is used to reuse or to redefine the exiting classdefinition.
Properties:
It is used to set or get the values from the privateor protected members of the class.
In order to define Readonlyproperty then get
block should be used with Readonly keyword. In oreder to define Writeonlyproperty then setblock should be used with writeonly keyword.
8/2/2019 VB.net Basicss
51/61
Public Class Customer
Private m_CustName As String
Public Property CustomerName() As String
Get
CustomerName = m_CustName
End Get
Setm_CustName = Value
End Set
End Property
End Class
Public Class CustCompany
Inherits Customer
Private m_CustCompany As String
Public Property CustomerCompany() As String
Get
CustomerCompany = m_CustCompany
End Get
Set
m_CustCompany = Value
End Set
End Property
End Class
8/2/2019 VB.net Basicss
52/61
It is used to modularize the flow of theapplication.
Advantage:
Easy DebuggingReusabilityPerformance
VB .NET supports two types of methods:1)Procedures or Sub routines2)Functions
8/2/2019 VB.net Basicss
53/61
8/2/2019 VB.net Basicss
54/61
8/2/2019 VB.net Basicss
55/61
8/2/2019 VB.net Basicss
56/61
Event:These are the actions that are allowed on a control
or an object.
Event Handlers:These are the methods which provide thefunctionality or the task to be executed when ever anevent has been raised on a control.
VB supports two types of Event Handlers:Static event handlers
Dynamic event handlers
8/2/2019 VB.net Basicss
57/61
Static Event Handlers:
whenever an event handler is defined for theobject of controls created at the design time then it is
said to be static event handler.
Dynamic Event Handlers:
whenever an event handler is defined for the
controls that are created at the runtime then it is saidto be Dynamic event handler.
8/2/2019 VB.net Basicss
58/61
8/2/2019 VB.net Basicss
59/61
8/2/2019 VB.net Basicss
60/61
Text box:It is used to accept the singleline, multiline or
password characters as the input.
Properties:
Multiline
Scrollbars
Passwordchar
Button control
Trackbar control
Save file dialog control
Open file dialog control
8/2/2019 VB.net Basicss
61/61
It is used to provide the browsing capabilities to thewindows form.
1)GroupBox control:
It is used to logically group the controls together.
2)Timer control:It is used to set of instructions repeatedly for every
specific interval of time.
3)ImageList control:
It is used to maintain a collection of images which canbe used by any control that has a capability to project theimage.
4)Picturebox control:
It is used to project an image