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
241 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

21 Experts available now in Live!

Get 1:1 Help Now