Home >>VB.Net Programs >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
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.