Function local variables : Variable Scope « Language Basics « VB.Net Tutorial






Module Module1

    Sub F()
        Dim Name As String = "www.java2s.com"
        Dim Price As Double = 17.45
        Dim I As Integer = 1001

        Console.WriteLine("In F")
        Console.WriteLine("Name: " & Name)
        Console.WriteLine("Price: " & Price)
        Console.WriteLine("I: " & I)
    End Sub

    Sub FF()
        Dim Name As String = "string"
        Dim Price As Double = 49.99
        Dim I As Integer = 0

        Console.WriteLine("In FF")
        Console.WriteLine("Name: " & Name)
        Console.WriteLine("Price: " & Price)
        Console.WriteLine("I: " & I)
    End Sub

    Sub Main()
        F()
        Console.WriteLine()
        FF()
    End Sub

End Module
In F
Name: www.java2s.com
Price: 17.45
I: 1001

In FF
Name: string
Price: 49.99
I: 0








1.5.Variable Scope
1.5.1.Demonstrates scope rules and instance variables
1.5.2.Block scope
1.5.3.Variable block scope
1.5.4.Variable scope in try catch statement
1.5.5.Define variable inside If statement
1.5.6.Sub scope
1.5.7.Function local variables
1.5.8.Local variable shadows global variable with the same name
1.5.9.Module global variable