Docsity

Notes on Select Case Statements - Introduction Computers Programming | CS 0004, Study notes of Computer Science

Partial preview of the text

Download Notes on Select Case Statements - Introduction Computers Programming | CS 0004 and more Study notes Computer Science in PDF only on Docsity!

CS 0004 – Introduc/on to

Programming

Using Visual Basic

Summer 2009

University of Pi@sburgh

Lecture 5

Chapter 4.

Select Case Statements

Example 1 – Form

txtPosi/on txtOutcome

Select Case Example 1

Private Sub btnEvaluate_Click(...) _ Handles btnEvaluate.Click Dim position As Integer = CInt(txtPosition.Text) Select Case position Case 1 txtOutcome.Text = "Win" Case 2 txtOutcome.Text = "Place" Case 3 txtOutcome.Text = "Show" Case 4, 5 txtOutcome.Text = "You almost placed in the money." Case Else txtBox.Text = "Out of the money." End Select End Sub

Example 1 – Code

Private Sub btnEvaluate_Click(...) _ Handles btnEvaluate.Click Dim position As Integer = CInt(txtPosition.Text) Select Case position Case 1 txtOutcome.Text = "Win" Case 2 txtOutcome.Text = "Place" Case 3 txtOutcome.Text = "Show" Case 4, 5 txtOutcome.Text = "You almost placed in the money." Case Else txtBox.Text = "Out of the money." End Select End Sub Selector

Value Lists

Example 1 – Output

Example 2 – Output

Select Case Syntax

The general form of the Select Case block is

Select Case selector

Case valueList

action

Case valueList

action

Case Else

action of last resort

End Select

Flow Chart for Select Case

Chapter 4.

ANSI Values

Rela/onal and Logical Operators

Boolean Values

ANSI Character Set

• A numeric representa/on for every key on the

keyboard and for other assorted characters.

ANSI Character Set

• A numeric representa/on for every key on the

keyboard and for other assorted characters.

• See Appendix A

• Also known as ASCII

Asc Func/on

For a string str ,

Asc(str)

is ANSI value of the first character of str.

EXAMPLES: Asc("A") is 65

Asc("¢25") is 162

ANSI Examples

• txtBox.Text = Chr(65)a

– This will display ‘A’ in the txtBox

• Why do I care? I could just do:

– txtBox.Text = "A"