?
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
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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