Solved

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

Posted on 2011-02-15
3
436 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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