Solved

Why the code  is not working

Posted on 2012-04-05
7
286 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

13 Experts available now in Live!

Get 1:1 Help Now