Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:46:43+00:00 2026-05-17T15:46:43+00:00

So I have case statements grouped together here, but I have a few case

  • 0

So I have case statements grouped together here, but I have a few case statements that need extra decision based on a second variable after the original case is confirmed.

This is what I have now:

Case "PRIVATE_PARTY"
    If Condition = KBB_CONDITION_EXCELLENT Then
        Vehicle.MarketValue = Response.PrivatePartyExcellent
    ElseIf Condition = KBB_CONDITION_GOOD Then
        Vehicle.MarketValue = Response.PrivatePartyGood
    Else
        Vehicle.MarketValue = Response.PrivatePartyFair
    End If

Is it possible to add an “and” statement to some of the cases like this and have the code work in the same fashion?

Case "TRADE_IN" And Condition = KBB_CONDITION_EXCELLENT
    Vehicle.MarketValue = Response.TradeInExcellent

And then just have 3 case statements instead of one but the code wouldn’t look ugly. By the way Condition is declared instead the same select.

  1. Would this work?
  2. Is there any reason why I shouldn’t use this if it does work?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:46:43+00:00Added an answer on May 17, 2026 at 3:46 pm

    Short Answer

    The code might compile, but it will be wrong. Don’t try to use Select Case like this! I explain why below.


    Long Answer

    Select Case in VB.NET is basically a glorified If/ElseIf/etc. (it is not semantically the same as a switch). So attempting to write your code this way would actually offer no real benefit over writing the equivalent code using If, ElseIf, etc.

    That said, the below does compile with Option Strict Off and Option Infer On using VB 9.

    Note: I am not saying this will “work” just because it compiles. The point I am in the process of making here is that just because code compiles, that doesn’t mean it does what you expect. Again: this compiles, but it will not work. Don’t use it.*

    Select Case s
        Case "Private Party" AndAlso i = 1
            Console.WriteLine(1)
        Case "Trade In" AndAlso i = 2
            Console.WriteLine(2)
    End Select
    

    The question is: what does it compile to?

    Cracking open the code in Reflector, here’s what you see:

    Dim VB$t_string$L0 As String = s
    If (VB$t_string$L0 = Conversions.ToString((Conversions.ToBoolean("Private Party") AndAlso (i = 1)))) Then
        Console.WriteLine(1)
    ElseIf (VB$t_string$L0 = Conversions.ToString((Conversions.ToBoolean("Trade In") AndAlso (i = 2)))) Then
        Console.WriteLine(2)
    End If
    

    So the VB compiler interprets "Private Party" AndAlso i = 1 as a Boolean, which it will then convert to a String (either “True” or “False”) in order to compare it to s.

    In other words, this isn’t going to work the way you want it to. I’d honestly just go for the If/ElseIf block; it would be easier to read (in my opinion).

    *You probably already understood the point I was making; I just wanted to make it 100% clear 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a switch statement that has over 300 case statements. case 'hello': {
I have tried this in multiple ways: if-then-else, guards, case statements but I never
I have this huge switch case with nested switch case statements in it that
In the method below there are numerous case statements (many have been removed) that
Ok here I have a switch case statement which is falling through and trying
I have some SQL that does an order by case statement. It works fine.
I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
Thank you to everyone who tries to help! I have 2 case select statements
I have a question about case statements and nulls in a where clause. I
I have a query that looks something like this: select xmlelement(rootNode, (case when XH.ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.