Content Archived

This content is no longer current. Our recommendation for up to date content: http://channel9.msdn.com/Series/Visual-Basic-Fundamentals-for-Absolute-Beginners

Enumerations and the switch Decision Statement - 19

Sign in to queue

The Discussion

  • User profile image
    Adam​Speight2008

    A found it a little misleading when you (Bob) refer to the ComplexIfStatement, kind of inferred or suggested that the Select Case decision statement can't do what the ComplexIfStatement does. (Especially with Option Strict Off)

    See Example Below.

    Module Module1
    
      Sub Main()
        SelectCase_Example()
        Console.WriteLine()
        SuperHero_Example()
        Console.ReadLine()
      End Sub
      Public Sub SelectCase_Example()
        Console.WriteLine("Select Case Example")
        Dim value = 42
        Select Case value
          Case Is < 1, Is > 100 : Console.WriteLine("Out of bounds")
          Case 23, 42, Is > 90 : Console.WriteLine("You Found one of the special numbers")
          Case Else
            Console.WriteLine("Not one of special numbers")
        End Select
      End Sub
      Public Sub SuperHero_Example()
        Console.WriteLine("SuperHero Example")
        GreetSuperHero(11)
        GreetSuperHero(SuperHeros.Batman)
      End Sub
    
      Public Sub GreetSuperHero(ByVal superhero As SuperHeros)
        Dim IsMemberOfSuperHeros = [Enum].IsDefined(GetType(SuperHeros), superhero)
        If IsMemberOfSuperHeros Then
          Console.WriteLine("Hello: {0}", superhero.ToString)
        Else
          Console.WriteLine("How Are You?")
        End If
      End Sub
      Enum SuperHeros
        Superman
        Batman
        Spiderman
      End Enum
    End Module
    

    When you use Enumerations it can be of any value that the underlying type can be. 

    See Example Code above

     

  • User profile image
    BobTabor

    @AdamSpeight2008:Awesome, awesome comment.  Thank you!  When we re-do this video I'll make sure to revise as you have advised.

Add Your 2 Cents