vb .net, select statement, default

Select Object.Name.ToString()
    Case "Name1"
        'Do something
    Case "Name2"
        'Do something else
    Case Else
        'Do the default action
End Select

This question is the exact opposite of VB.NET Select...Case Statement Equivalent in C#


use case Else , it is same as default of c syntax:

Select [ Case ] testexpression
    [ Case expressionlist
        [ statements ] ]
    [ Case Else
        [ elsestatements ] ]
End Select

e.g.

creamcake = TextBox1.Text

Select Case creamcake

Case "Eaten"
DietState = "Diet Ruined"
Case "Not Eaten"
DietState = "Diet Not Ruined"
Case Else
DietState = "Didn't check"
End Select

if you want to assign more than one case then example

Select Case agerange

Case 16 To 21
MsgBox “Still Young”
Case 50 To 64
MsgBox “Start Lying”

End Select

Tags:

Vb.Net