Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27569

Scope of variables in and out of procedures

$
0
0
Hi,

I have declared 2 variables as integer in main module. The Func(a, b) assings the values to variables a and b.
After the function execute, When I try to print the values of a and b, both the message boxes for a and b are blank.
I expected that values 1 and 2 will be displayed instead it was blank.

Could someone help me to understand the scope of variables declared as public outside the procedure and initialized within a procedure, can be used it wherever we need?


Public Module Main
Dim _desktop As Desktop = Agent.Desktop

Public a As Integer
Public b As Integer

Public Sub Main()

Func(a, b)
Msgbox(a)
Msgbox(b)

End Sub

Public Sub Func(a, b)

a = 1
b = 2

End Sub

End Module

Viewing all articles
Browse latest Browse all 27569

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>