Conversion Functions
1) Asc Function
Returns the ANSI character code corresponding to the first letter in a string.
Syntax:
Asc(string)
Remarks
The string argument is any valid string expression. If the string contains no characters, a run-time error occurs.
Dim MyNumber
MyNumber = Asc("A") ' Returns 65.
MyNumber = Asc("a") ' Returns 97.
MyNumber = Asc("Apple") ' Returns 65.
2) CByte Function
Returns an expression that has been converted to a Variant of subtype Byte.
Syntax:
CByte(expression)
The expression argument is any valid expression.
Use the CByte function to provide conversions from any data type to a Byte subtype.
Example:
Dim MyDouble, MyByte
MyDouble = 125.5678 ' MyDouble is a Double.
MyByte = CByte(MyDouble) ' MyByte contains 126.
3) CDate Function
Returns an expression that has been converted to a Variant of subtype Date.
Syntax:
CDate(date)
The date argument is any valid date expression.
Use the IsDate function to determine if date can be converted to a date or time.
Example:
MyDate = "October 19, 1962" ' Define date.
MyShortDate = CDate(MyDate) ' Convert to Date data type.
MyTime = "4:35:47 PM" ' Define time.
MyShortTime = CDate(MyTime) ' Convert to Date data type.
4) Chr Function
Syntax:
CDate(date)
The date argument is any valid date expression.
Use the IsDate function to determine if date can be converted to a date or time.
Example:
MyDate = "October 19, 1962" ' Define date.
MyShortDate = CDate(MyDate) ' Convert to Date data type.
MyTime = "4:35:47 PM" ' Define time.
MyShortTime = CDate(MyTime) ' Convert to Date data type.
4) Chr Function
Returns the character associated with the specified ANSI character code.
Syntax:
Chr(charcode)
The charcode argument is a number that identifies a character.
Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character.
Example:
Dim MyChar
' Returns A:
MyChar = Chr(65)
' Returns B:
MyChar = Chr(66)
' Returns Z:
MyChar = Chr(90)
' Returns a:
MyChar = Chr(97)
' Returns b:
MyChar = Chr(98)
' Returns z:
MyChar = Chr(122)
' Returns 0:
MyChar = Chr(48)
' Returns 1:
MyChar = Chr(49)
' Returns 9:
MyChar = Chr(57)
' Returns horizontal tab:
MyChar = Chr(9)
' Returns >:
MyChar = Chr(62)
' Returns %:
MyChar = Chr(37)
5) CLng Function
Returns an expression that has been converted to a Variant of subtype Long.
Syntax:
CLng(expression)
The expression argument is any valid expression.
Use the CLng function to provide conversions from any data type to a Long subtype.
Example:
Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45: MyVal2 = 25427.55 ' MyVal1, MyVal2 are Doubles.
MyLong1 = CLng(MyVal1) ' MyLong1 contains 25427.
MyLong2 = CLng(MyVal2) ' MyLong2 contains 25428.
6) CStr Function
Returns an expression that has been converted to a Variant of subtype String.
Syntax:
CStr(expression)
The expression argument is any valid expression.
Example:
Dim MyDouble, MyString
MyDouble = 437.324 ' MyDouble is a Double.
MyString = CStr(MyDouble) ' MyString contains "437.324"
7) Oct Function
Returns a string representing the octal value of a number.
Syntax:
Oct(number)
The number argument is any valid expression.
Example:
Dim MyOct
MyOct = Oct(4) ' Returns 4.
MyOct = Oct(8) ' Returns 10.
MyOct = Oct(459) ' Returns 713.
8) CBool Function
Returns an expression that has been converted to a Variant of subtype Boolean.
Synta:
CBool(expression)
The expression argument is any valid expression.
If expression is zero, False is returned; otherwise, True is returned. If expression can't be interpreted as a numeric value, a run-time error occurs.
Example:
Dim A, B, Check
A = 5: B = 5 ' Initialize variables.
Check = CBool(A = B) ' Check contains True.
A = 0 ' Define variable.
Check = CBool(A) ' Check contains False.
9) CCur Function
Returns an expression that has been converted to a Variant of subtype Currency.
Syntax:
CCur(expression)
The expression argument is any valid expression.
Example:
Dim MyDouble, MyCurr
MyDouble = 543.214588 ' MyDouble is a Double.
MyCurr = CCur(MyDouble * 2) ' Convert result of MyDouble * 2 (1086.429176) to a Currency (1086.4292).
10) CInt Function
Returns an expression that has been converted to a Variant of subtype Integer.
Syntax:
CInt(expression)
The expression argument is any valid expression.
Example:
Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble is a Double.
MyInt = CInt(MyDouble) ' MyInt contains 2346.
11) CSng Function
Returns an expression that has been converted to a Variant of subtype Single.
Syntax:
CSng(expression)
The expression argument is any valid expression.
Example:
Dim MyDouble1, MyDouble2, MySingle1, MySingle2 ' MyDouble1, MyDouble2 are Doubles.
MyDouble1 = 75.3421115: MyDouble2 = 75.3421555
MySingle1 = CSng(MyDouble1) ' MySingle1 contains 75.34211.
MySingle2 = CSng(MyDouble2) ' MySingle2 contains 75.34216.
12) Hex Function
Returns a string representing the hexadecimal value of a number.
Syntax:
Hex(number)
number argument is any valid expression.
we can represent hexadecimal numbers directly by preceding numbers in the proper range with &H.
Example:
Dim MyHex
MyHex = Hex(5) ' Returns 5.
MyHex = Hex(10) ' Returns A.
MyHex = Hex(459) ' Returns 1CB.
For More Functions visit:
No comments:
Post a Comment