Microsoft Visual Basic 2010: Reloaded Fourth Edition - PowerPoint PPT Presentation

Loading...

PPT – Microsoft Visual Basic 2010: Reloaded Fourth Edition PowerPoint presentation | free to download - id: 49f1f4-ZjUwZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Microsoft Visual Basic 2010: Reloaded Fourth Edition

Description:

Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus * Microsoft Visual Basic 2010: Reloaded, Fourth Edition Summary (cont'd.) – PowerPoint PPT presentation

Number of Views:71
Avg rating:3.0/5.0
Slides: 35
Provided by: mywebAsta5
Learn more at: http://myweb.astate.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Microsoft Visual Basic 2010: Reloaded Fourth Edition


1
Microsoft Visual Basic 2010 Reloaded Fourth
Edition
  • Chapter Ten
  • String Manipulation and Menus

2
Objectives
  • After studying this chapter, you should be able
    to
  • Determine the number of characters in a string
  • Remove characters from a string
  • Insert characters in a string
  • Search a string
  • Access the characters in a string

3
Objectives (contd.)
  • Align the characters in a string
  • Compare strings using pattern-matching
  • Add a menu to a form
  • Code a menu items Click event procedure

4
Working with Strings
  • Most applications need to manipulate string data
    in some way
  • String properties and methods are used to
    manipulate string data

4
5
Determining the Number of Characters in a String
  • Length property stores the number of characters
    contained in a string as an integer value
  • Can be used with a String variable, a String
    named constant, or the Text property of a control

5
6
Figure 10-1 How to determine the number of
characters in a string
6
7
Removing Characters from a String
  • Computer first makes a temporary copy of the
    string in memory and operates on the copy only
  • Trim method removes one or more spaces from both
    the beginning and end of a string
  • Remove method removes a specified number of
    characters located anywhere in a string
  • Index an integer indicating the characters
    position in the string
  • The first character in a string has an index of 0

7
8
Removing Characters from a String (contd.)
  • Arguments
  • startIndex argument the index of the first
    character to be removed
  • numCharsToRemove argument number of characters
    to be removed
  • If omitted, all characters from the startIndex
    position through the end of the string are
    removed

8
9
Removing Characters from a String (contd.)
Figure 10-2 How to remove characters from a
string
9
10
Removing Characters from a String (contd.)
Figure 10-2 How to remove characters from a
string (contd.)
10
11
Inserting Characters in a String
  • Insert method used to insert characters anywhere
    within a string
  • Computer makes and operates on a temporary copy
    of the string
  • Arguments
  • startIndex specifies where in the string to
    insert the value
  • value the character(s) to be inserted

11
12
Inserting Characters in a String (contd.)
Figure 10-3 How to insert characters in a string
12
13
Searching a String
  • Contains method
  • Determines if a string contains a specific
    sequence of characters
  • Returns a Boolean value of True when the
    substring is contained in the string, and False
    if not
  • Performs a case-sensitive search
  • Arguments
  • subString represents the sequence of characters
    to be searched for

13
14
Searching a String (contd.)
  • IndexOf method returns an integer representing
    the location of a substring within a string
  • Performs a case-sensitive search
  • Arguments
  • subString sequence of characters to be searched
    for
  • startIndex the starting position for the search
    (zero-relative)

14
15
Figure 10-4 How to search a string
15
16
Figure 10-4 How to search a string (contd.)
16
17
Accessing the Characters in a String
  • Substring method accesses any number of
    characters contained in a string
  • Arguments
  • startIndex index of the first character to be
    accessed (zero-relative)
  • numCharsToAccess number of characters to be
    accessed

17
18
Accessing the Characters in a String (contd.)
Figure 10-5 How to access characters in a string
18
19
Aligning the Characters in a String
  • PadLeft method inserts characters at the
    beginning of a string
  • PadRight method inserts characters at the end of
    a string
  • Arguments
  • totalChars represents the total number of
    characters you want in the resulting string
  • padCharacter the character used to pad the
    string default value is the space character

19
20
Figure 10-6 How to align the characters in a
string
20
21
Using Pattern-Matching to Compare Strings
  • Like operator
  • Uses pattern-matching characters to determine if
    one string is equal to another
  • Returns a Boolean value (True/False)
  • Arguments
  • pattern contains one or more pattern-matching
    characters
  • characterList a listing of characters to be
    matched

21
22
Using Pattern-Matching to Compare Strings
  • Pattern-matching characters
  • ? Represents 1 character only
  • represents 0 or more characters
  • represents a single digit
  • Use square brackets to provide a list of
    characters to match
  • Use a hyphen between characters to specify a
    range of characters

22
23
Figure 10-7 How to use pattern-matching to
compare strings
23
24
Figure 10-7 How to use pattern-matching to
compare strings (cont'd.)
24
25
Adding a Menu to a Form
  • Menu strip control used to include one or more
    menus on a Windows form
  • Found in the Menus Toolbars section of the
    toolbox
  • Menu title appears on the menu bar at the top of
    the form
  • When clicked, the menu opens and displays a list
    of options called menu items
  • Clicking a menu item executes the command
    associated with it

25
26
Adding a Menu to a Form (contd.)
Figure 10-8 Location of menu elements
26
27
Adding a Menu to a Form (contd.)
  • Each menu element is considered an object
  • Each has a set of properties associated with it
  • Name property used to refer to the menu element
    in code
  • Text property stores the menu elements caption
    the text the user sees
  • Access key used in combination with the Alt key,
    will open the menu
  • Shortcut key allows the user to select the item
    without opening the menu

27
28
Adding a Menu to a Form (contd.)
Figure 10-9 Game menu
Figure 10-10 Exit commands Click event procedure
28
29
Programming Tutorial 1
  • Creating the Guess the Word Game Application

Figure 10-12 MainForm in the Guess the Word Game
application
29
30
Programming Tutorial 2
  • Creating the Bucky Burgers Application

Figure 10-22 MainForm for the Bucky Burgers
application
30
31
Programming Example
  • Yolanda Drapery Application

Figure 10-28 MainForm in the Yolanda Drapery
application
31
32
Summary
  • Use a menu strip control to add one or more menus
    to a form
  • Menu elements should have access keys
  • String manipulation techniques
  • Length property number of characters in the
    string
  • Trim method removes leading and trailing spaces
  • Remove method removes characters from a string
  • Insert method inserts characters into a string

32
33
Summary (cont'd.)
  • String manipulation techniques (contd.)
  • Contains method determines whether a specific
    sequence of characters appears in a string
    returns a Boolean value
  • IndexOf method determines whether a specific
    sequence of characters appears in a string
    returns the integer position where the sequence
    starts
  • Substring method accesses one or more characters
    in a string

33
34
Summary (cont'd.)
  • String manipulation techniques (contd.)
  • PadLeft method pads the beginning of a string
    with the specified character
  • PadRight method pads the end of a string with
    the specified character
  • Like operator uses pattern-matching to compare
    strings

34
About PowerShow.com