Tuesday, March 22, 2022

Switch function

Evaluates a list of expressions and returns a Variant value or an expression associated with the first expression in the list that is True.

Syntax

Switch( expr-1, value-1 [, expr-2, value-2 ] … [, expr-n, value-n ] )

The Switch function syntax has these arguments:

Argument

Description

expr

Required. Variant expression you want to evaluate.

value

Required. Value or expression to be returned if the corresponding expression is True.

Remarks

The Switch function argument list consists of pairs of expressions and values. The expressions are evaluated from left to right, and the value associated with the first expression to evaluate to True is returned. If the parts aren't properly paired, a run-time error occurs. For example, if expr-1 is True, Switch returns value-1. If expr-1 is False, but expr-2 is True, Switch returns value-2, and so on.

Switch returns a Null value if:

  • None of the expressions is True.

  • The first True expression has a corresponding value that is Null.

Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.

Query example

Expression

Results

SELECT ProductSales.ProductID, Switch([ProductID]="PRO_XYZ1","First",[ProductID]="PRO_XYZ2","Two",[ProductID]="PRO_XYZ1","Ten") AS testSwitch FROM ProductSales;

Returns the "ProductID", evaluates the expressions in "Switch" formula and switches the existing values with defined values for all the "True" expressions. For example: "PRO_XYZ1" is replaces by "First", "PRO_XYZ2" is replaces by "Two" and so on.

VBA example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the Switch function to return the name of a language that matches the name of a city.

Function MatchUp (CityName As String)
Matchup = Switch(CityName = "London", "English", _
CityName = "Rome", "Italian", _
CityName = "Paris", "French")
End Function

4 comments:

  1. Investing online has been a main source of income, that's why knowledge plays a very important role in humanity, you don't need to over work yourself for money.All you need is the right information, and you could build your own wealth from the comfort of your home!Binary trading is dependent on timely signals, assets or controlled strategies which when mastered increases chance of winning up to 90%-100% with trading. It’s possible to earn $10,000 to $20,000 trading weekly-monthly in cryptocurrency(bitcoin) investment,just get in contact with Mr Bernie Doran my broker. I had almost given up on everything about binary trading and never getting my lost funds back, till i met with him, with his help and guidance now i have my lost funds back to my bank account, gained more profit and I can now trade successfully with his profitable strategies and software!!
    Reach out to him on Telegram: @bernie_doran_fx or +1(424)285-0682 for inquires

    ReplyDelete
  2. Special thanks to HACK VANISH, a professional hacker I’ve been hiring for the past 2 years because, I find him to be an outstanding hacker who has aided me in various hacking related issues, ranging from fixing my poor FICO credit score of about 437 TransUnion, 462 Equifax to 802 plus excellent score, tracking my cheating husband’s phone and currently has helped me recover my lost crypto funds from an online scam investment I recently ventured into, I must confess he is the best, quite brilliant, ever since I discovered him through a positive review I saw on Wallet Hub and reached out to him via Email: Hackvanish @ Gmail. com, and Phone: +1(747) 293-8514, to which he responded in less than 10mins, I have never regretted working with him, he’s been quite helpful and highly efficient. I Would recommend his services to anyone without hesitation.

    ReplyDelete
  3. I invested $95,420 in Bitcoin trading from an unregulated broker, I feel agitated about my situation, even find my life in a difficult time to make withdrawal from my account, I Saw a post about An online fund charge back recovery company going through some page here on this platform, at *www thedailychargeback com* ,I gave them all the information they needed to place the recovery. To my surprise I successfully got my funds off that broker confirming the payment on my wallet account, I highly recommend their service to others.

    ReplyDelete
  4. All thanks to Mr Anderson Carl for helping with my profits and making my fifth withdrawal possible. I'm here to share an amazing life changing opportunity with you. its called Bitcoin / Forex trading options. it is a highly lucrative business which can earn you as much as $2,570 in a week from an initial investment of just $200. I am living proof of this great business opportunity. If anyone is interested in trading on bitcoin or any cryptocurrency and want a successful trade without losing notify Mr Anderson Carl now on Whatsapp: +1(252)285-2093 Email: andersoncarlassettrade@gmail.com

    ReplyDelete