Results 1 to 6 of 6

Thread: Case Statement Issue VS 2010 Plz Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    73

    Question Case Statement Issue VS 2010 Plz Help

    So Im Using The Case Statement In My Chat Bot Application And From My Code Below You Will See The Line "Do You Think I Am Nice" , Now , im trying to make it so that if you type in anything other than "yes" or "no" then it says "I Did Not Understand That". I tried using a case else statement and that did not work . any ideas ?



    Code:
    Console.ForegroundColor = ConsoleColor.Yellow
            Console.WriteLine("Do You Think I Am Nice ?")
            Select Case Console.ReadLine.ToLower
    
                Case "yes", "no"
    
    
                    Console.WriteLine("Thank You , I'm Glad You Like me :) , Do You Like Thanksgiving ?")
                    Response3 = Console.ReadLine.ToUpper
    
                    If Response3 = "yes" Then
                        Console.WriteLine("Me Too , I Wish I Could Eat Turkey Though ....")
                        Console.WriteLine("Since I Am A Computer")
                    ElseIf Response3 = "no" Then
                        Console.WriteLine("Nice")
    
                    Else
                        Console.ForegroundColor = ConsoleColor.Red
                        Console.WriteLine("I Didn't Understand That.")
                        Console.WriteLine("-----------------------------")
                        Console.ReadLine()
                        End
                    End If
    
                Case "no", "nah"
                    Console.ForegroundColor = ConsoleColor.Yellow
                    Console.WriteLine(":( , Im Sorry , I'll Get You Flowers To Make Up For It , Do You Like Flowers ?")
                    Response4 = Console.ReadLine().ToLower
                    If Response4 = "yes" Then
                        Console.WriteLine("Okay I'll Talk To You Later , Im Off To Get Sunflowers , Bye")
                    ElseIf Response4 = "no" Then
                        Console.WriteLine("Okay , Ill Try To Be A Better Robot , Bye")
                    Else
                        Console.ForegroundColor = ConsoleColor.Red
                        Console.WriteLine("I Didn't Understand That")
                        Console.WriteLine("-----------------------------")
                        Console.ReadLine()
                        End
                    End If
    
            End Select
            Console.ReadLine()
    
    
        End Sub
    
    End Module
    Last edited by dday9; Nov 24th, 2014 at 04:36 PM. Reason: Added code tags

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: Case Statement Issue VS 2010 Plz Help

    I've added code tags to your code. They help format the code properly and look like this:
    [CODE][/CODE]

    As for your question, just like If/Then statements, Select/Case statements contain an Else keyword:
    Code:
    Case Else
        'Sorry I didn't understand that
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    73

    Re: Case Statement Issue VS 2010 Plz Help

    I put that under Case and it gave me an error

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    73

    Re: Case Statement Issue VS 2010 Plz Help

    it said

    Error 1 'Case' cannot follow a 'Case Else' in the same 'Select' statement. C:\Users\jason_000\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Module1.vb 104 13 ConsoleApplication1

    When I put a case else in

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: Case Statement Issue VS 2010 Plz Help

    Just like the If/Then statement it has to be the last case:
    Code:
    Select Case Console.ReadLine.ToLower
        Case "yes", "no"
    
        Case "no", "nah"
    
        Case Else
    
    End Select
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    73

    Re: Case Statement Issue VS 2010 Plz Help

    Thank you - Solved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width