Solved

Why the code  is not working

Posted on 2012-04-05
7
287 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
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 85

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now