Programming | | Notes on SELECT CASE Control Structure and MessageBox.Show: |
The SELECT CASE Control Structure: is a conditional structure like the IF statement, but allows for more than two alternative paths when the condition is evaluated. The CASE structure serves as an alternative for the nested IFTHENELSE control structure; it cannot be used in place of a sequential IFTHENELSE. Note that while there may be several case statements in a structure, only one case will be executed. Regardless of which case the path takes, there will only be one common exit point from the logic structure. The SELECT CASE Pattern: As you can view below, the Select Case structure flowchart path is compared to the expression that follows the word Case in the block (expression 1, expression 2, expression 3, and so on). In this example the text expression will match one of the (statement block or processing) expressions associated with the Case clause and execution will follow.
The Visual Basic SELECT CASE: The Select Case structure works best with the ComboBox. With a list of predefined expressions in a ComboBox, the program then can be coded in a manner that automatically has all of the expressions defined in the code. Displaying a Message Box: In your last example problem you were given a generic and older method in writing the code to display a message box. To review this again, you now will see the newest method in programing a Message Box Caption. Again, a message box can be displayed during run time with a variety of arguments. There are four parts to a message box. Below is the General Format for a message box statement with Caption, buttons, and icon with a review of the structure. If you just enter the following: MessageBox.Show("Combo Box Item is Missing"), this will display a message box.
This first argument would show a message box with just a message and the default OK button. In a Window Application program a message box always will be supportive of a button. If you do not place the arguments of a button it will automatically apply this one (the "OK" button). Below is an example of what would be supportive of the message box. If you just enter the following: MessageBox.Show("Combo Box Item is Missing", "User Combo Box Error"), this will display another message box again.
Notice we have added the Caption to the code. The second argument will add and give further information to the user's title of this message box. Also note the OK button is still supportive in the message box. If you now enter the following: MessageBox.Show("Combo Box Item is Missing", "User Combo Box Error", MessageBoxButtons.OKCancel), this will display a message box. Now notice that there are two buttons; an OK and a Cancel button. The third argument represents the buttons that can be displayed on the message box. To change the general format button command type from OK to another button type, it would occur here. Below is also a list that reviews the different arguments for the different buttons that could be displayed on the message box. When working your next example problem try switching these arguments around so you can review the different buttons. If you enter the final argument to a message box: MessageBox.Show("Combo Box Item is Missing", "User Combo Box Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error), this will display a message box again. Now you will see an icon on the message box. The fourth and last argument represents the icons. changing the general format of an icon to another type would occur here. Again if you do not support an icon argument then a message box will not have one. Please review the different icons listed below. When working your next example problem try switching these icon arguments around so you can review the different icons.
Example #10 Simulation (Message Box and SELECT CASE Control Structure):
Example #10 Simulation : As you can see below the purpose of this example problem is to create a program for your school's concession stand. As you select one of the five items and the number of items followed by the ENTER button, this will display the total amount beside the item. This program is built to accept all items and unlimited number amounts. Once the order is completed if you select the Total Bill button it will display a person's total amount for the order, simply adding the total of all the items. Before you get start you will need to copy the following icon to your Module 4 folder. Simply click on the icon as and copy it and paste it in this project location. You must complete this step to import the icon to your form:
Data File needed for this Example problem:
Flowerbox Template: Put the flower box into the code as shown above.
Flowchart: Click Here to see the Flowchart for this Example problem 10. In addition to building this Visual Basic program you will also be asked to create and draw the flowchart for this program. Noticed that the Selected Case is nested in the false path of this ITTHENELSE structure.
The Desk Check - You will see four different desk check below. Once your program is running try to enter in the inputs to capture the output and screen shots for this example problem.
Teacher's Comments: This is one of your largest example problems to date which hopefully has provided much new information. As your program knowledge becomes more advanced you may find that using SELECT CASE Structure will involve less coding. This is a simple program that should give you the foundation of how the structure works. Please take the time to review the program and format.
Directions for turning in Example problem - In the classroom: In this example problem you will have a print code and the screen shot (snipping Tool) for Example Problem 10. Once you get this output try to use the Snipping program to copy the screen shots and put it in a Word Document. Example Problem 10 Program Form (during run time), Code, Flowchart Directions for turning in Example problem 10 - Virtual: Virtual No Printing just upload the assignment files to Canvas Module 4 Example Problem 10. You will NOT need to print out any documents just submit this example problem in the Canvas drop box. Note you should have three screen shots: Example 10 Code, and the Form (Run Time screen) and the If-Selected Case Flowchart. Put all screen shots (images) in a Word Document and send me the file. Save the Word document as the example problem: Example 10 and your first and last name. Please note, that you will need to re-save this file as a pdf file before uploading. Here is an example video on how to do that: See Video > > > How to save a Word file to a pdf right click mouse and select... (Open link in new tab) |