1 / 12

CS0004: Introduction to Programming

CS0004: Introduction to Programming. Select Case Statements and Selection Input. Review. A condition is either… True or False Relational Operators = <> < > <= >= Logical Operators And Or Not. Select Case Statements.

carr
Download Presentation

CS0004: Introduction to Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS0004: Introduction to Programming Select Case Statements and Selection Input

  2. Review • A condition is either… • True or False • Relational Operators • = • <> • < • > • <= • >= • Logical Operators • And • Or • Not

  3. Select Case Statements • Sometimes you want to check if a variable is one of many values. You can do this with If statements: Dim a As Integer If a = 1 Then ‘do something ElseIf a = 2 Then ‘do something ElseIf a = 3 Then ‘do something Else ‘do something • However, you can use select case statements, instead to form a more logical decision structure Dim a As Integer Select Case a Case 1 ‘do something Case 2 ‘do something Case 3 ‘do something Case Else ‘do something End Select

  4. Select Case Statements • General Form Select Case selector Case valueList1 action1 Case valueList2 action2 Case Else actionOfLastResort End Select • The value lists can be literals, variables, expressions, or a range in the form a To b where a and b are literals, variables, or expressions. • Value lists can also be multiple values separated by a comma, for instance you can have: Case 1, 2, 5 • This case will be executed if the selector is either 1, 2 or 5

  5. Select Case Examples • New Topics: • Select Case Statements • Ranges

  6. Selection Input • Some controls in VB ask the user to make selections from multiple choices. Some Examples are: • Radio Buttons • Check Boxes • List Boxes • Radio buttons and check boxes can be grouped together using group boxes. • If controls are inside of a group box, it is said that the controls are attached to the group box. • If multiple radio buttons are in the same group box, only one of them can be selected at a time.

  7. Radio Buttons • Radio buttons are controls that when grouped, only one can be checked (selected) at a time. • Radio buttons default event procedure is CheckedChanged • This event happens when a radio button is either first checked or unchecked. • Radio buttons have a property called Checked that holds the boolean value of whether the box is checked or not. radButton.Checked • You can set whether a radio button is checked or not checked with this property radButton.Checked = True radButton.Checked = False

  8. Select Case Statement with Radio Buttons Example • New Topics: • Radio Buttons • CheckChanged Event Procedure • Checked Property

  9. List Boxes • An input box is a list of strings in which each can be selected. • We have added items to the list and cleared the list in previous examples lstTheList.Items.Add(parameter) lstTheList.Items.Clear() • You can also add items to the list box at design time in Visual Studio. • Click the task button (the triangle) on the control in Visual Studio. • Click on “Edit Items” on the menu that appears • Add each item in a single line in the dialog box. • Click “OK” • You can access the item currently selected by using the Text property of the list box. • The list box default event procedure is SelectedIndexChanged. This means that the item that is selected has changed.

  10. List Box Example • New Topics: • List Box • Design time list items

  11. Check Boxes • Check boxes are like radio buttons, but multiple check boxes can be checked at once. • They also have a checked property chkTheCheckBox.Checked • The default event procedure for a check box is CheckChanged

  12. Check Box Example • New Topics: • Check Boxes • Font Property • Font Class • New Keyword

More Related