Solved

Best way to graphically show a numeric range - Switch Statement?

Posted on 2011-02-15
3
434 Views
Last Modified: 2012-05-11
I'm doing some file anlytics and want to show a green check image for 100%, an orange one for 90 to 100%, then a red one for less than 90%.

Does anyone have a c# example of this?  I started using a switch statement, but it doesn't seem to allow me to enter ranges.  
0
Comment
Question by:JT_SIRO
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
silemone earned 125 total points
ID: 34899618
why not use a simple if/else contruct

if (x > 10 && x < 90)
0
 
LVL 7

Assisted Solution

by:dimaj
dimaj earned 125 total points
ID: 34899888
switch (myNumber) {
  case myNumber >= 0 && myNumber < 10:
     // display color 1
  case myNumber >= 10 && myNumber < 20:
     // display color 2
  case myNumber >= 20 && myNumber < 30:
     // display color 3
  case myNumber >= 30 && myNumber < 40:
     // display color 4
  case myNumber >= 40 && myNumber < 50:
     // display color 5
  case myNumber >= 50 && myNumber < 60:
     // display color 6
  case myNumber >= 60 && myNumber < 70:
     // display color 7
  case myNumber >= 70 && myNumber < 80:
     // display color 8
  case myNumber >= 80 && myNumber < 90:
     // display color 9
  case myNumber >= 90 && myNumber < 100:
     // display color 10
  case default:
    // there was an error
}
0
 
LVL 7

Expert Comment

by:dimaj
ID: 34899917
if those cases don't work, you can always resort to using IFs

if (range 1) {
  color 1
}
else if (range 2) {
  color 2
}
else if (range n) {
 color n
}
else {
 // error
}
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Auto refresh part of an MVC5 View 7 54
In WPF / C# binding a local database in code behind 1 24
C# Single Form 8 26
System.Speech 2 9
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

914 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

21 Experts available now in Live!

Get 1:1 Help Now