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
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
Try something like:
*Be sure to reset the color of the TextBoxes when data is entered!
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
*Be sure to reset the color of the TextBoxes when data is entered!
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
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
ASKER
Sorry but this will not work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok
What you are expecting there? Check in debug mode this If condition is returning True or not?