Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple select cases in VB.NET

I have tried the below:

Select Case Combo1.SelectedItem Or Combo2.SelectedItem

But I get the error:

Conversion from String "string here" to type 'Long' is not valid

Is it possible to have multiple select cases?

like image 442
user1295053 Avatar asked Dec 20 '12 10:12

user1295053


People also ask

What is the syntax for select case?

Syntax of Select Case Statement in VB.Netyour_expression: this denotes an expression which evaluates to one of the elementary Data Types supported in Microsoft VB.NET. expression_list: expression clauses that denote the match values for the expression. For the case of multiple clauses, separate them using a comma (,).

What is switch statement in Visual Basic?

In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via search and map.

Is VB.Net case sensitive?

Visual Basic is case-insensitive, but the common language runtime (CLR) is case-sensitive. For more information, see "Case Sensitivity in Names" in Declared Element Names. By default, this message is a warning.

What is while loop in Visual Basic?

It executes a series of statements as long as a given condition is True. The syntax for this loop construct is − While condition [ statements ] [ Continue While ] [ statements ] [ Exit While ] [ statements ] End While. Here, statement(s) may be a single statement or a block of statements.


1 Answers

You separate multiple values by using a comma:

Case Combo1.SelectedItem, Combo2.SelectedItem

Using Or would make it an expression that would be evaluated before compared to the value in the Select.

If your value in the Select is a Long value, then you may need to convert the strings from the controls:

Case CLng(Combo1.SelectedItem), CLng(Combo2.SelectedItem)

To address the question directly, using multiple values as a test expression in a select is not possible:

Select Case v1, v2 'Not possible
like image 184
Guffa Avatar answered Sep 21 '22 15:09

Guffa