VB.Net program to input and print an integer variable

Here, we are going to learn how to input and print an integer variable in VB.Net?
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]

Inputting and printing an integer variable

We will create a program to read an integer variable from the user and print them on the console screen.

VB.Net code to input and print an integer variable

The source code to input and print an integer variable is given below. The given program is compiled and executed successfully.

'VB.Net program to input and print an integer variable.

Module Module1
    Sub Main()
        Dim num As Integer = 0

        Console.Write("Enter an integer value: ")
        num = Convert.ToInt32(Console.ReadLine())

        'print the value
        Console.WriteLine("num = {0}", num)
        Console.ReadLine()
    End Sub

End Module

Output:

Enter an integer value: 108
num = 108

Explanation:

In the above program, we created a Module that contains the Main() method, here we created a local variable num initialized with 0.

Console.Write("Enter an integer value: ")
num = Convert.ToInt32(Console.ReadLine())

here, we read the value using ReadLine() method, but ReadLine() method return the string then we needs to convert it into integer using ToInt32() method of Convert class and then we assigned the value to the num variable. After that we printed the value of num on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





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