×

VB.Net Programs

VB.Net program to create a global variable

By Nidhi Last Updated : October 13, 2024

Creating a global variable in VB.Net

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 code to create a global variable

'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 »


Comments and Discussions!

Load comments ↻





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