I have a question about variable scope in VBScript. I know there's the following keywords (from autoitscript.com):
- Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)
- Global = Forces creation of the variable in the Global scope
- Local = Forces creation of the variable in the Local/Function scope
Imagine that I have the following .vbs file:
Dim strPath
strPath = "C:\folder"
DisplayPath strPath
Sub DisplayPath(strPath) 'Does this strPath get it's own local scope?
MsgBox strPath
End Sub
In the function: DisplayPath(strPath)
, is strPath
a local variable? Or do functions/subs have access to the strPath
defined at the top of the main section of the script as a global variable?
Also, what's the point of explicitly using Dim
versus just defining variables as I use them, which is possible in scripting languages?