120 likes | 212 Views
Chapter 2. Functions in Foxpro. Functions. Used to evaluate data and return a result can be assigned to a variable x = LEN(‘I LOVE U’) // x =8 can be used directly in a print command ? LEN(‘I LOVE U’) // 8 input: parameter and argument //’I LOVE U’
E N D
Chapter 2 Functions in Foxpro Foxpro Chap. 2 Functions
Functions • Used to evaluate data and return a result • can be assigned to a variable • x = LEN(‘I LOVE U’) // x =8 • can be used directly in a print command • ? LEN(‘I LOVE U’) // 8 • input: parameter and argument //’I LOVE U’ • output: return as a single value //8 Foxpro Chap. 2 Functions
Commonly used functions • Character processing • Numeric processing • Date processing • Logical processing Foxpro Chap. 2 Functions
Functions forCharacter Processing(1) • LEN(‘ABC’) // 3 • UPPER(‘Au’) // ‘AU’ • LOWER(‘Au’) // ‘au’ • PROPER(‘AU wan’) // ‘Au Wan’) • SPACE(3) // ‘ ’ • LTRIM(‘ abc’) // ‘abc’ • RTRIM(‘abc ’ ) // ‘abc’ • ALLTRIM(‘ abc ’ ) // ‘abc’ Foxpro Chap. 2 Functions
Functions forCharacter Processing(2) • LEFT(‘ABCDE’, 2) // ‘AB’ • RIGHT(‘ABCDE’, 2) // ‘DE’ • SUBSTR(‘ABCDE’, 2, 3) // ‘BCD’ • STUFF(‘ABCDE’, 2, 3, ‘X’) // ‘AXE’ • STUFF(‘ABCDE’, 2, 0, ‘X’) // ‘AXBCDE’) • STUFF(‘ABCDE’, 2, 3, ‘’) // ‘AE’ • STUFF(‘ABCDE’, 7, 3, ‘X’) // ‘ABCDEX’ Foxpro Chap. 2 Functions
Functions forCharacter Processing(3) • AT(‘CD’, ‘ABCDE’) // 3 • AT(‘CE’, ‘ABCDE’) // 0 • VAL(‘123’) // 123 • ‘123’ + ‘45’ // ‘12345’ • VAL(‘123’) + VAL(‘45’) // 168.00 • STR(123) // ‘123’ • STR(123, 6, 2) // ‘123.00’ • ASC(‘ABC’) // 65 • CHR(65) // ‘A’ Foxpro Chap. 2 Functions
Functions forNumeric Processing • ABS(-123) // 123 • ROUND(123.45, 1) // 123.5 • P.63 ROUND(numExp, numExp) • INT(456.78) // 456 • CEILING(456.78) // 457 • FLOOR(456.78) // 456 • MOD(20, 7) // 6 • SQRT(10) // 3.16 Foxpro Chap. 2 Functions
Functions forDate Processing(1) • DATE() // today • DAY({04/23/2003}) // 23 • DOW({04/23/2003}) // 4 • note: 1st day of week is Sunday • CDOW({04/23/2003}) // Wednesday Foxpro Chap. 2 Functions
Functions forDate Processing(2) • MONTH({04/23/2003}) // 4 • CMONTH({04/23/2003}) // April • YEAR({04/23/2003}) // 2003 • YEAR({04/23/03}) // 1903 • CTOD(‘01/23/00’) //{01/23/1900} • CTOD(‘01#23#00’) // { / / } • DTOC({01/23/00}) // ‘01/23/1900’ Foxpro Chap. 2 Functions
Functions forLogical Processing • IIF(condition, exp1, exp2) • IIF(1=2, ‘abc’, ‘xyz’) // ‘xyz’ • IIF(1=1, ‘abc’, ‘xyz’) // ‘abc’ Foxpro Chap. 2 Functions
More on Functions • What are the arguments in the function STUFF(‘ABCDE’, 2, 3, ‘FG’) • What is the output? • What is the output of SUBSTR(‘Amoy Garden’, address) Foxpro Chap. 2 Functions
Exercise • Do Ex. 1 to 15 on P.64 - 68 and get a feel of the pitfalls that comes with some of the questions. Foxpro Chap. 2 Functions