Functions, Subroutines, Variables, and Scope

No, this section isn’t an exercise in "Which of these objects doesn’t belong?" Scope, in terms of programming, means the range of execution during which a variable exists. To realize the importance of this, consider these facts:

  • When you call a function or subroutine, your program asks Windows for whatever memory the function or subroutine needs. This includes memory for ByVal copies of arguments, variables, and so forth.

  • When your function or subroutine ends, it gives the memory for these items back to Windows.

Do you see the implications of this? Any variables you declare inside a function subroutine have no existence unless that function subroutine is running! You certainly can’t access these variables ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.