MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

Embed Size (px)

Citation preview

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    1/33

    Introduction to VB.NET

    MELJUN CORTESMELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    2/33

    Agenda

    Why VB.NET

    What is new in VB.NET

    Update to VB.NET?

    VB.NET Language Essential

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    3/33

    Why VB.NET (from technicalstandpoint)

    The world of applications is changing:The move to Web

    The need for reusability, centralizationand scalabilityMTS, COM+, and Component Servicescannot be fully taken advantage of byVB.SOAP: features can be implementedmore completely with .NET.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    4/33

    Why VB.NET (cont.)

    To get the benefit of .NETframework and its core execution

    engine: CLR.Garbage collection

    OO mechanism

    Standard security servicesIntegrated debugging tools

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    5/33

    Why VB.NET (cont.)

    Why not C#VB.NET----The most productive tool for

    building .NET-connected applications. ----Microsoft Corporation

    Root in Basic, the most pure-flavor languageproduct from MS.

    Easier for VB programmers: a number of uniquefeatures.

    E.g.: Only VB.NET has background compilation,dropdown list of the code window.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    6/33

    What is New in VB.NET ----ForExperienced VB Programmers

    IDE changesProject ChangesWeb Changes

    WebClass ChangesData ChangesComponent Authoring ChangesUserControl ChangesForms ChangesDebugging ChangesSetup and Deployment ChangesInternational ChangesWindows API ChangesRegistry Access ChangesConstant Changes

    Namespace ChangesRun-Time Chan es MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    7/33

    Overview of Big Changes inVB.Net

    Everything is object-oriented: abstraction,inheritance, overloading, encapsulation and

    polymorphism.(Note: no multipleinheritance, but interfaces supported.)

    Multithreaded applications are possible.

    Language syntax changes

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    8/33

    Changes in VB Language

    All data are objects, based on the class:System.Object.

    E.g. class supports Windows forms:System.Windows.Forms.Form.

    The built-in VB functionality isencapsulated in a namespace called System.

    E.g Collectionhas be replaced bySystem.Collections.

    Old control are gone, and new ones haveappeared.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    9/33

    Changes in VB Language (cont.)

    Many keywords are renamed or gone, whilesome new added.

    E.g. GosubremovedStrict data typing is now enforcedVariable must be declared before used bydefault.

    Cannot assign one data type to another, but canuse Ctypeto convert between types.The same as in VC++ and C#.

    Structured exception handling:

    TryCatchFinally.MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    10/33

    Changes in VB Language (cont.)

    When calling procedures, must useparentheses.

    Parameters are by default passed by value,instead of by reference.

    Supports constructors and destructors for

    use when initializing an object of a class.IfThenstatements are now short-circuited.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    11/33

    Changes in VB Language (cont.)

    A number of new compound operatorsE.g. x+=2

    The And, Or, Notand Xoroperators havechanged from bitwise to boolean operators.Meanwhile, the bitwise versions areBitAnd, BitOr, BitNot, and BitXor.

    No default property supportedE.g. VB6: TextBox1=Hello

    VB.Net: TextBox1.Text=Hello

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    12/33

    Changes in VB Language (cont.)

    Three new datatypes

    Char: unsigned 16-bit

    Short: signed 16-bit

    Decimal: signed 96-

    bit (replacesVariant)

    Integer Type VB 6.0 VB.NET

    8 bit Byte Byte

    16 bit Integer Short

    32 bit

    Long

    Integer

    64 bit Not Applicable Long

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    13/33

    Changes in Data Handling

    A new data-handling model: ADO.NET.Facilitates Web application.Uses XML to exchange data.

    COM/DCOM technologies have beenreplaced by .NET framework.Datasets (not record sets now) are basedon XML schema, so they are strongly

    typed.Many new tools are provided to handledata.But can still work with ADO using COMinteroperabilityin the .NET framework.MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    14/33

    Changes in Web Development

    Two major types of Web application:Web forms: web-based applications with

    GUI.Based on ASP.NETCan use standard HTML control, or newServer control handled by the Web server.

    Controls can be bound on a Web form bysetting the codes in the properties.

    Web services: to process data usingHTTP and XML files on the Internet.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    15/33

    Update to VB.NET ?

    Visual Basic .NET represents a majordeparture form previous versions of Visual

    Basic in several ways.----Microsoft CorporationPlenty changes in VB.NET will take lots ofeffort of even the experienced VB

    developers.Old but running fine systems, fund,experienced developers

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    16/33

    Update to VB.NET ? (cont.)

    ConsiderationUnsupported features

    OLE Container ControlDynamic Data ExchangeDAO or RDO Data BindingVB5 Controls

    DHTML ApplicationsActiveX DocumentsProperty Pages

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    17/33

    Update to VB.NET ? (cont.)

    Carefully reworkedSingle-tier Database Applications

    VB Add-insGames

    Graphics

    Drag and Drop Functionality

    VariantsWindows APIs

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    18/33

    Update to VB.NET ? (cont.)

    Visual Basic Upgrade WizardAutomatically invoked when open a VB6

    project.Results are not satisfactory due to thebig different.

    Recoding by hand.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    19/33

    VB.NET Language Essential ----For Non-VB Programmers

    Projects TypesThree most commonly used:

    Windows FormsWeb Forms

    Console Applications

    Statements

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    20/33

    Statement: IfElse

    Module Module1Sub Main()

    Dim intInput As Integer

    System.Console.WriteLine(Enter an interger)intInput=Val(System.Console.ReadLine())If intInput=1 Then

    System.Console.WriteLine(Thank you!)ElseIf intInput=2 Then

    System.Console.WriteLine(Thats good!)

    ElseSystem.Console.WriteLine(Not a right number!)

    End IfEnd Sub

    End Module

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    21/33

    Statement: Select CaseModule Module1Sub Main()

    Dim intInput As IntegerSystem.Console.WriteLine(Enter an interger)intInput=Val(System.Console.ReadLine())Select Case intInput

    Case 1System.Console.WriteLine(Thank you!)

    Case 2System.Console.WriteLine(Thats good!)

    Case 3 To 7System.Console.WriteLine(OK)

    Case Is> 7System.Console.WriteLine(Too Big)

    Case ElseSystem.Console.WriteLine(Not a right number!)

    End SelectEnd Sub

    End Module MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    22/33

    Functions: Switch and Choose

    Switch FunctionSyntax

    Switch(expr1, value1[, expr2, value2[,exprn, valuen]])

    E.g.intAbsValue=Switch(intValue=0, intValue)

    Choose FunctionSyntax

    Choose(index, choice1[, choice2,[,choicen]])Note: unlike array index, choose index from 1 to n

    E.g.

    Str=Choose(intValue, Thank you!, That is good!)MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    23/33

    Loop Statement: Do

    Syntax:Do [While|Until] condition]

    [statements][Exit Do]

    [statements]Loop

    E.g.Module Module1

    Sub Main()Dim strInput As StringDo Until Ucase(strInput)=Stop

    System.Console.WriteLine(What should I do?)strInput=System.Console.ReadLine()

    LoopEnd Sub

    End Module

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    24/33

    Loop Statement: For

    Syntax:For index=startTo end[Step step]

    [statements][Exit For]

    [statements]Next [index]

    E.g.Module Module1

    Sub Main()Dim loopIndex As IntegerFor loopIndex=0 to 3

    System.Console.WriteLine(Hello!)Next loopIndex

    End SubEnd Module

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    25/33

    Loop Statement: While

    Syntax:While condition

    [statements]End While

    E.g.Sub CheckWhile()

    Dim intCounter As Integer =0Dim intNumber As Integer =10While intNumer>6

    intNumber-=1intCounter+=1

    End WhileMsgBox(The loop ran & intCounter & times.)

    End Sub

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    26/33

    Loop Statement: For EachNext

    Syntax:For Each elementIn group

    [statements][Exit For]

    [statements]Next element

    E.g.Sub Main()

    Dim intArray(2), intItem As IntegerintArray(0)=0intArray(1)=1intArray(2)=2For Each intItem In intArray

    System.Console.WriteLine(intArray)Next intItem

    End Sub

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    27/33

    Like a Loop: With

    Syntax:With object

    [statements]

    End WithE.g.

    With TextBox1

    ,Height = 1000

    .Width = 3000

    .Text = Welcome, World!End With

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    28/33

    Like With: Enumerations

    E.g.Module Module

    Enum Days

    Sunday=1Monday=2Tuesday=3Wednesday=4

    End Enum

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

    End SubEnd Module

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    29/33

    Option Statement

    Option Explicit: On/Off.On:requires declaration of all variables beforeused.

    Option Compare: Binary/Text.Specifies strings are compared using binary ortext comparison operations.

    Option Strict: On/Off.On:used when assigning a value of one type toa variable of another type, indicates anypossibility of data loss.

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    30/33

    Example for Option Strict

    Option Strict On

    Module Module1

    Sub Main()

    Dim dbData As DoubleDim intData As Integer

    dbData=3.14159

    intData=Cint(dbData) Not intData=dbData

    System.Console.WriteLine(intData:&_Str(intData))

    End Sub

    End Module

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    31/33

    Imports Statement

    To import a namespace .

    E.g.

    Option Strict OffImports System.Console

    Module Module1

    Sub Main()

    WriteLine(Hello!)

    End Sub

    End Module

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    32/33

    References

    Steven Holzner, Visual Basic.NETBlack Book, The Coriolis Group, LLC,

    2001.http://msdn.microsoft.com/vbasic

    http://www.dotnet247.com

    MELJUN CORTES

  • 7/27/2019 MELJUN CORTES Vb Net Lecture----> HANDOUTS for VB.Net 2010

    33/33

    Thank you!

    MELJUN CORTES