Selection Structures ; String Functions - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Selection Structures ; String Functions

Description:

Use the Is keyword to specify a range of values when you don't know both the ... picOutcome.Print 'Congratulations!' Case Is 3. picOutcome.Print 'Not in the money' ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 14
Provided by: scie248
Learn more at: http://www.cs.uwyo.edu
Category:

less

Transcript and Presenter's Notes

Title: Selection Structures ; String Functions


1
Selection Structures String Functions
2
IfThenElse
  • If condition Then
  • instructions when the condition is true
  • Else
  • instructions when the condition is false
  • End If
  • If condition Then Else

3
Select Case selection structure
  • Select Case testexpression
  • Case expressionlist1
  • instructions for the first Case
  • Case expressionlist2
  • instructions for the second Case
  • Case expressionlistn
  • instructions for the nth Case
  • Case Else
  • instructions for the default case
  • End Select

4
  • Dim intPosition as Integer
  • intPosition Val(txtPosition.Text)
  • Select Case intPosition
  • Case 1
  • picOutcome.Print "Win"
  • Case 2
  • picOutcome.Print "Place"
  • Case 3
  • picOutcome.Print "Show"
  • Case 4, 5
  • picOutcome.Print Almost!"
  • Case Else
  • picOutcome.Print "Out of luck.
  • End Select

5
Is and To
  • Use the To keyword to specify a range of values
    when you know both the minimum and maximum values
    in the range.
  • Use the Is keyword to specify a range of values
    when you dont know both the minimum and the
    maximum values in the range.

6
  • Private Sub cmdDescribe_Click()
  • Dim intPosition as Integer
  • intPosition Val(txtPosition.Text)
  • Select Case intPosition
  • Case 1 To 3
  • picOutcome.Print "In the money."
  • picOutcome.Print "Congratulations!"
  • Case Is gt 3
  • picOutcome.Print "Not in the money"
  • End Select
  • End Sub

7
Select Case statements (cont.)
  • You can use multiple expressions or ranges in
    each Case clause.
  • Case 1 To 4, 7 To 9, 11, Is gt MaxNumber
  • Select Case statements can be nested.

8
UCase Function
  • Returns a string containing the specified string,
    converted to uppercase.
  • Syntax
  • UCase(string)
  • Examples
  • Dim strConvert, strTemp As String
  • strTemp ants
  • strTemp UCase(strTemp)
  • strConvert UCase(Allyson)

9
LCase Function
  • Returns a string that has been converted to
    lowercase.
  • Syntax
  • LCase(string)
  • Examples
  • Dim strConvert, strTemp As String
  • strTemp Ronald McDonald
  • strTemp Lcase(strTemp)
  • strConvert LCase(Allyson)

10
Len Function
  • Returns a Long containing the number of
    characters in a string.
  • Syntax
  • Len(string or variablename)
  • Example
  • MyString "Hello World"
  • MyLen Len(MyString) 'Returns 11.

11
Left Function
  • Returns a Variant (String) containing a specified
    number of characters from the left side of a
    string.
  • Syntax
  • Left(string, length)
  • Examples
  • AnyString "Hello World"
  • MyStr Left(AnyString, 1)
  • MyStr Left(AnyString, 7)

12
Right Function
  • Returns a string containing a specified number of
    characters from the right side of a string.
  • Syntax
  • Right(string, length)
  • Examples
  • AnyString "Hello World
  • MyStr Right(AnyString, 1)
  • MyStr Right(AnyString, 6)

13
Mid Function
  • Returns a string containing a specified number of
    characters from a string.
  • Syntax
  • Mid(string, start, length)
  • Examples
  • MyString "Mid Function Demo
  • FirstWord Mid(MyString, 1, 3)
  • LastWord Mid(MyString, 14, 4)
  • MidWords Mid(MyString, 5)
Write a Comment
User Comments (0)
About PowerShow.com