Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 14 / 68

The Select Case statement

This lesson covers branching on several conditions with VB.NET's Select Case, with the aim of organising conditions more readably than an If statement can.

Select Case ... Case ... Case Else ... End Select branches on several possible values. When one variable drives many branches, Select Case reads far better than a stack of If statements.

The sample code prints a different message from Case 1 to Case 3 depending on day, falling back to Case Else for anything else. For a multi-way branch on a single variable, Select Case simply looks tidier.

A common early stumble is not knowing that several values can share one Case, and writing the same work out repeatedly. Separating them with a comma, as Case 1, 2, gathers them into a single condition.

In professional work, Select Case is used wherever work is split across a fixed set of options — days of the week, status codes. Once you have three or more branches, it is worth converting from If.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)