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

Material Type: Notes; Class: INTRO COMPUTER PROGRMMNG-BASIC; Subject: Computer Science; University: University of Pittsburgh; Term: Summer 2009;

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-q6h
koofers-user-q6h 🇺🇸

9 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS#0004#–#Introduc/on#to#
Programming#
Using#Visual#Basic#
Summer#2009#
University#of#Pi@sburgh#
Lecture#5#
6/1/09# CS4#‐#Summer#2009#‐#Lecture#5# 1#
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

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"