Introduction to Variables in Visual Basic

A fast introduction to variables in Visual Basic. Five review questions at the end.

ProgrammingVisual BasicVariables
1.0x

Introduction to Variables in Visual Basic

Created 3 years ago

Duration 0:08:17
lesson view count 186
A fast introduction to variables in Visual Basic. Five review questions at the end.
Select the file type you wish to download
Slide Content
  1. Introduction to Variables

    Slide 1 - Introduction to Variables

    • Visual Basic variables for Beginners
  2. A variable represents a location in memory

    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?
  3. Every variable has a name, a type and a value.

    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
  4. Dim statement declares a variable

    Slide 4 - Dim statement declares a variable

    • Dim age as Integer = 19
    • Name is “age”
    • Type is “Integer”
    • Value is 19.
    • Declaring Variables
    • 199
  5. Variable names are one form of identifier

    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.
    • Identifiers
  6. Some valid Visual Basic identifiers are:

    Slide 6 - Some valid Visual Basic identifiers are:

    • savings
    • textLabel
    • rest_stop_12
    • B3
    • _test
    • My____my
    • Some invalid identifiers are:
    • 4you ‘ Starts with a number
    • x<y ‘ Includes an illegal character, <
    • top-gun ‘ Includes an illegal character, -
    • integer ‘ Reserved keyword
  7. Integer – whole numbers, no fractional part

    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
  8. Assignment statements copy the value on the right into the location on the left

    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
    • Assignment
  9. Age = 18

    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
    • Examples