From the course: Visual Basic Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Understand variable scope - Visual Basic Tutorial
From the course: Visual Basic Essential Training
Understand variable scope
- [Instructor] We haven't talked about variable scope or lifetime yet. So, I'll do that in this RunCode method. I'll start by talking about local variables meaning variables that are declared within a sub-routine or function. The scope of a variable determines its visibility to other code. So the visibility of a local variable like this one declared here on line 22 would be inside this sub. I can't use it before I declare it but once I've declared it, I can use it anywhere else in this sub-routine. I'm using it here on line 27, and on line 34. I'm also incrementing the value over here on line 28. So I can use it all the way down until I get to the End Sub. Rule number two, variables in the same scope cannot have the same identifier or name. Let's look at line 23. I'll uncomment this line. I get an error. So even though this is a different type and a different initialized value, because it has the same…
Contents
-
-
-
-
-
-
-
-
-
Work with variables and constants4m 56s
-
(Locked)
Use the Code Explorer project1m 59s
-
(Locked)
Declare a variable6m 30s
-
(Locked)
Tips to make literals pop in the editor2m 34s
-
(Locked)
Work with custom and built-in constants3m 54s
-
(Locked)
Understand variable scope5m 42s
-
(Locked)
Understand numeric to numeric conversions5m 54s
-
(Locked)
Convert numeric values5m 43s
-
(Locked)
Convert and format numbers to string6m 39s
-
(Locked)
Convert and parse string to numbers5m 59s
-
(Locked)
Work with strings7m 11s
-
(Locked)
Work with dates and times9m 21s
-
(Locked)
Challenge: Strings, dates, and parsing52s
-
(Locked)
Solution: Strings, dates, and parsing2m 5s
-
-
-
-
-
-
-
-