Вы находитесь на странице: 1из 61

Why

should we implement this new software developers tool? What language will be THE most used language? Is this simply another upgrade? What classes could incorporate the content of .NET?

Easier

to Use Modernized More Powerful than VB 6.0 Higher level of access to system resources that in the past required the use of languages like C++ True Object Inheritance Garbage Collection for better memory management

NO!

VB.NET

omits quite a few forms of

syntax VB.NET requires a total rewrite rather than a simple port of code VB.NET is not dependent on older libraries such as VBA runtime and ADO (ActiveX Database Object)

The

forms engine has been replaced by the forms engine built into .NET This new forms engine is called Windows Forms (or Win Forms for short) Win Forms add such features as docking and opacity

In VB6, forms were classes, but you rarely treated them that way VB .NET shows the code that instantiates the form To show additional forms, you must first instantiate them

C# is a new language that was designed to be friendly to programmers who are already proficient in C or C++ Either language can be used to write software that takes full advantage of the CLR and .NET framework

Collapsed Regions
Tabs Method List Class List

Collapsed Region Collapsed Procedure

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

In

VB6, forms were classes, but you rarely treated them that way VB .NET shows the code that instantiates the form To show additional forms, you must first instantiate them

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 statement


VB

.NET adds two short-circuiting Boolean operators:


AndAlso OrElse

This

If statement is already false on the x>2 part, but 5\x is still checked because And does not short-circuit In this case, 5\x causes a divide by zero error

Dim x As Integer x = 0 If x>2 And 5\x > 1 Then ...

Dim x As Integer x = 0 If x>2 AndAlso 5\x > 1 Then ...


This

If statement is already false on the x>2 part, so the AndAlso does not check the 5\x portion The key result: No Error!

Firstly

the Currency data type is no longer used in VB 6.0 Currency has been replaced with Decimal in VB.NET The Currency data type (64 bit) does not provide sufficient accuracy to avoid rounding errors, so Decimal (96 bit) was created as its own data type. Dim x As Currency is upgraded to: Dim x As Decimal

VB

6.0 - Long variables were stored as 32bit numbers and Integer variables as 16-bit numbers VB.NET - Long variables are stored as 64bit numbers, Integer variables are stored as 32-bit numbers, and Short variables are stored as 16-bit numbers.

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 an

object.
Dim

x As Variant

is upgraded to: Dim x As Object

In

VB.BET the option is turned on by default for all new projects. When Option Explicit Off is used (not a good programming style), you can use any variable without first declaring it.

New

Option in VB.NET When Option Strict is turned on, the compiler/editor does not allow implicit conversions from a wider data type to a narrower one, or between String and numeric data types CInt and CDec convert Limits erroneous numbers or run-time errors
Place

the line Option Strict On before the first line of code

It is used to specify the type of value can be assigned for the member. VB.NET supports two types of data types 1.value type 2.Reference type Value Type: (a)whenever a data type is designed from structure then it is to be Value type data type. b)Variable information and the value will be maintained 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

byte sbyte Short (sho) ushort

1 byte 1 byte

Range 0 to 255 Range -128 to 127

Unsigned byte Signed byte Signed short Unsigned short

2 bytes Range -32768 to 32767 2 bytes Range 0 to 65535

int (int)

4 bytes

Range
-2,147,483,647 to 2,147,483,647

Signed integer

uint long (lng)


ulong

4 bytes 8 bytes
8 bytes

Range
0 to 4,294,967,295

Unsigned integer

Greater than Signed 900,000 trillion long int


Greater than 18 million trillion Unsigned long int

single (sng) double (dbl) decimal

4 bytes 8 bytes

Range
A number 6 digits past the decimal

Float number

Double A number 14 digits past the precision

Range
decimal

8 bytes string (str) N/A char 2 bytes Bool (bln)

Range
A number 28 zeros long

Fixed precision Unicode Unicode character Boolean

Range N/A Range


0x0000 to 0xFFFF

True or False

Reference Data type: a)whenever the data type is designed from a class definition then it is said to be reference type data type. b)The variable information is maintain in the stack memory and the value will be maintain in heap memory. 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.

Initialize

a variable at declaration Dim intMax As Integer = 100I Dim decRate As Decimal = 0.08D Declare multiple variables at once Dim 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 #) CDec CStr

** CInt and CDec parse some characters like $, commas,()

New

assignment Operators += = *= /= \= &= decTotal += decSale same as decTotal=decTotal + decSale

String

ToUpper and ToLower methods Replace UCase and LCase functions


If txtInput.Text.ToUpper = YES

VB

6.0 - Arrays can be defined with lower and upper bounds of any whole number. The Option Base statement is used to determine the default lower bound if a range is not specified in the declaration. VB.NET- To enable interoperability with other languages, all arrays must have a lower bound of zero. This makes the Option Base statement no longer necessary. Dim a(1 To 10) As String is upgraded to: Dim a(10) As String

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 Bound of the array This means that arrays will always be one larger than the size declared Dim x(2) As Integer has three elements

Garbage Collection

The garbage collector periodically checks for unreferenced objects and releases all memory and system resources used by the objects VBs garbage collection reclaims object space automatically behind the scenes For efficiency, VB only runs the garbage collection feature when:
There are objects to recycle There is a need to recycle them

