From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Understand the variable scope: What code can access the variable

Understand the variable scope: What code can access the variable - Visual Basic Tutorial

From the course: Visual Basic Essential Training

Understand the variable scope: What code can access the variable

- [Instructor] When you think about variables, it's important to understand two concepts. The scope of the variable and the lifetime of the variable. Scope determines the visibility of that variable to other parts of your code. In other words, where can I use that variable? Lifetime refers to how long the memory is kept available. Here's some information about scope and remember that's the visibility of the variable. Variables that are within the same scope cannot share the same name. Lifetime depends on where the variable is declared. So let's start by talking about local variables. We'll talk about three types of variables, local variables, block level variables, and we'll also talk about class or module level variables. Starting with local variables. If I declare a variable within this procedure, the scope is all the code that in this procedure. So all the code that's in run code can see that variable. I'm declaring this cart counter here. That means I can use it elsewhere in my…

Contents