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 3318846
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:45:17+00:00 2026-05-17T22:45:17+00:00

I have a webpage that needs to selectively show or hide a substantial number

  • 0

I have a webpage that needs to selectively show or hide a substantial number of controls. Each control’s visibility is determined based on which of 3 conditions are true.

So, for example, given the conditions A, B, and C;

  • Control1 needs to be visible only when A and B are true and C is false.
  • Control2 needs to be visible only when B and C are true and A is false.
  • Control3 needs to be visible only when A and C are true and it doesn’t care what B is.
  • and so on…

If each control looked at every condition, the control logic would be ugly, but doable.

If A Then
    If B Then
        If C Then

        Else

        End If
    Else
        If C Then

        Else

        End If
    End If
Else
    If B Then
        If C Then

        Else

        End If
    Else
        If C Then

        Else

        End If
    End If
End If

But unfortunately, when you mix in the fact that many controls only care about 1 or 2 of the 3 conditions, the code starts to grow into a maintenance nightmare. Here are all 26 of the possible conditions:

A   False   B   Any     C   Any  
A   True    B   Any     C   Any  
A   Any     B   Any     C   False
A   False   B   Any     C   False
A   True    B   Any     C   False
A   Any     B   Any     C   True 
A   False   B   Any     C   True 
A   True    B   Any     C   True 
A   Any     B   False   C   Any  
A   False   B   False   C   Any  
A   True    B   False   C   Any  
A   Any     B   False   C   False
A   False   B   False   C   False
A   True    B   False   C   False
A   Any     B   False   C   True 
A   False   B   False   C   True 
A   True    B   False   C   True 
A   Any     B   True    C   Any  
A   False   B   True    C   Any  
A   True    B   True    C   Any  
A   Any     B   True    C   False
A   False   B   True    C   False
A   True    B   True    C   False
A   Any     B   True    C   True 
A   False   B   True    C   True 
A   True    B   True    C   True 

Is there a better pattern to handle checking for multiple conditions?

Edit:
I had started going down the road that Marcelo Cantos suggested, but my A, B, and C conditions are quite long. So I made a helper function:

Dim isMatch = Function(A As Boolean?, B As Boolean?, C As Boolean?) As Boolean
        Return (Not A.HasValue OrElse A.Value = SomeLongConditionA) _
        AndAlso (Not B.HasValue OrElse B.Value = SomeLongConditionB) _
        AndAlso (Not C.HasValue OrElse C.Value = SomeLongConditionC)
    End Function

Control1.Visible = isMatch(True, True, False)
Control2.Visible = isMatch(False, True, True)
Control3.Visible = isMatch(True, Nothing, True)
  • 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-17T22:45:18+00:00Added an answer on May 17, 2026 at 10:45 pm
    Control1.Visible = A And B And Not C
    Control2.Visible = Not A And B And C
    Control3.Visible = A And C
    ...
    

    Note that this form looks like the description of the rules you provided. This is a good way to think about most problems: “How can I make the code look like my description of the problem?”

    EDIT: If A, B and C represent long-winded expressions, you don’t have to copy-paste those expressions onto every line, or write a helper function. Just pre-compute the values:

    Dim A As Boolean = SomeLongConditionA
    Dim B As Boolean = SomeLongConditionB
    Dim C As Boolean = SomeLongConditionC
    
    Control1.Visible = A And B And Not C
    ...
    

    Also note that this will be much faster than the helper function, which saves on typing but still evaluates the conditions many times over.

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

Sidebar

Related Questions

No related questions found

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.