Solved

How would I do validate to see if 3 text boxes hold text in vb.net with Windows forms?

Posted on 2006-06-19
3
253 Views
Last Modified: 2010-04-23
I am looking for a way of doing something in VB.NET.  I want to be able have the user look at the form.  If any of 3 text boxes are empty, I want a messagebox to go off saying ("Please fill text box1 with a filepath")  I want this to be done for three different text boxes in a form.  If any of them are empty, I want the messagebox to be displayed for that particular text box.  If all text boxes have text, then the program will run.  How would I do this?
0
Comment
Question by:VBBRett
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 16935179
1) You could use an ErrorProvider control

2) You could use something like this:

  If Text1.Text.Length = 0 OrElse Text2.Text.Length = 0 OrElse Text3.Text.Length = 0 Then
    MessageBox.Show("Please fill text box1 with a filepath")
  End If

Bob
0
 

Author Comment

by:VBBRett
ID: 16935444
Thank you TheLearnedOne
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16935454
Hi VBBRett;

Or you can use the Validating event of the TextBox object. I am using one Validation event to handle all three TextBox's.

    Private Sub TextBox_Validating(ByVal sender As Object, _
        ByVal e As System.ComponentModel.CancelEventArgs) _
        Handles TextBox1.Validating, TextBox2.Validating, TextBox3.Validating

        Dim tb As TextBox = CType(sender, TextBox)

        If tb.Text.Length = 0 Then
            MessageBox.Show("The text box " & tb.Name & _
                " can not be empty. Please correct.")
            tb.Focus()
        End If

    End Sub


Fernando
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question