Download presentation
Presentation is loading. Please wait.
1
Variables and Constants
Variables: Memory locations that hold data, that can be changed during project execution (eg: student names will vary as the information for each student is being processed) Constants: Memory locations that hold data that cannot change during execution (eg: however, the college which the students attend (UCC) will remain the same)
2
Variables Variables are declared, depending on where they are used and how long their value needs to be retained Variables are locations in the computers memory, which are named by the user Variables store values The values which are assigned to variables can change during project execution (the values they hold varies, hence the name)
3
Variables have to be declared (the computer must be made aware of their existence) and once they have been declared, the computer allocates them (memory) storage space and assigns this area of memory a name, called an identifier Variables are declared using the DIM statement DIM Variable Name (Identifier) AS Data Type The declaration statements establish the project variables, assign names to the variables, and specify the type of data that the variables will hold The statements are non-executable (they are not executed in the flow of instructions during program execution
4
Dim stName As STRING (Declares a string variable) Dim iCounter As INTEGER (Declares an integer variable) The reserved word DIM is short for dimension, meaning size Variables can have a number of different data types A variable can only store values which correspond with the data type they are assigned
5
Data Types The data type of a variable indicates what type of information will be stored in the allocated memory space The default data type is variant The advantage of using variant data type is that it is easy, and the variables change their appearance as needed for each situation The disadvantage is that variants are less efficient than the other data types, they require more memory and operate less quickly
6
Variable Declarations
DIM Variable name (Identifier) AS Data Type Dim iYear As Integer Dim stCustName As String can also be declared as: Dim iYear As Integer, stCustName As String Also Specific Characters can be used to represent each of the Data Types
7
Data Types - String ($) - Integer (%) - Currency - Long Integer (&) - Single Precision (!) - Double Precision (£) Variable Declarations Dim iYear%, stCustName$,
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.