Visual Basic.NET
  Home arrow Visual Basic.NET arrow Understanding Custom Events using Visual B...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Understanding Custom Events using Visual Basic.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2007-08-08

    Table of Contents:
  • Understanding Custom Events using Visual Basic.NET 2005
  • A sample class without any event declarations: testing the class
  • Rewriting the sample class with eventing in Visual Basic 2005: coding the class
  • Rewriting the sample class with eventing in Visual Basic 2005: testing the class
  • Handling events dynamically in Visual Basic 2005

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Understanding Custom Events using Visual Basic.NET 2005


    (Page 1 of 5 )

    This article teaches you how to declare and handle events using Visual Basic.NET 2005. It assumes the reader is familiar with object-oriented programming in Visual Basic.NET.
    A downloadable zip file is available for this article.

    If you are new to OOP in Visual Basic.NET, I strongly suggest you to go through the following links:

    Using Constructors with Object-Oriented Database Development

    Properties and Object-Oriented Database Development

    Using Methods with Object-Oriented Database Development

    Inheritance with VB.NET 2005

    The entire source code for this article is available in the form of a downloadable zip file. The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition.  I didn't really test it in any other environment.  I request that you post in the discussion area if you have any problems in execution.

    A sample class without any event declarations: coding the class

    Before going directly to learning about events in Visual Basic 2005, let us try to understand the following class:

    Public Class Sample01

      Private _x As Integer

      Private _y As Integer

     

      Public Property X() As Integer

        Get

          Return _x

        End Get

        Set(ByVal value As Integer)

          _x = value

        End Set

      End Property

     

      Public Property Y() As Integer

        Get

          Return _y

        End Get

        Set(ByVal value As Integer)

          _y = value

        End Set

      End Property

     

      Public Function GetCalculatedValue() As Double

        If Me.Y <> 0 Then

          Dim v As Double = Me.X / Me.Y

          MessageBox.Show("Successful")

          Return v

        Else 'division by zero

          MessageBox.Show("Division by zero is not permitted")

          Return 0

        End If

      End Function

    End Class

     

    The above class has two private fields ("_x" and "_y") which are only accessible within the class, and not outside the class. Further, it has two public properties and a public method named "GetCalculatedValue" (public members are accessible even outside the class).

    The "GetCalculatedValue" method tries to do division based on the values available in "_x" and "_y."  The denominator ("_y") should never be zero during division.  The "if" condition checks for the same and responds with an appropriate message.

    In the next section we will try to test the above class with a Windows form.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,This is my new article on "Events in Visual Basic 2005". This is...
       · Event handler methods take two parameters. The first is of type System..::.Object...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek