Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation Methods

Status
Not open for further replies.

trenta87

Programmer
Oct 29, 2007
13
US
Does anyone know a way that I can use a general method which validates whether a textbox is empty or not. I want to be able to write one method and have it applied to all textboxes in my project instead of rewriting the code for each field. Can anyone help?
 
Hi there,

First of all put an ErrorProvider control onto your form then create this sub:

Code:
    Private Sub Textboxes_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles textbox1.Validating, textbox2.validating
  
If CType(sender, TextBox).Text = "" Then
 ErrorProvider1.SetError(sender, "This field cannot be emtpy")
Else
 ErrorProvider1.SetError(sender, "")
End If

then just put all of the textboxes you wish to validate after the handles statement with their validating event.

hope this helps.

alex

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
Rick Cook, The Wizardry Compiled
 
apologies this is not written for project wide only form wide but could definitely be tweaked to do so.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
Rick Cook, The Wizardry Compiled
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top