Visual Basic for Applications/Variables

From Wikiversity
Jump to navigation Jump to search

This lesson introduces variables.

Objectives and Skills[edit | edit source]

Objectives and skills for using variables include:

  • Declaring variables by using the appropriate data types
  • Making variables available to procedures in all modules of an application
  • Performing actions with built-in and user-defined constants

Readings[edit | edit source]

  1. Wikipedia: Variable (computer science)
  2. Wikipedia: Constant (computer programming)
  3. Wikipedia: Data type
  4. Wikipedia: Type conversion
  5. Wikipedia: Scope (computer science)
  6. Microsoft: Declaring Variables
  7. Microsoft: Option Explicit
  8. Microsoft: InputBox Function
  9. Microsoft: Let Statement

Multimedia[edit | edit source]

  1. YouTube: InputBox

Examples[edit | edit source]

'This macro accepts user input and then displays double the value entered.

Option Explicit

Sub DoubleValue()
    Const Title = "Double Value"
    Dim Value As Single
    Dim Result As Single
    Value = InputBox("Enter a value:", Title)
    Result = Value * 2
    MsgBox Value & " * 2 = " & Result, vbOKOnly + vbInformation, Title
End Sub

Activities[edit | edit source]

See Also[edit | edit source]

References[edit | edit source]

Nuvola apps edu miscellaneous.svg Type classification: this is a lesson resource.