Monday, September 16, 2013

VBA String Functions - Part 1

ASC Function (VBA)

In Microsoft Excel, the ASC function returns the ASCII value of a character or the first character in a string.

Syntax

The syntax for the ASC function is:  Asc( string )

string is the specified character to retrieve the ASCII value for. If there is more than one character, the function will return the ASCII value for the first character and ignore all of the characters after the first.

VBA Function Example

Here are some examples of what the ASC function would return:

Asc ("W") would return 87
Asc ("Wednesday") would return 87
Asc ("x") would return 120


Dim iResult As Integer
iResult = Asc ("W")

In this example, the variable called iResult would now contain the value 87.




CHR Function (VBA)


In Microsoft Excel, the CHR function returns the character based on the ASCII value.

Syntax

The syntax for the CHR function is: Chr( ascii_value )

ascii_value is the ASCII value used to retrieve the character.

VBA Function Example

Dim sResult As String
sResult = Chr(87)

In this example, the variable called sResult would now contain the value "W".


No comments:

Post a Comment

Data base function

Database function Daverage function      Averages the values in a field (column) of records in a list or database that match conditio...