devxlogo

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

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

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.