Visual Basic Concepts
Introduction to Variables, Constants and Data Types
You often need to store values temporarily when performing calculations with Visual Basic. For example, you might want to calculate several values, compare them, and perform different operations on them, depending on the result of the comparison. You need to retain the values if you want to compare them, but you don't need to store them in a property.
Visual Basic, like most programming languages, uses variables for storing values. Variables have a name (the word you use to refer to the value the variable contains) and a data type (which determines the kind of data the variable can store). Arrays can be used to store indexed collections of related variables.
Constants also store values, but as the name implies, those values remain constant throughout the execution of an application. Using constants can make your code more readable by providing meaningful names instead of numbers. There are a number of built-in constants in Visual Basic, but you can also create your own.
Data types control the internal storage of data in Visual Basic. By default, Visual Basic uses the Variant data type. There are a number of other available data types that allow you to optimize your code for speed and size when you don't need the flexibility that Variant provides.
For more detailed information, see:
- Variables An introduction to variables: what they are and how to use them.
- Understanding the Scope of Variables A discussion of scope as it applies to variables.
- Advanced Variable Topics Detailed information about variables.
- Static Variables An introduction to using static variables to preserve values.
- Constants An introduction to using constants to represent values.
- Data Types A discussion of the data types available in Visual Basic.
- Advanced Variant Topics Detailed information about the Variant data type.
- Arrays An introduction to the use of arrays for groups of values.
- Dynamic Arrays A discussion of using dynamic arrays to work with groups of values.