Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb .net, select statement, default

Tags:

vb.net

In C I can assign default to some existing switch entry:

switch(c) {

default :
case 1:

       break;

case 2 :


      break;   

}

Is there a similar possibility in VB's select statement?

like image 352
user1797147 Avatar asked Dec 05 '12 09:12

user1797147


2 Answers

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
like image 53
Ravindra Bagale Avatar answered Sep 28 '22 02:09

Ravindra Bagale


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#

like image 23
LonWolf Avatar answered Sep 28 '22 01:09

LonWolf