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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Call an IPL program from vb.net and pass in a file location parmeter 2 17
SQL LINE CONTINUATION ISSUE 12 31
get row value in vb.net 4 14
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
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…

813 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

12 Experts available now in Live!

Get 1:1 Help Now