Extend Select Case Range with a Integer Varible


How do I extend a range in a Select Case Statement. It’s seems that it would be Simple but I’m making it complicated. Also my iRange calculates to a negative integer. I have to change it to a positive integer. This is a way that I though I could pull it off but it does not work. Forgive me for not indenting the code there has been a lot of changes to the Forum posting editor since I have last been here. It used to have code formatting.

Thank You

Dim iRange As Integer
Dim iExtend As Integer

iExtend = -2

iExtend = -Extend

Select Case iRange
Case 1 to 11 + -(iExtend)
MessageBox("Extend Range 1 to 13 ")
Case 12 to 24
MessageBox(“12 to 24 Range”)
End Select

If I understand the question, you can use a comma:

Case 1 to 11, iExtend

The code posted works fine.

Maybe if you explain what do you meant with “extend a range”.

And also, what is the problem with that code?


I see how i made it confusing with the negative integer. I made a correction in the code to turn it into a positive integer. I’m trying to extend the range from (1 to 11) to (1 to 11 + (iExtend)) or 1 to 13. (Extend = 2) If that makes any sense.

I just tried it again and it worked. Somehow the Xojo intellisense was throwing a syntax error. I think it was the way I was using the parenthesis. I better take a break. Thanks guys for the help.


Jeffrey, you could also use:

Select Case True
Case iRange >= 0 and iRange <= extend

Case iRange > extend and iRange < 24

End Select

I’ll try it Greg. Thanks

Use another variable to avoid confusions and better to use the Abs function instead of Negate the value :

Dim iRange As Integer = 12
Dim iExtend As Integer
Dim iExtended As Integer

iExtend = -2
iExtend = abs(iExtend)
iExtended = 11 + iExtend

Select Case iRange
Case 1 To iExtended
  MessageBox("Extend Range 1 to 13 ")
Case 12 To 24
  MessageBox("12 To 24 Range")
End Select
1 Like

good variable name are importent for understanding.
iRange is not a range it is a number.
a range have two numbers, from to.

i suggest also to have a ready input for a method.
not this special means everywhere.

Thank You for your input on better variables naming Markus.