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
247 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 62

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now