[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# What am I doing wrong?

Posted on 2012-08-17
7
Medium Priority
?
320 Views
Last Modified: 2012-08-17
Hello, I need some help to figure out why I'm not getting the expected results from the code below?  


            double D47 = double.Parse(txtD47.Text);
            int D48 = Convert.ToInt32(txtD47.Text);
           
           
            if (D48 <= 3)
                txtD47.StateActive.Border.Color1 = Color.Red;


The value in txtD47.Text is 79 and the code changes the Border of field txtD47 to Red.  My thinking is it should make no changes to the Border and the default color set in the properties should be the Border color.

If I hard code and  set the value of D48 to 79 (D48 = 79;) all works as expected and the Border of txtD47 shows the default color set in the properties.

Any help appreciated.

Gary
0
Comment
Question by:garymcgowan
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38306208
Instead of:

    int D48 = Convert.ToInt32(txtD47.Text);

Try this:
            int D48;
            if (int.TryParse(txtD47.Text, out D48))
            {
                if (D48 <= 3)
                {
                    txtD47.StateActive.Border.Color1 = Color.Red;
                }
            }
            else
            {
                MessageBox.Show("Invalid Int in D47");
            }

Open in new window


Do you get any messages?
0
 

Author Comment

by:garymcgowan
ID: 38306382
No, it didn't work.  No MessageBox was displayed.  Any more ideas?

Thanks for your help.

Gary
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 38306639
Might need to see more code...not sure.

Does this shed any more light?...
           int D48;
            if (int.TryParse(txtD47.Text, out D48))
            {
                if (D48 <= 3)
                {
                    txtD47.StateActive.Border.Color1 = Color.Red;
                }
                else
                {
                    MessageBox.Show("D47 is greater than 3: " + txtD47.Text);
                } 
            }
            else
            {
                MessageBox.Show("Invalid Int in D47: " + txtD47.Text);
            }

Open in new window

0
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.

 

Author Comment

by:garymcgowan
ID: 38306715
Thanks for all your help.  With the above code I get the Messagebox "D47 is greater than 3: 76"  

Thanks, Gary
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38306745
..and you really intended to use a variable called "D48" with a TextBox called "txtD47"?  (not "txtD48"?)
0
 

Author Comment

by:garymcgowan
ID: 38306820
No, no txtD48.  Using that as a variable.  Thanks to you I have the code working as expected.  Here is a copy of the code:

            int D48;
            if (int.TryParse(txtD47.Text, out D48))
            {
                if (D48 <= 3)
                {
                    txtD47.StateActive.Back.Color1 = Color.Lime;
                }
                else
                {
                    txtD47.StateActive.Back.Color1 = Color.White;
                }
             
                {
                    txtD47.StateActive.Border.Color1 = Color.Red;
                }

                if (D48 >= 87)
                {
                    txtD47.StateActive.Back.Color1 = Color.Lime;
                }

                else

                {
                    txtD47.StateActive.Border.Color1 = Color.Red;
                }

                {
                    txtD47.StateActive.Border.Color1 = Color.Red;
                }

I'm sure this could be done much more efficiently but I'm more interested in it working that reducing lines of code.  Again, thank for your help.  I couldn't have done it without you.

Gary
0
 

Author Comment

by:garymcgowan
ID: 38307037
I cleaned this code up a bit in case someone ever has the same problem.  Thanks to Idle_Mind for all his help.

Gary

                int D47;

                int.TryParse(txtD47.Text, out D38);
               
                    if ((D47 <= 3) || (D47 >= 87 ))
                   
                        txtD47.StateActive.Back.Color1 = Color.Lime;
                    else
                        txtD47.StateActive.Back.Color1 = Color.White;

                    if ((D47 <= 3) || (D47 >= 87))
                   
                        txtD47.StateActive.Border.Color1 = Color.Green;
                    else
                        txtD47.StateActive.Border.Color1 = Color.Red;
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

829 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