Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why the code  is not working

Posted on 2012-04-05
7
Medium Priority
?
295 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

927 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