Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why the code  is not working

Posted on 2012-04-05
7
Medium Priority
?
293 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

705 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