Fundamantal Definition of ‘variable’

 

<-- Back

 


A “variable”  is a letter or word that identifies a place
in the computer’s memory where a value can be stored.

 

NOTE : A variable’s name MUST start with any letter,
and may be followed by more letters or numbers.


The contents of that memory location can change,
which is why it’s called a ‘variable.’

It varies from time to time while the program is running.

 

A “variable” can store a number, or a word (or many words)
or a “True/False” value.
 

 

The value that is stored in the variable can be retrieved easily
by simply using the variable’s name in a program statement.

 

Any time the computer program encounters a variable name in the code,
the program “looks up” the value stored in memory and retrieves it.
The program then replaces the name with the stored value and uses it
however your code says to use it.

 

Depending on what kind of data is stored in the variable’s memory location,
it might be used to do some arithmetic (if it’s a number) or display a name (if it is text.)

 

 

For example, if you use a variable called “EmployeeID”

It might be stored in memory using this code :

(Note that when ‘assigning’ a value to a variable, the variable is on the left of the “=” sign.)

EmployeeID = “ABC123”

 

 

To retrieve that value from memory, and display it on a form,
it might be placed in a label that has been added to a form :
(Note that when retrieving a value from a variable, the variable is on the right of the “=” sign.)

LblEmployeeID.Caption = EmployeeID

 

 

<-- Back