ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to create a global variable

Here, we are going to learn how to create a global variable in VB.Net?
Submitted by Nidhi, on December 21, 2020

Here, we will two global variables and then use them in the Main() function.

Program/Source Code:

The source code to create a global variable is given below. The given program is compiled and executed successfully.

'VB.Net program to create a global variable.

Module Module1
    Dim num1 As Integer = 10
    Dim num2 As Integer = 20

    Sub Main()
        Dim num3 As Integer = 0

        num3 = num1 + num2
        Console.WriteLine("Sum: " & num3)
    End Sub
End Module

Output:

Sum: 30
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created two global variables num1, num2. Which are initialized with 10, 20 respectively. In the Main() function, we created a local variable num3, which is initialized with 0 then we add num1 and num2 and assigned the sum into the num3 variable. After that, we printed the sum on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

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.