Home >>VB.Net Programs >VB.Net program to print the ASCII values of numbers

VB.Net program to print the ASCII values of numbers

Write a VB.Net program to print the ASCII values of numbers

Here, using the "GoTo" statement and Asc() function, we can print the ASCII values of numbers from 1 to 5.

Program :

Below is the source code to print ASCII values for numbers from 1 to 5 using the 'GoTo' statement. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim num As Integer = 0
MyLabel:
        num = num + 1
        If num <= 5 Then
            Console.WriteLine("Num:{0}, Ascii value:{1}", num, Asc(num))
            GoTo MyLabel
        End If
    End Sub
End Module
	
Output:
Num:1, Ascii value:49
Num:2, Ascii value:50
Num:3, Ascii value:51
Num:4, Ascii value:52
Num:5, Ascii value:53

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created a variable number of the Integer kind in the Main() method, which is initialized with 0. Then we developed the MyLabel label, which is used using the "GoTo" statement to pass program power. So the value of the variable number is increased by one to 5.

If num <= 5 Then
    Console.WriteLine("Num:{0}, Ascii value:{1}", num, Asc(num))
    GoTo MyLabel
End If

In the above code, program control can pass the number and its corresponding ASCII value to the console screen each time until the value of variable num is less than equal to 5.


No Sidebar ads