Wednesday, 24 October 2012

Mistaken use of Select Case

When I showed you how to check multiple cases to do the same outcome I accidently used a format found in the language C#. This results in no action being taken.

Below is a short example illustrating the way I showed you and the correct way to do it.

For p = 0 To s.Length - 1
    Select Case s.Substring(p, 1).ToLower()
 
          'correct way to test for multiple cases with same outcome
          'use comma between things you want to do the same action with
          Case "a", "b", "c" : counter = counter + 1
 
          'wrong way to test for multiple cases with same outcome
          'this will not work
          Case "a" : Case "b" : Case "c" : counter = counter + 1
     
     End Select
 Next

No comments:

Post a Comment