Microsoft Access Office VB VBA Help and Examples
           
             

Conversion Functions Explained

The following is a list of functions available in VB & VBA for converting from one type to another. These function are most useful when you are creating your own functions or want to manipulate a number or text string.

  • CBool(expression) This will convert any valid expression into a boolean (true / false) value. The only expressions you can pass to it are the following "True" , "False" "0" or 0 gives false, and any other text or normal number gives true.
  • CByte(expression)This is only useful if you want to convert a string, integer, long or double that has a positive value less that 256 into a byte (which takes up less space)
  • CCur(expression)Converts any string, integer, long, byte, or double value to a currency value (roughly plus or minus 900 Trillion to four decimal places.
  • CDate(expression)Great for converting strings into date format. Accepts most formats for dates. 12/3/99 12-3-99 12 March 1999 e.t.c also accepts numbers counting from 1/1/1899 so 36231.0 is equal to 12/3/1999.
  • CDbl(expression)Converts any valid string, long , byte , decimal or currency to double. (You know the scientific format).
  • CDec(expression)Converts any valid string, long, byte, double or currency to decimal. That would be numbers up to 79 gazillion (+/-79,228,162,514,264,337,593,543,950,335) or the same with decimal places +/-7.9228162514264337593543950335
  • CInt(expression)Converts valid values to integer format (-32,768 to 32,767).
  • CLng(expression)Converts valid values to long format (-2,147,483,648 to 2,147,483,647)
  • CSng(expression)Converts valid values to single format. (Scientific but not as big as double)
  • CVar(expression)Don't do it, it's too confusing
  • CStr(expression)Converts valid values (numbers, boolean) to string format. Great for doing string calculations on numbers. For instance if you want the first two characters as a number of any long then you can use clng(left(cstr(number),2)). So 2345 would give 23 and 23456 would give 23.
 
HOME   SEARCH SITE   PRIVACY POLICY   CONTACT
The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.