Sunday, January 27, 2013

Microsoft Access - Val Function

Val Function

This function is used to extract the number contained in a string as numeric value. The val function is useful when a string contains numbers in the left hand side.


Val(String) or Val([ColumnName])

The String argument can be any string expression.

The Val function evaluates the expression or string if the first character contains a number. If it not contains a number in the first character it stops reading. The function recognizes radix prefixes &o(for Octal) and &H(for Hexadecimal). If the string value contains the number in the middle of the string it will not recognizes it. The Currency and commas contained in the string or expression are not recognized. Linefeeds, spaces, tab and blank characters are stripped from the argument.


Val(“    15236 “) will return 15236. As the argument contains the number as the first character.
Val(“9 Cross”) will return 9.
Val(“Jan 13”) will return 0. As the first character is not a number.
Val(“35.2 inches) will return 35.2.
Val(“&HFF”) will return 256. As &H is a radix prefix for Hexadecimal Numbers.
Val(“&O12”) will return 10. AS &O is the radix prefix for Octal numbers.

No comments:

Post a Comment