bmsherma
- 24th November 2009, 03:15
Is there a way to isolate a range of numbers in a case statement?
I've used this:
Select Case Voltage
Case is < 512
Expression...
End Select
But what if I want numbers less than 512 AND greater than 256??!
Tried this...didn't work:
Case is < 512 and is > 256
Tried this...didn't work:
Case 256 to 512
Tried this...didn't work:
Case 256:512
Any ideas how to do this? Basically I'm trying to type the code below in a more elegant way. I'm using IF-THEN's at the moment but since there is no ELSEIF command I have 4 separate blocks. I would like one block so I can use an ELSE statement (or in this situation a CASE ELSE). If I use an ELSE statement in the fourth block that ELSE statement will ALWAYS operate if the fourth block is false (even if one of the first 3 blocks is true)...NOT GOOD CODING!
PLEASE HELP!
If (Voltage <=256) and (Voltage > 0) Then
PORTC = %0001
PAUSE 100
Endif
If (Voltage <=512) and (Voltage > 256) Then
PORTC = %0010
PAUSE 100
ENDif
If (Voltage <= 768) And (Voltage > 512) Then
PORTC = %0100
Pause 100
endif
If (Voltage <= 1023) and (Voltage > 768) Then
PORTC = %1000
Pause 100
ENDif
How can I do this with Case Statements??
Thanks in advance!
-Brian
I've used this:
Select Case Voltage
Case is < 512
Expression...
End Select
But what if I want numbers less than 512 AND greater than 256??!
Tried this...didn't work:
Case is < 512 and is > 256
Tried this...didn't work:
Case 256 to 512
Tried this...didn't work:
Case 256:512
Any ideas how to do this? Basically I'm trying to type the code below in a more elegant way. I'm using IF-THEN's at the moment but since there is no ELSEIF command I have 4 separate blocks. I would like one block so I can use an ELSE statement (or in this situation a CASE ELSE). If I use an ELSE statement in the fourth block that ELSE statement will ALWAYS operate if the fourth block is false (even if one of the first 3 blocks is true)...NOT GOOD CODING!
PLEASE HELP!
If (Voltage <=256) and (Voltage > 0) Then
PORTC = %0001
PAUSE 100
Endif
If (Voltage <=512) and (Voltage > 256) Then
PORTC = %0010
PAUSE 100
ENDif
If (Voltage <= 768) And (Voltage > 512) Then
PORTC = %0100
Pause 100
endif
If (Voltage <= 1023) and (Voltage > 768) Then
PORTC = %1000
Pause 100
ENDif
How can I do this with Case Statements??
Thanks in advance!
-Brian