VB

6.0 - While statements are ended with a - WEND statements are changed to

WEND statement.
VB.NET

End While. This improves language consistency and readability.


While

End While

Arrays

in VB.NET are classes supporting properties and methods, making them quite flexible.
.Sort .Reverse

You

can sort an array in one line of code!

VB

6.0 - Parameters that do not specify either 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 ByRef eliminates the problem of having a procedure mistakenly modify a variable passed in by the caller.

VB

6.0 - The GoSub line ... Return statement branches to and returns from a subroutine within a procedure. VB.NET - GoSub...Return is a nonstructured programming construct. Its use makes programs harder to read and understand. Creating separate procedures that you can call may provide a more structured alternative or use case statements.

User

Defined Types (UDTs) have been replaced with Structures Structures are far more powerful than UDTs
They support the equivalent of properties and

methods They are not as powerful as classes

VB

.NET supports such built-in functions as FileOpen and Write


These functions are found in the

VB6

code that is upgraded to VB .NET will use these functions The Framework includes a rich namespace called System.IO

Microsoft.VisualBasic namespace

System.IO

contains a large number of classes 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 and write binary streams

and DirectoryInfo classes are for such operations as creating, moving, and deleting files and directories If you use the Open method of FileInfo to open a file, the returned object is a FileStream
FileInfo

The

StreamReader and StreamWriter classes are common ways to perform file I/O
This can read binary and text data

The

StringReader and StringWriter are designed to read text data

VB

.NET now supports Structured Exception Handling (SEH)


On Error Goto is still supported

SEH

uses the TryCatchFinally syntax Should help reduce spaghetti code

Overloading

is the ability to have the same method, but with different arguments
You could fake this in VB6 using ParamArrays

For

example, a FindCustomer method could accept a customer ID, a customer name, or a contact name

Finalize

will run when the object is cleaned up by the GC You might want to release resources explicitly, since you cannot determine when Finalize will be called Use the Dispose design pattern to explicitly free resources

VB

.NET allows you to create truly multithreaded (or free threaded) applications The Framework includes a System.Threading namespace to make working with threads easier You will learn more in Chapter 11, Multithreaded Applications

E.g. Module Module Enum Days Sunday=1 Monday=2 Tuesday=3 Wednesday=4 End Enum

Sub Main() System.Console.WriteLine(Monday is day & Days.Monday) End Sub End Module

It is used to initialize the members of the class. VB.net supports two types of constructors 1)Instance constructor 2)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

Constructors

are blocks of code that run when a class is instantiated Destructors are blocks of code that run when a class drops out of memory Constructors can be overloaded to make them more powerful Due to garbage collection, you cannot be assured of when destructors will execute

2)Shared members: It is used to initialize the shared members of the class. syntax: shared sub new() statements . . end sub shared constructor will be invoked only once when the class is definition is loaded

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 information and group the together(class or structure should be used) Polymorphism(many forms): whenever an entity can change its definition based on the arguments values supplied for that entity then it is said to be supporting.

Inheritance: It is used to reuse or to redefine the exiting class definition. Properties: It is used to set or get the values from the private or protected members of the class. In order to define Readonly property then get block should be used with Readonly keyword. In oreder to define Writeonly property then set block should be used with writeonly keyword.

Public Class Customer Private m_CustName As String Public Property CustomerName() As String Get CustomerName = m_CustName End Get Set m_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

It is used to modularize the flow of the application.

Advantage:
Easy Debugging Reusability Performance

VB .NET supports two types of methods:


1)Procedures or Sub routines 2)Functions

It is a set of instructions which are used to perform a specific action on task.

syntax:
[modifier]Sub MethodName([arginfo]) statement(s) End sub

It is set of instruction which is used to perform calculations, expressions, calculating and used to return a value Syntax of Functions: [modifier]function MethodName([argInfo]) as Datatype statement(s) . Return<return value> End function

It is a collection of members without any definition Syntax: Interface<InterfaceName> member(s) without definition ....... End interface

Event: These are the actions that are allowed on a control or an object. Event Handlers: These are the methods which provide the functionality or the task to be executed when ever an event has been raised on a control. VB supports two types of Event Handlers: Static event handlers Dynamic event handlers

Static Event Handlers: whenever an event handler is defined for the object 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 said to be Dynamic event handler.

It is used for developing an application for the desktops with effective user interface. whenever a class inherits System.windows.Forms.Form class then it is said to be an windows form. Understanding vs.net IDE for Windows Development:

ToolBox(ctrl+Alt+x):
It is used to set or get the value from the private or protected members of the class.

Properties window(F4):
It is used to set or get or set the value from the private or protected members of the class.

Solution Explorer(Alt+ctrl+l):
It maintains all the files that are used with in the application.

Form:
it.

Its acts like a canvas where other controls can be drawn

Label control:
It is used to provide any starting information on the form.

Name:
Text:
Used to specify an unique identifier for the control

It is used to set or get value from the control

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

It is used to provide the browsing capabilities to the windows 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 can be used by any control that has a capability to project the image. 4)Picturebox control: It is used to project an image

Вам также может понравиться