Solved

Why the code  is not working

Posted on 2012-04-05
7
292 Views
Last Modified: 2012-04-06
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
0
Comment
Question by:searchsanjaysharma
[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
7 Comments
 
LVL 9

Expert Comment

by:suvmitra
ID: 37815117
If True Then

What you are expecting there? Check in debug mode this If condition is returning True or not?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37815161
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!
0
 

Author Comment

by:searchsanjaysharma
ID: 37815183
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
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 9

Expert Comment

by:suvmitra
ID: 37815190
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
0
 

Author Comment

by:searchsanjaysharma
ID: 37815191
Sorry but this will not work
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 37815210
Dim Passed As Boolean = True

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

        If Passed Then
            MsgBox("test")
        End If
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37815249
ok
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

632 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