From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Select case: A better way to branch

Select case: A better way to branch - Visual Basic Tutorial

From the course: Visual Basic Essential Training

Select case: A better way to branch

- [Speaker] In Visual Basic, the select case statement simplifies decision-making by evaluating an expression once and then executing the appropriate block of code based on matching conditions. It is a cleaner alternative to multiple if, else if statements. It is similar to the switch statement in languages like Java and PHP. So what we're going to do is get a sequence of numbers, one, two, three, four, and so on. And each time we get a number, we're going to run a select case on it. And the cases are listed here. So values one, two, and three will go in this first text box, five, seven, and nine in the next text box, four, six, and eight go in this text box, it allows me to check these different conditions in our select case. To add one to your code, type in the word select and then press the tab key twice. Visual studio uses what's called a code snippet. It's plugged in about six lines of code, and you'll notice that I can press the tab key to move to the yellow areas. Those are…

Contents