• androidimg
  • phpimg
  • c++img
  • javaimg
  • netimg
  • Android Programming

    Android software development is the process by which new applications are created for the Android operating system. Applications are usually developed in the Java programming language using the Android Software Development Kit.

  • PHP Programming

    PHP is a server scripting language, and widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

  • C++ Programming

    C++ is one of the most popular object oriented programming languages and is implemented for both hardware and operating system platforms. C++ is also used for hardware design, where the design is initially described in C++, then analyzed, architecturally constrained, and scheduled to create a register-transfer level hardware description language via high-level synthesis.

  • Java Programming

    Java is an object-oriented language similar to C++, but simplified to eliminate language features that cause common programming errors. Java source code files are compiled into a format called bytecode.

  • .Net Programming

    Microsoft describes .NET as a set of software technologies for connecting information, people, systems, and devices. This new generation of technology is based on Web services-small building-block applications that can connect to each other as well as to other, larger applications over the Internet.

Monday 18 April 2016

Posted by Venika Emy
No comments | 20:57
Classes provide reusable code in the form of objects. A class library contains one or more classes that can be called on to perform specific actions. This walkthrough shows how to create a class library project in vb.net and incorporate it into a Web application project.

In order to complete this walkthrough, you will need:
  • The .NET Framework version 3.5.
  • The SP1 release of Visual Web Developer 2010 Express.
The following procedures build upon each other. Therefore, you must follow the order of the procedures to successfully complete this walkthrough.

Creating the Class Library Project

To create the CDemoLib class library and the Customer class file

1.      On the File menu, select New Project to open the New Project dialog box.
2.      In the list of Windows project types, select Class Library, and then type CDemoLib in the Name box.
3.      In Solution Explorer, right-click CDemoLib and then click Properties.
Notice that the Default namespace box contains CDemoLib. The root namespace is used to qualify the names of class in the assembly. For example, if two assemblies provide class named Customer, you can specify the Customer class by using CDemoLib.Customer.
Close the properties window.
4.      In Solution Explorer, right-click CDemoLib, click Add, and then click Class.
The Add New Item dialog box is displayed.
5.      Type Customer.cs in the Name box and then click Add to create the class.
A class named Customer is added to your class library.
6.      In Solution Explorer, right-click Class1.cs and then click Delete.
This deletes the default class that is provided with the class library, because it will not be used in this walkthrough.
7.      In the File menu, click Save All to save the project.

Creating the Class

Constructors control the way your class is initialized. Properties are values of the class that you can get and set. In Visual C#, all constructors have the same name as the class.

To add code to define the Customer class

·         In the code editor, replace the existing code with the following code to define the Customer class in the CDemoLib class library.
VB
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
 Namespace CDemoLib
    Public Class Customer
        Private _age As Integer        Private _name As String      
        Public Sub New()
            Age = 0
            Name = "Not available"        End Sub      
        Public Property Age() As Integer            Get                Return _age
            End Get            Set                _age = value
            End Set        End Property        Public Property Name() As String            Get                Return _name
            End Get            Set                _name = value
            End Set        End Property    End ClassEnd Namespace

Adding the Class Library to a Web Application Project

To test the class, you must have a project that uses it. This project must be the first project that starts when you run the application.

To add the CDemoTest Web Application project as the startup project for the solution

1.      In the File menu, click Add and then click New Project.
The Add New Project dialog box is displayed.
2.      Under Project types, expand Visual Basic or Visual C#, and then click Web to display available Web templates.
3.      In the Templates box, select ASP.NET Web Application.
4.      In the Name box, type CDemoTest as the name of the new application.
5.      Click OK.
creates the Web application project in the existing solution.
In order to use the Customer class, the client test project must have a reference to the class library project. After you add the reference, it is a good idea to add a using statement in C# (an Imports statement in Visual Basic) to the test application to simplify the use of the class.

To add a reference to the class library project

1.      In Solution Explorer, right-click the References node underneath CDemoTest, and then click Add Reference.
2.      In the Add Reference dialog box, select the Projects tab.
3.      Double-click the CDemoLib class library project. CDemoLib will appear under the References node for the CDemoTest project.
4.      In Solution Explorer, right-click Default.aspx and then click View Code.
Adding the reference to CDemoLib lets you use the fully qualified name of the Customer class, which is CDemoLib.Customer.

To add a using or Imports statement

·         Add the following using statement (Imports in Visual Basic) at the top of the code editor window for the Default.aspx page.
VB
Imports CDemoLib
·         Adding this statement lets you omit the library name, and refer to the class type as Customer.

Using the Class from the Class Library

The CDemoTest Web application will call the class that is contained in the class library and display the results.

To add code to create and use a Customer object

1.      In Solution Explorer, right-click Default.aspx and select View Designer.
2.      From the Standard tab of the Toolbox, drag a Label control onto the design surface.
3.      Double-click the design surface to display the Page_Load event handler.
4.      In the Page_Load event handler add the following code:
VB
Dim myCustomer As New Customer()
myCustomer.Name = "Alex Jendar"myCustomer.Age = 30
Label1.Text = "Name: " & myCustomer.Name + "<br/>Age: " & _     myCustomer.Age.ToString()
5.      In the File menu, click Save All to save the solution.

To run and debug the CDemoTest project

1.      Press CTRL+F5 to start the solution.
Notice that the Customer class properties are automatically displayed in the label control.
2.      Close the browser window to return to the development environment.



0 comments:

Post a Comment

About Us

We provide excellent programming solutions & supports in an easy ongoing development environment.
Sitemap