Download presentation
Presentation is loading. Please wait.
1
On to… string operations & functions
2
Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate the strings: c = “23” d = “skidoo” e = c & d Picture1.Print e;”!” 23skidoo!
3
Relating characters & digits §Text boxes can contain only string data, so we must make use of special Visual Basic functions if we want to use this data in a numeric sense. l We know these... Val (“123”) returns the number 123 Str (123) returns the string “123” l These are new... Asc (“A”) returns the number 65 Chr (65) returns the string “A”
4
Categories of string functions §We have 3 categories of string functions: l Format functions l Those that return a string type result l Those that return a numeric type result Let’s see...
5
The Format Function §Used to format the display of numeric output data and dates: formatspecifier (num, decplaces) A numeric value or string representation of a numeric value or date; may be a variable An integer that specifies the desired number of decimal places; if omitted, the default value is 2
6
Examples FormatNumber (12345.628) FormatCurrency (12345.628) FormatNumber (12345.628,0) FormatPercent (12345.6283,1) Format (12345,” @@@@@@@@ ”) Format (12345,” @@@@@@@@@ ”) 12,345.63 $12,345.63 12,346 1234562.8% bbb12345 bbbb12345
7
Formatting Dates FormatDateTime(“2/5/01”, vbLongDate) Friday, February 5, 2001
8
String functions that return string results §These require different numbers of input values but they all return exactly one output value that is character string type: l Left (string, integer_value) l Right (string, integer_value) l Mid (string, integer_value, integer_value) l UCase (string) l Trim (string)
9
Examples Left (“abcdefg”, 4) returns “abcd” Right (“abcdefg”, 2) returns “fg” Mid (“abcdefg”, 3, 2) returns “cd” UCase (“abCd7f*”) returns “ABCD7F*” Trim (“ abcdefg ”) returns “abcdefg”
10
String functions that return numeric results §These each receive character string input values and return a unique numeric output value: Len (string) InStr (string1, string2)
11
Examples Len (“abcdefg”) returns 7 InStr (“abcdefg”, “de”) returns 4 Len (text1.text) returns the length of the input string
12
Lab §Page 133 # 130 (But input only one word, and replace one character in that word with another character) §Page 133 #131
13
Homework Due Next Tuesday §Page 135 # 138 §Page 133 # 130 (As stated in the book)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.