Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the Chr() function

VB.Net program to demonstrate the Chr() function

Write a VB.Net program to demonstrate the Chr() function

To get characters against the specified ASCII value, the Chr() function is used.

Syntax :

Chr(num)

Parameters :

  • num: This is the value of ASCII.

Return Value :

The Chr() function will return the corresponding ASCII value for the character.

Program :

Below is the source code to demonstrate the Chr() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim num As Integer = 67
        Dim ch As Char
        ch = Chr(num)
        Console.WriteLine("Character: {0}", ch)
    End Sub
End Module
	
Output:
Character: C

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created two variables num and ch in the Main() method, where variable num is initialized with 67 here. As we know, the ASCII value of the character "C" is 67.

ch = Chr(num)

We used the Chr() function in the above code that returns the corresponding ASCII value of the character. Then, on the console screen, we printed a character.