vb.net textbox empty

i have to box for the user to display data so i wanna check befur it debug to see if the textbox is not empty so i try this if  If Len(txtCUSTID.Text) Or (txtname.Text) Then
            MsgBox("Pls Give A Name Or A ID")
end if
but the problem is that after the msg box popt up
yhe code get error
i want if its "" then it shulde not go and wait till the user give a name or text
probly is the way to maka do loop
but i need help on that
menachem680Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSenior Software EngineerCommented:
use the RequiredFieldValidator to check for empty value :
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx
Link contains a very simple textbox/validation example
ZhaolaiCommented:
I assume that you place the code in a button click event (OK button), like this:


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If txtCUSTID.Text = "" Then
            MessageBox.Show("Please enter an ID.", "ID is required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtCUSTID.Focus()
            Exit Sub
        End If
        If txtname.Text = "" Then
            MessageBox.Show("Please enter a name.", "Name is required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtname.Focus()
            Exit Sub
        End If

        'Now you have a valid ID and name, do something with them below.


        'then close the form
        Me.Close()
    End Sub

Open in new window

AliSyedCommented:
If you are using ASP.net you might want to use required validator control that is built in to force the user to mak an entry before submitting the form.
check this
http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/validation/RequiredFieldValidator.src
you can set messagebox propert to true to show the error message in message box
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

menachem680Author Commented:
THE PROBLEM IS THAT THE MSGBOX  SHULDE ONLY DISPLAY ONLY IF BOTH R EMPTY?
ZhaolaiCommented:
If you want message box to display when BOTH fields are empty, try this:

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If txtCUSTID.Text = "" AndAlso txtname.Text = "" Then
            MessageBox.Show("Please enter an ID or name.", "Either ID or Name is required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtCUSTID.Focus()
            Exit Sub
        End If

        'Now you have a valid ID and name, do something with them below.


        'then close the form
        Me.Close()
    End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jorge PaulinoIT Pro/DeveloperCommented:

You already have an answer but just to clarify your problem ... Len() function gives you the lenght of your string. Your code could work if you changed Len(txtCUSTID.Text) = 0, because txtCUSTID.Text lenght should be always bigger then zero.

Also you need to change the "OR" to "AND" because you need to check if the two conditions where true.

Something like: If Len(txtCUSTID.Text) = 0 AND Len(txtname.Text) = 0 Then

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.