Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 9
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Understanding Custom Events using Visual Basic.NET 2005 - A sample class without any event declarations: testing the class


    (Page 2 of 5 )

    To test the class presented in the previous section, add a new form with two buttons and a label.  Modify your code to match the following:

    Public Class Form1

      Dim obj As New Sample01

     

      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        obj.X = 10

        obj.Y = 0

        Me.lblValue.Text = obj.GetCalculatedValue

      End Sub

     

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        obj.X = 10

        obj.Y = 5

        Me.lblValue.Text = obj.GetCalculatedValue

      End Sub

     

    End Class

     

    When you hit "Button1," it should give you a "Successful" message and the result in a label.  If you hit "Button2," it gives the error message and the result in the label would be "0."

    It is quite impractical (and not at all recommended) to have message boxes in classes. The business logic classes are meant only for logic and none of them should display any message boxes. Instead, the messages should be sent to the calling applications (in this case, it is the form). 

    In the "GetCalculatedValue" method, we are dealing with two things simultaneously. One of them is giving a message to the form (the user may use the message for display or simply suppress messages from displaying), and the other is returning a value back to the form.  Returning a value to the form is simply done using the "Return" statement.  How about the message?  How do we send it back professionally?  The user may or may not be interested in the message!  If he is interested, he displays the message in another label and if not, he simply neglects it.

    The next section gives you a professional approach for the same issue using events in Visual Basic 2005.

    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

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway