Partial Class Example1_SelectCase Inherits System.Web.UI.Page ' Select Case Statement 'https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim varFirstName As String ' get textbox value and store in variable varFirstName = TextBox1.Text Select Case varFirstName Case "Bob" Label1.Text = "Hi Bob" Case "Beth" Label1.Text = "Hi Beth" Case "John" Label1.Text = "Hi John" Case "Billy", "Willy" Label1.Text = "Hi Billy or Willy" Case "Joe" Label1.Text = "Hi Joe" Case "Susan" Label1.Text = "Hi Susan" End Select End SubEnd Class
A Case statement with multiple clauses can exhibit behavior known as short-circuiting. Visual Basic evaluates the clauses from left to right, and if one produces a match with testexpression, the remaining clauses are not evaluated. Short-circuiting can improve performance, but it can produce unexpected results if you are expecting every expression in expressionlist to be evaluated.
Is it better to use an Or operator? How do I revise this case statement to use the Or operator instead?
Case "Billy", "Willy"
Label1.Text = "Hi Billy or Willy"
So if I type either Billy OR Willy then display "Hi Billy or Willy" on the label.