VB .net tutorial - 13

Embed Size (px)

Citation preview

  • 8/14/2019 VB .net tutorial - 13

    1/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 1 of 19

    Objectives

    In this lesson, you will learn to:

    Create components for Windows Forms

    Use COM components in Visual Basic .NET

    Implement an Interface in Visual Basic .NET

  • 8/14/2019 VB .net tutorial - 13

    2/19

  • 8/14/2019 VB .net tutorial - 13

    3/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 3 of 19

    Just a Minute

    You need to write a program to validate user logins. Thisprogram will be used across applications. What will youdevelop the program as and why?

  • 8/14/2019 VB .net tutorial - 13

    4/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 4 of 19

    Component Architecture in .NET

    Assembly

    Contains information about the files on which the

    component depends and the location of these files.

    Consists of a manifest and the portable executables(PE).

    Global Assembly Cache Is a repository of assemblies.

    Must have a unique identification to resolve nameconflicts. To avoid this conflict you can also give ashared name to an assembly.

  • 8/14/2019 VB .net tutorial - 13

    5/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 5 of 19

    Just a Minute

    Why does an assembly need a shared name?

  • 8/14/2019 VB .net tutorial - 13

    6/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 6 of 19

    Component Classes

    Get created when they follow defined standards ofinteraction provided by the IComponent interface.

    Can be created by using the .NET Class Library projecttemplate.

    Can be used in another project by adding a reference to thecomponents.

  • 8/14/2019 VB .net tutorial - 13

    7/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 7 of 19

    Just a Minute

    How will you use a component?

  • 8/14/2019 VB .net tutorial - 13

    8/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 8 of 19

    Life Cycle of a Component

    Initialization phase

    Can be of two types:

    Type initialization

    Instance initialization

    Cleanup phase Is implemented by using the Dispose() method.

    Destroy phase

    Gets invoked when the garbage collector finds thatthere are no references to the component and thereforeit calls the Finalize() method of the component.

  • 8/14/2019 VB .net tutorial - 13

    9/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 9 of 19

    Polymorphism

    Is the ability of a class to implement functions with the samename to perform different actions depending on how theyare called.

    Is a feature supported by all object-oriented languages.

    Can be implemented in three ways:

    By implementing an interface

    By using inheritance

    By using abstract classes

  • 8/14/2019 VB .net tutorial - 13

    10/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 10 of 19

    COM in .NET

    .NET supports COM and ActiveX objects for backwardcompatibility.

    Interaction between COM and .NET is provided through awrapper called RuntimeCallableWrapper (RCW).

    A COM component can be called from .NET in the followingways:

    By converting the COM type library to a .NET assemblyby using the tlbimp tool

    Using COM components directly by adding a reference

  • 8/14/2019 VB .net tutorial - 13

    11/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 11 of 19

    Problem Statement 13.D.1

    Customers of Diaz Telecommunications who place theirorders online must submit their credit card number, name, andthe expiry date of the credit card. The credit card numbersubmitted has to be validated.

  • 8/14/2019 VB .net tutorial - 13

    12/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 12 of 19

    Task List

    Identify the most suitable type of component.

    Identify the properties and methods for the component.

    Create a project of the appropriate type.

    Add properties and functions to the component.

    Build the component.

    Create a user interface to display the result.

    Verify the execution.

  • 8/14/2019 VB .net tutorial - 13

    13/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 13 of 19

    Task 1: Identify the most suitable type of component.

    Result:

    A customized component has to be created to verify the

    credit card numbers supplied by the customers.

  • 8/14/2019 VB .net tutorial - 13

    14/19

  • 8/14/2019 VB .net tutorial - 13

    15/19

  • 8/14/2019 VB .net tutorial - 13

    16/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 16 of 19

    Task 2: Identify the properties and methods for thecomponent. (Contd.)

    Result:

    RightChar(): A method to return the rightmost characterfrom a string.

    CharaceterToInt(): A method to return the numericalequivalent of a character.

    Validate(): A method to validate the card number.

  • 8/14/2019 VB .net tutorial - 13

    17/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 17 of 19

    Task 3: Create a project of the appropriate type.

    Task 4: Add properties and functions to the

    component.

    Task 5: Build the component.

    Task 6: Create a user interface to display the result.

    Task 7: Verify the execution.

  • 8/14/2019 VB .net tutorial - 13

    18/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 18 of 19

    Problem Statement 13.P.1

    The Employee data in the call centers at DiazTelecommunications requires check for valid employee id,age, and salary entries. The employee id should start with theletter E followed by three digits. The age should be from 21years to 60 years. In addition, the salary should be in therange of $3000 to $35000. Create a component that will checkthe validity of employee id, age, and salary.

  • 8/14/2019 VB .net tutorial - 13

    19/19

    Creating Components

    NIIT Creating Components/Lesson 13/Slide 19 of 19

    Summary

    In this lesson, you learned that:

    A component is a reusable piece of code in a binary formthat can be plugged into components from other

    vendors, with relatively little effort.

    An assembly contains information about the files on whichthe component depends and the location of these files.

    An interface can be implemented in a class to implementpolymorphism.

    ComponentObjectModule (COM) is alanguage independent software architecture that defines a set

    of standards for component interoperability.COM components can be used in .NET by using the tlbimp

    tool or by adding a reference.