Microsoft Visual Basic 2005 Reloaded Second Edition Chapter
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 6 String Manipulation and More Controls Microsoft Visual Basic 2005: Reloaded, Second Edition
Comparing Strings • String. Compare method: compares two strings • string 1, string 2 arguments: the two strings to be compared • ignore. Case argument: a Boolean value indicating whether to perform a case-sensitive or caseinsensitive search Microsoft Visual Basic 2005: Reloaded, Second Edition 2
Comparing Strings (continued) • String. Compare returns an integer result: – Returns 0 when string 1 equals string 2 – Returns 1 when string 1 > string 2 – Returns -1 when string 1 < string 2 • String. Compare uses word sort rules: – Numbers are less than lowercase letters – Lowercase letters are less than uppercase letters Microsoft Visual Basic 2005: Reloaded, Second Edition 3
Comparing Strings (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 4
Comparing Strings (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 5
Comparing Strings (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 6
Comparing Strings (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 7
The Like Operator • Like operator: – Uses pattern-matching characters to determine if one string is equal to another – Returns a Boolean value (True/False) • pattern argument: contains one or more patternmatching characters • string argument: the string to be evaluated Microsoft Visual Basic 2005: Reloaded, Second Edition 8
The Like Operator (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 9
The Like Operator (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 10
The Like Operator (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 11
The Like Operator (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 12
The Like Operator (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 13
The Like Operator (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 14
More Controls • Text. Box control: – Advantage: can accept any data the user enters – Disadvantage: application must validate the input • Controls other than text boxes allow the user to select a value instead of typing a value – Eliminate some or all of the input validation Microsoft Visual Basic 2005: Reloaded, Second Edition 15
Using Radio Buttons • Radio. Button tool: creates a Radio. Button control • Radio. Button control: allows the user to select only one of a group of two or more choices • Radio. Button choices are related but mutually exclusive – only one can be selected • Container control: – Isolates a group of radio buttons – Includes Group. Box, Panel, and Table. Layout controls Microsoft Visual Basic 2005: Reloaded, Second Edition 16
Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 17
Using Radio Buttons (continued) • Minimum number of radio buttons in a group is 2 – Must select a radio button to deselect another radio button • Recommended maximum number in a group = 7 • Windows standard is to set one as the default radio button – Shows as selected when the screen appears – Should be the most likely selection or the first radio button Microsoft Visual Basic 2005: Reloaded, Second Edition 18
Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 19
Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 20
Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 21
Using Radio Buttons (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 22
Using Check Boxes • Check. Box tool: creates a Check. Box control • Check. Box control: – Allows a user to select or deselect a choice – Each choice is independent of the others, so any number can be selected Microsoft Visual Basic 2005: Reloaded, Second Edition 23
Using Check Boxes (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 24
Using Check Boxes (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 25
Using Check Boxes (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 26
Using Check Boxes (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 27
Using Check Boxes (continued) Microsoft Visual Basic 2005: Reloaded, Second Edition 28
Programming Tutorial Microsoft Visual Basic 2005: Reloaded, Second Edition 29
Programming Example Microsoft Visual Basic 2005: Reloaded, Second Edition 30
Summary • Length property: determines the number of characters in a string • Trim. Start and Trim. End methods: remove characters at beginning or end of a string • Remove method: removes one or more characters anywhere in the string • Replace method: replaces all occurrences of a sequence of characters with another sequence • Mid statement: replaces a specific number of characters with characters from another string Microsoft Visual Basic 2005: Reloaded, Second Edition 31
Summary (continued) • Pad. Left and Pad. Right methods: insert characters at beginning or end of a string • Insert method: inserts characters within a string • Starts. With and Ends. With methods: determines whether a string begins or ends with a specific sequence of characters • Contains method: determines if a string contains a specific sequence of characters • Index. Of method: finds the index of the start position of a specified sequence of characters Microsoft Visual Basic 2005: Reloaded, Second Edition 32
Summary (continued) • Substring method: accesses one or more characters contained in a string • String. Compare method: determines whether one string is equal to another • Like comparison operator: uses pattern-matching characters to determine whether one string is equal to another Microsoft Visual Basic 2005: Reloaded, Second Edition 33
Summary (continued) • Radio buttons: used for related but mutually exclusive choices – Only one of a group of radio buttons can be selected – Use container controls to group radio buttons • Checkboxes: used for independent and nonexclusive choices – Any number of checkboxes can be selected Microsoft Visual Basic 2005: Reloaded, Second Edition 34
- Slides: 34