-1

I'm trying to program an Arduino..... In VBA (Visual Basic for Applications), one can write:

Select Case Range("B5").Value
    Case Is > 1000
        Dim DrawDownVolume As Integer
        DrawDownVolume = 275 + DrugVolume - 315
        Range("E14") = "PHARMACIST:   Draw out " & DrawDownVolume & " mL from 250 mL bag before adding elotuzumab."
        Range("B6").Value = 315
    Case Is < 1000
        'Continue as normal - see below
        Range("E14") = ""
        Range("B6").Value = 275 + DrugVolume
   Case Else
        'Do nothing
End Select

But I see no way of doing this in C++. Can someone point out how this is done? Basically I want to pass a variable through an evaluation event (<, >, !=, etc) with a constant or another variable:

Case Is > TimeStamp

Any help would be greatly appreciated. On-line, I only see switch statements and no select statements talked about.

  • Take a look at the C++ control structures – KIIV Jun 28 '20 at 19:51
  • 3
    Does this answer your question? [How do I select a range of values in a switch statement?](https://stackoverflow.com/questions/9432226/how-do-i-select-a-range-of-values-in-a-switch-statement) – Leonard Jun 28 '20 at 19:51
  • 1
    If you need to program in C++, then I suggest you learn it properly. Please get [a decent book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) or two. – Some programmer dude Jun 28 '20 at 19:52
  • The easiest way of doing what you are looking for is probably through a `if` statement – Ranoiaetep Jun 28 '20 at 19:58
  • If you want to program in C++ then learn C++. – TomServo Jun 28 '20 at 22:09

1 Answers1

0

Using switch case is not a good choice for testing ranges. The best option is to use several if-else if conditions as stated:

if (value == 0)
    // ...
else if (value < 10)
    // ...
else if (value < 25)
    // ...
else if (value < 50)
    // ...
else if (value < 100)
    // ...
else if (value >= 100)
    // ...
else
    std::cout << "ERROR!";

C++ has no Is stuff like VB.Net that could be used in switch statements. Although, still you can do it in a less-readable style:

switch (value) {
    case 0: std::cout << "0";
    case 1:
    case 2:
    case 3: std::cout << "Till some more ranges...";
    ...
    default: std::cout << "ERROR!";
}

Which will make your code super lengthy in case you use it to test lengths on switch statement.

Rohan Bari
  • 7,482
  • 3
  • 14
  • 34