Asc - VBScript


The Asc function returns the American Standard Code for Information Interchange (ASCII) code for the first character of a string. This function is useful for converting characters to their numerical equivalents.




  • string: (Required) The string to convert.




' Get the ASCII code for the letter "A"
Dim code = Asc("A")
' Display the ASCII code
WScript.Echo code  ' Output: 65
' Convert a string of characters to their ASCII codes
Dim str = "Hello World"
For i = 1 To Len(str)
    Dim code = Asc(Mid(str, i, 1))
    WScript.Echo code  ' Output: 72 101 108 108 111 32 87 111 114 108 100

Common Issues

  • The Asc function only returns the ASCII code for the first character of a string. To convert the entire string to ASCII codes, you can use a loop to iterate through each character in the string.


The Asc function can be combined with other VB Script functions to perform more complex tasks. For example, you can use the Chr function to convert an ASCII code back to a character.

' Convert the ASCII code 65 to a character
Dim chr = Chr(65)
' Display the character
WScript.Echo chr  ' Output: A
  • Chr – Converts an ASCII code to a character.
  • Mid – Returns a substring from a string.
  • Len – Returns the length of a string.