Visual Basic for Applications/Variables
Appearance
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]- Wikipedia: Variable (computer science)
- Wikipedia: Constant (computer programming)
- Wikipedia: Data type
- Wikipedia: Type conversion
- Wikipedia: Scope (computer science)
- Microsoft: Declaring Variables
- Microsoft: Option Explicit
- Microsoft: InputBox Function
- Microsoft: Let Statement
Multimedia
[edit | edit source]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