Change select case to if\else

• Question

• User1529716912 posted

hello,

can anyone help me in changing the following code from select case to if/else:

Select Case J

Case Is >=5

Select Case false

Case x=1

s = "Test 1"

case else

s = "Test 2"

End select

Case Is > 2, Is < 10, 13, 14

s = "Test 3"

Case Else

s = "Test 4"

End Select

Sunday, March 8, 2015 1:06 AM

• User281315223 posted

Your current case statement seems a bit strange, but it might look something like this :

```' Define your return value (s) '
Dim s = ""

' Run through your logic '
If J >= 5 Then
If x = 1 Then
s = "Test 1"
Else
s = "Test 2"
End If
Else If (J > 2) OrElse (J < 10) OrElse (J = 13) OrElse (J = 14) Then
s = "Test 3"
Else
s = "Test 4"
End If
```

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Sunday, March 8, 2015 8:40 AM

All replies

• User-758443495 posted
```if (j>=5)
{
if (x==1)
{
s = "Test 1";
}
else
{
s = "Test 2";
}
}
else if (j > 2)

{
s = "Test 3";
}
else
{
s = "Test 4";
}```

Sunday, March 8, 2015 1:30 AM
• User281315223 posted

Your current case statement seems a bit strange, but it might look something like this :

```' Define your return value (s) '
Dim s = ""

' Run through your logic '
If J >= 5 Then
If x = 1 Then
s = "Test 1"
Else
s = "Test 2"
End If
Else If (J > 2) OrElse (J < 10) OrElse (J = 13) OrElse (J = 14) Then
s = "Test 3"
Else
s = "Test 4"
End If
```

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Sunday, March 8, 2015 8:40 AM
• User1529716912 posted

thank you very much Rion

A+

Sunday, March 8, 2015 8:46 AM
• User-758443495 posted

OrElse (J < 10) OrElse (J = 13) OrElse (J = 14) never happens as the first if statement is J >= 5 so it is redundant, isn't it?

Sunday, March 8, 2015 8:46 PM