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
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
Re: Case Statement Issue VS 2010 Plz Help
I put that under Case and it gave me an error
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
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
Re: Case Statement Issue VS 2010 Plz Help