A function is built in feature that returns a predefined or performs some operation on data and returns the result in the specified form. The expression usually contain the value of a field or memory variable.
Different type of Visual FoxPro Function: There are Three types of Function. To display the result of function, use “?” (Print) sign before the function in Visual FoxPro command window.
A. Numeric Function: User can use the following numeric function on numeric data or to returns numeric data.
1. ABS( ): This function returns the absolute value of the numeric expression.
Example: A=12 [Enter] B=22 [Enter] ?ABS(A-B) [Enter] Will display: 10
2. INT( ): This function evaluates the numeric argument and returns the integer part of the numeric expression.
Example: ?INT(123.456) [Enter] Will display: 123
3. MAX( ): This function returns the highest value of the numeric expressions.
Example: ?MAX(12,45,78,33) [Enter] Will display: 78
4. MIN( ): This function returns the lowest value of the numeric expressions.
Example: ?MIN(12,45,78,33) [Enter] Will display: 12
5. MOD( ): This function returns the remainder value from a division problem.
Example: ?MOD(15,3) [Enter] Will display: 0
?MOD(15,4) [Enter] Will display: 3
6. ROUND( ): This function returns round number with specified number of decimal place.
Example: ?ROUND(123.456,2) [Enter] Will display: 123.46
?ROUND(123.456,-2) [Enter] Will display: 100
?ROUND(153.456,-2) [Enter] Will display: 200
7. SQRT( ): This function returns square root value
Example: ?SQRT(64) [Enter] Will display: 8.00
?SQRT(64.64) [Enter] Will display: 8.04
8. VAL( ): This function returns a numeric value from character string expression.
Example: ?VAL(“12AB13cD14″) [Enter] Will display: 12.00
?VAL(“AB13cD14″) [Enter] Will display: 0
B. Date & Time Function: This functions are convenient for displaying or printing the current time & date on reports.
*Date setup: SET DATE BRITISH [Enter]
1. CDOW( ): This function returns the day of the week in text form.
Example: ?CDOW({^1947/08/15}) [Enter] Will display: Friday
2. DOW( ): This function returns the day of the week as a number.
Example: ?DOW({^1947/08/15}) [Enter] Will display: 6
3. CMONTH( ): This function returns the month of the year in text form.
Example: ?CMONTH({^1947/08/15}) [Enter] Will display: August
4. MONTH( ): This function returns the month of the year as a number.
Example: ?MONTH({^1947/08/15}) [Enter] Will display: 8
5. YEAR( ): This function returns the year in number.
Example: ?YEAR({^1947/08/15}) [Enter] Will display: 1947
6. DAY( ): This function returns the day in number.
Example: ?DAY ({^1947/08/15}) [Enter] Will display: 15
7. GOMONTH( ): This function returns the date which is a certain number of months after or before the date expression.
Example: ?GOMONTH({^1947/08/15},3) [Enter] Will display: 15/11/1947
?GOMONTH ({^1947/08/15},-3) [Enter] Will display: 15/05/1947
8. DATE( ): This function returns the system date.
Example: ?DATE( ) [Enter] Will display: [System date]
9. TIME( ): This function returns the system time.
Example: ?TIME( ) [Enter] Will display: [System time]
10. SECOND( ): This function returns the system time in second.
Example: ?SECOND( ) [Enter] Will display: [System time in seconds]
11. DTOC( ): This function convert a date expression to character string.
Example: ?”Independence day is :-“+DTOC({^1947/08/15}) [Enter] Will Display: Independence day is :-15/08/1947
STORE DATE( ) to D [Enter] or D=Date( ) [Enter]
?”Today date is :-”+DTOC(D) [Enter] Will display: Today date is :-[Current Date]
C. String Function: A string is a series of character and spaces which are numeric, character or logical. This functions are tools that let you control the way you can store or display strings.
1. LTRIM( ): This function remove the leading and trailing blank spaces of left side from a character expression.
Example: A=” Ratan ” [Enter]
B=” Tata ” [Enter]
?A+B [Enter] Will display: [ Ratan Tata ]
?LTRIM(A)+LTRIM(B) [Enter] Will display: [Ratan Tata ]
2. RTRIM( ): This function remove the leading and trailing blank spaces of Right side from a character expression.
Example: A=” Ratan ” [Enter]
B=” Tata ” [Enter]
?A+B [Enter] Will display: [ Ratan Tata ]
?RTRIM(A)+RTRIM(B) [Enter] Will display: [ Ratan Tata]
3. ALLTRIM( ): This function remove the leading and trailing blank spaces of both side from a character expression.
Example: A=” Ratan ” [Enter]
B=” Tata ” [Enter]
?A+B [Enter] Will display: [ Ratan Tata ]
?ALLTRIM(A)+ALLTRIM(B) [Enter] Will display: [RatanTata]
4. ASC( ): This function returns the ASCII code of the character expression.
Example: ?ASC(“A”) [Enter] Will display: 65
?ASC(“a”) [Enter] Will display: 97
5. CHR( ): This function returns the character of the ASCII code.
Example: ?CHR(90) [Enter] Will display: Z
?CHR(122) [Enter] Will display: z
6. ATC( ): This function search source expression by a target expression and returns where the source expression was found.
Example: T=“It was the wonderful sight indeed. It was lovely” [Enter]
?ATC(“was”,T) [Enter] Will display: 4
?ATC(“was”,T,2) [Enter] Will display: 39
7. LEN( ): This function returns total number of character of a character expression.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?LEN(M) [Enter] Will display: 21
?LEN (“India”) [Enter] Will display: 5
8. LOWER( ): This function returns the specified character expression in lower case.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?LOWER(M) [Enter] Will display: youth computer centre
9. UPPER( ): This function returns the specified character expression in upper case.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?UPPER(M) [Enter] Will display: YOUTH COMPUTER CENTRE
10. PROPER( ): This function returns a capitalized character.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?PROPER(M) [Enter] Will display: Youth Computer Centre
11. OCCUR( ): This function returns the number of times a source character expression occurs in a target character expression.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?OCCUR(“u”,M) [Enter] Will display: 1
12. REPLICATE( ): This function returns a specified number of time repeating character.
Example: ?REPLICATE(“W”,5) [Enter] Will display: WWWWW
13. LEFT( ): This function returns the left portion of a character string.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?LEFT(M,5) [Enter] Will display: YoUth
14. RIGHT( ): This function returns the right portion of a character string.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?RIGHT(M,6) [Enter] Will display: cEntRe
15. SUBSTR( ): This function returns the specified number of character from a character string expression.
Example: M=“YoUth cOmPuter cEntRe” [Enter]
?SUBSTR(M,7,8) [Enter] Will display: cOmPuter
16. SPACE( ): This function use for fixed specified number of blanks.
Example: X=SPACE(10) [Enter] Will store: 10 space in X variable
17. STR( ): This function convert a numeric expression to a character expression.
Example: A=123.456 [Enter]
?STR(A) [Enter] Will display: 123
?STR(A,6,2) [Enter] Will display: 123.45