Code Snippets VB.Net

VB.Net - Get ASCII Value of a Character.

IncludeHelp VB.Net 14 OCT 2016

In this VB.Net code we will learn how to get ASCII value of any character in VB.Net?

In this example there is a form with textbox and button control, character will be entered in textbox and will print ASCII value in message box on button click event.

To convert character into its equivalent ASCII value Convert.ToByte() can be used.

Convert.ToByte(character): This function will return ASCII Value of given character.

VB.Net Code - Get ASCII value of any character

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim charValue As Char

        'getting single character from textbox
        charValue = CChar(TextBox1.Text.Trim)

        'getting byte as ascii value of the character
        Dim asciiValue As Integer

        asciiValue = Convert.ToByte(charValue)

        'printing value

        MsgBox("ASCII value is: " & asciiValue)

    End Sub
End Class

Output

character to byte, ascii conversion in vb.net




Copyright © 2024 www.includehelp.com. All rights reserved.