-1

I am trying to use SELECT CASE in my code.

but even the value of the variable is in between the set value in SELECT CASE it does not hit the code inside that case.

for example:

Dim i as Integer = 27

Select Case i
   Case 3 To 33
      'This would be Hit
   Case 34 To 50 
      'Some Code
   Case Else
End Select

Now. The code below in comment This would be hit cannot be executed.

How to fix it?

Regards,

Boooo Booooo
  • 57
  • 1
  • 2
  • 11

1 Answers1

1

Either you are mistaken or something on your system is broken. I just tested this code in a Console project:

Module Module1

    Sub Main()
        Dim i As Integer = 27

        Select Case i
            Case 3 To 33
                'This would be Hit
                Console.WriteLine("i is in the range 3 to 33")
            Case 34 To 50
                'Some Code
                Console.WriteLine("i is in the range 34 to 50")
            Case Else
                Console.WriteLine("i is in not in either range")
        End Select

        Console.ReadLine()
    End Sub

End Module

I saw the message:

i is in the range 3 to 33

as expected.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • Thank you Sir.. I saw that the data type of the declared variable is in `string`. That's Why. hehe – Boooo Booooo Jun 19 '19 at 04:39
  • 2
    That's an example of why it's important to copy and paste the actual code you're using that generates the error. We can't help with code we haven't seen, especially if we're misled with code you're not actually running. – jmcilhinney Jun 19 '19 at 05:09
  • I'm Sorry Sir. Next time I will copy my original code. – Boooo Booooo Jun 20 '19 at 02:20