Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

Why the code is not working

Why this code is not of working.
I hve 3 textboxes, i want if any of the textboxes is empty it should be red.If all the textboxes are filled the code for save should fire.

on btnclick

If True Then
            If TextBox1.Text = "" Then
                TextBox1.BackColor = Color.Red
            End If
            If TextBox2.Text = "" Then
                TextBox2.BackColor = Color.Red
            End If
            If TextBox3.Text = "" Then
                TextBox3.BackColor = Color.Red
            End If
        Else
            MessageBox.Show("India is great")
             'code to save data
End If
Avatar of suvmitra
suvmitra
Flag of India image

If True Then

What you are expecting there? Check in debug mode this If condition is returning True or not?
Avatar of Mike Tomlinson
Try something like:
            Dim Passed As Boolean = True 

            If TextBox1.Text.Trim = "" Then
                TextBox1.BackColor = Color.Red
                Passed = False
            End If
            If TextBox2.Text.Trim = "" Then
                TextBox2.BackColor = Color.Red
                Passed = False
            End If
            If TextBox3.Text = "" Then
                TextBox3.BackColor = Color.Red
                Passed = False
            End If

            If Passed Then
                'code to save data
            End If

Open in new window


*Be sure to reset the color of the TextBoxes when data is entered!
Avatar of searchsanjaysharma
searchsanjaysharma

ASKER

Ya good, but the user may enter the in t1 and t3, and leave t2, i want to color t2 only. then this one will not be ideal
use

if isempty(TextBox1) then
TextBox1.BackColor = Color.Red
elseif isempty(TextBox2) then
TextBox2.BackColor = Color.Red
elseif isempty(TextBox2) then
TextBox2.BackColor = Color.Red

end if
Sorry but this will not work
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial