Introduction to Variables in Visual Basic
Created 3 years ago
A fast introduction to variables in Visual Basic. Five review questions at the end.
Email this Mix
Slide 1 - Introduction to Variables
- Visual Basic variables for Beginners
Slide 2 - A variable represents a location in memory
- We need a name to reference it
- The location stores information
- We need to tell it what to store
- All information is stored as Binary numbers
- We need to tell the computer what kind of information it is
- What is a variable?
Slide 3 - Every variable has a name, a type and a value.
- What is it called? Name
- What kind of information is it? Type
- What is the information it is storing? Value
- All three have to be defined by the programmer!
- Key Point
Slide 4 - Dim statement declares a variable
- Dim age as Integer = 19
- Name is “age”
- Type is “Integer”
- Value is 19.
- Declaring Variables
Slide 5 - Variable names are one form of identifier
- An identifier names program elements.
- Visual Basic names are NOT case sensitive.
- Digits may occur, but cannot be the first character.
- Identifiers may use the underscore character.
- Keywords are identifiers reserved for special uses.
Slide 6 - Some valid Visual Basic identifiers are:
- Some invalid identifiers are:
- 4you ‘ Starts with a number
- x<y ‘ Includes an illegal character, <
- top-gun ‘ Includes an illegal character, -
- integer ‘ Reserved keyword
Slide 7 - Integer – whole numbers, no fractional part
- Double – floating point numbers, fractional part
- String – characters of any type
- Boolean – true or false are the only values
- Variable Types
- Dim x as Integer
- Dim x as Integer = 0
- Dim d as Double
- Dim d as Double = 0.0;
- Dim s as String
- Dim s as String = “Something”;
- Dim done as Boolean
- Dim Done as Boolean = true
Slide 8 - Assignment statements copy the value on the right into the location on the left
- Assign values during runtime
- The assignment operator is the equals sign, =
- age = 10
- The value is stored in the memory location allocated for that variable.
- Assignment statements copy the value on the right into the location on the left
Slide 9 - Age = 18
- Value of 18 is copied into variable Age
- myAge = Age
- What ever value is in Age is copied into variable myAge. Age still holds the same value
- FirstName = TextBox1.Text
- The string that the user typed into the textbook called TextBox1 is copied into the variable FirstName