devxlogo

Always Use Case Else With Select Case

Always Use Case Else With Select Case

Select Case statements can lead to errors when the test expression in the Select Case line doesn’t yield a true result for any of its individual Case expressions. Therefore, you should always use a Case Else as the final Case within a Select Case statement. This sample raises a custom error when an application invokes the Select Case statement with an operation other than the four basic ones:

 Select Case Operation	Case "Addition"		Computer2 = dblNumber1 + _			dblNumber2	Case "Subtraction"		Computer2 = dblNumber1 - _			dblNumber2	Case "Multiplication"		Computer2 = dblNumber1 * _			dblNumber2	Case "Division"		Computer2 = dblNumber1 / _			dblNumber2	Case Else		Err.Raise 1, , "Wrong operation."End Select
See also  Small Business Strategies with Venmo
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist