Questions tagged [select-case]
164 questions
134
votes
14 answers
JavaScript: using a condition in switch case
How can I use a condition inside a switch statement for JavaScript?
In the example below, a case should match when the variable liCount is <= 5 and > 0; however, my code does not work:
switch (liCount) {
case 0:
setLayoutState("start");
…

haemse
- 3,971
- 5
- 28
- 40
55
votes
3 answers
What is the equivalent of Select Case in Access SQL?
I have a query which includes fields named openingbalance and commissions. I would like to compute values for commissions based on openingbalance, similar to this Select Case block in Access VBA:
Select Case OpeningBalance
Case 0 To 5000
…

Kelly K.
- 567
- 2
- 5
- 9
42
votes
5 answers
Select Case on an object's type in VB.NET
I'm not sure if this valid C#, but hopefully you get the idea. :)
switch (msg.GetType()) {
case ClassA:
// blah
case ClassB:
// blah 2
case ClassC:
// blah 3
}
How would I switch on an object's type but using…

mcjabberz
- 9,788
- 10
- 36
- 38
26
votes
1 answer
Can you use .Contains(string) with a Select Case Statement?
Is there anyway I can build a Select statement that uses the Contains function? Like this:
Select commentStr
Case commentStr.Contains("10")
Case commentStr.Contains("15")

Lou
- 918
- 3
- 16
- 29
24
votes
2 answers
Why should I use exit select?
Here are a couple of questions I gathered regarding exit select...
Is there any reason for using exit select in VB.NET?
Does the reason have anything to do with performance?
Is the exit select equal to break;?
Example 1
Select case Name
case…

OrElse
- 9,709
- 39
- 140
- 253
17
votes
3 answers
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?

user1295053
- 303
- 1
- 7
- 17
13
votes
2 answers
Excel VBA: Select Case if ActiveCell like "*string*"
I'm working on a macro that takes the current value of the ActiveCell and changes that value based on a select case.
However, I am unable to determine if the ActiveCell contains a wild card string. I am not sure if my syntax is correct. How can I…

thedeepfield
- 6,138
- 25
- 72
- 107
10
votes
6 answers
Converting DayOfWeek enum to a string repesenting the day
I was wondering if there was a way to directly convert the integer DayOfWeek returns into a string representing the day like Monday, Tuesday etc.
Sample code:
MessageBox.Show(Date.Today.DayOfWeek)
This will return 6 (as of today). Is there a way to…

James
- 139
- 2
- 3
- 7
10
votes
3 answers
How can you use COUNT() in a comparison in a SELECT CASE clause in Sql Server?
Let's say you want do something along the following lines:
SELECT CASE
WHEN (SELECT COUNT(id) FROM table WHERE column2 = 4) > 0
THEN 1 ELSE 0 END
Basically just return 1 when there's one or more rows in the table, 0 otherwise. There has…

Panzercrisis
- 4,590
- 6
- 46
- 85
8
votes
5 answers
C# Switches vs. VB Case Statements
I recently switched from VB to C#. One thing that I noticed was that in C#, I have problems using comparisons as part of the case. I am not sure how to explain it in words, so here is an example of what I am trying to do.
In VB, my code looks like…

user2763890
- 85
- 2
- 6
7
votes
2 answers
VB.net Select Case Statement with Beginswith
Is there a way to use the Select Case statment in VB.net for beginswith? Or do i have to use a long elseif? Example:
If text.StartsWith("/go") then
elseif test.StartsWith("/stop")
elseif test.StartsWith("/continue")
End If
But instead something…

James T
- 3,292
- 8
- 40
- 70
6
votes
2 answers
Select Case Not Or
I'm looking to carry out a Select Case with just one case - where the case is not equal to "P", "Ev" or "Af".
This is what I have so far.
Select Case Range("my_range").Offset(0, column_offset).Value
Case Not "P", "Ev", "Af"
'my code
End…

tom_j_uk
- 147
- 1
- 2
- 7
6
votes
3 answers
How to sense parameters with Case
I'm trying to create a series of commands that can take parameters. To pick up each separate command I am using Select Case The problem with this is I can't sense the 'parameters' (the second part of the string) if I use Case Else. If I don't use…

08robertsj
- 344
- 3
- 5
- 17
6
votes
7 answers
Ending a Case Early
So I have something like the following in Vb6;
Select case Case
case "Case0"
...
case "Case1"
if Condition Then
Exit Select
End If
*Perform action*
case "Case2"
...
End Select
But for some reason my Exit Select throws the error…

windowsgm
- 1,566
- 4
- 23
- 55
5
votes
3 answers
Select Case With Conditions ( Classic ASP)
<%
i=2
Select Case i
Case 1,2,3,4,5,7,8,9,10
response.write("Grade A")
Case 11,12,13,14,15,16,17,18,19,20
response.write("Grade B")
Case 21,22,23,24,25,26,27,28,29,30
response.write("Grade C")
Case…

Skullcandy
- 77
- 1
- 1
- 4