ADVERTISEMENT
ADVERTISEMENT

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

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

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.