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

VB.Net program to print the HEX values of numbers

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

Here, we use the "GoTo" statement and the Hex() function to print the HEX values of numbers from 1 to 15.

Program :

Below is the source code to print HEX 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 <= 10 Then
            Console.WriteLine("Num:{0}, Hex value:{1}", num, Hex(num))
            GoTo MyLabel
        End If
    End Sub
End Module
	
Output:
Num:1, Hex value:1
Num:2, Hex value:2
Num:3, Hex value:3
Num:4, Hex value:4
Num:5, Hex value:5
Num:6, Hex value:6
Num:7, Hex value:7
Num:8, Hex value:8
Num:9, Hex value:9
Num:10, Hex value:A

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created a variable num 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 control. So the value of the variable num is increased by one to 5.

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

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


No Sidebar ads