How to Convert Characters to Their ASCII Values in Visual Basic

Written by kevin walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert Characters to Their ASCII Values in Visual Basic
Every letter, punctuation mark and number has a corresponding ASCII code. (alphabet image by Blue Moon from Fotolia.com)

English characters are stored on the computer in a standardised set of codes known as the American Standard Code for Information Interchange (ASCII). This code contains 256 characters (some of them meant only for the machine to understand) to represent all the common letters, numbers and symbols of English punctuation. It has since been surpassed by Unicode Transformation Format (UTF), though all the original ASCII values maintain the same meaning in UTF to ensure compatibility with older systems. Visual Basic makes it easy to determine the ASCII code value for any character using the "Microsoft.VisualBasic.Asc" function.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Create a new project. Choose the "ConsoleApplication" type. Later, you can use the same code, without modification, within any Graphical User Interface (GUI) project. When prompted to give your project a name, name it "ASCII Translator."

  2. 2

    Paste the following code to create the string you would like to get the ASCII characters for:

    Dim s as String = "Hello."

    Dim char() as Char = s.toCharArray()

    Replace "Hello." with whatever string of characters you would like to translate.

  3. 3

    Paste the following to iterate through each letter in the string, convert it to its ASCII value and print it to the screen:

    For x as Integer = 0 to char.Length - 1

    Dim v as Integer = Microsoft.VisualBasic.Asc(char(x))

    Console.write(char(x))

    Console.write(" ")

    Console.writeLine(v)

    next

  4. 4

    Paste the following to pause the program and give the user a chance to view the results:

    Console.ReadKey()

  5. 5

    Click the green arrow to run the program. The results, if you leave the initial string as "Hello." will be:

    H 72

    e 101

    l 108

    l 108

    o 111

    . 46

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.