Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Inheritance and Windows Forms
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 
Moblin 
JMSL Numerical Library 
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

Inheritance and Windows Forms
By: Mohammed Qattan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 25
    2004-01-26

    Table of Contents:
  • Inheritance and Windows Forms
  • Exploring Forms
  • Validating Inputs
  • Carrying Out the Scenario
  • Explanation

  • 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


    Inheritance and Windows Forms - Validating Inputs


    (Page 3 of 5 )

    So far we managed to have 2 forms, with the same basic controls and functionality, much like the “Employee” class and the other inherited classes “Manager” and “Technician”. It shouldn’t stop here, should it?

    Uhm, no.

    As a matter of fact, if I am adding a Manager, or a Technician, then I want to validate the inputs. We will not, however, make the validation on each form alone (remember the “ManageEmployee” Form). We will put the validation code and make use of the error provider on the “ManageEmployee” form.

    We will add a function “IsValidInputs” which will validate the user inputs in the text boxes. It will also set the set the properties of the error provider if any errors were found.


    Protected Function IsValidInputs() As Boolean
            Dim strEmployeeName 
    As String
            Dim strEmployeeAge 
    As String 
    'Age should be integer, but not we will be reading from the' 
    'text box, and we need to validate that it is an integer'
            Dim bIsValidInputs 
    As Boolean True 
    'we start with the assumption that the inputs are valid'
            
    Try
                
    strEmployeeName txtName.Text.Trim
                strEmployeeAge 
    txtAge.Text.Trim
                
    'check if the Name is empty'
                
    If strEmployeeName String.Empty Then
                    bIsValidInputs 
    False
                    errProvider
    .SetError(txtName"Please add a Name.")
                Else
                    
    'Make sure to clear the Error Provider
                    errProvider.SetError(txtName, "")
                End If
                If strEmployeeAge = String.Empty Then
                    bIsValidInputs = False
                    errProvider.SetError(txtAge, "Please add an Age.")
                Else
                    '
    Make sure to clear the Error Provider'
                    errProvider.SetError(txtAge, "")
                End If
                If Not IsNumeric(strEmployeeAge) Then
                    bIsValidInputs = False
                    errProvider.SetError(txtAge, "Age should be a number.")
                Else
                    '
    Make sure to clear the Error Provider'
                    errProvider.SetError(txtAge, "")
                End If
                Return bIsValidInputs
            Catch oException As Exception
                '
    Handle any unexpected errors here'
            End Try
        End Function

    Let’s get back to the object oriented. The function above should be only visible to the form and the forms inheriting from it. (Yes, it should be protected.)

    More Visual Basic.NET Articles
    More By Mohammed Qattan


     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - 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 ...





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