What are Program Variables?
· In programming concepts, VARIABLES are data storage spaces (memory boxes), created in the computers memory.
· These boxes can be used to store data that which are being used while the program is running or executing.
· The programmer usually declare the variables to be used in the program. When the program is executed, the Variables are created by the program, according to the declarations.
· Variable are usually temporary. In other words, these memory boxes are usually created at the beginning of the program and later destroyed at the end of the program.
· A variable is referred by it’s given NAME at any time and from almost any part of the program.
· A more permanent variable, called the DYNAMIC Variable, could also be created to hold data for a longer time.
Advantages of using Program Variables
· Variables can be used, over and over again, form almost any part of the program.
· Variable can be manipulated to create the results that we want.
· Variable makes program coding more meaningful and less confusing. For example, instead of using Text20.text + Text 28.text, we could use GrossPay + TaxReturn, after the ‘textboxes’ have been renamed to these names.
· Variable can be used to store data temporarily, therefore we don’t have to ‘hard code’ a data permanently in in the program. This makes the program shorter and easy to be manage.
Condition for naming a Variables
• A hidden variable (memory box) can be created at any part of the program and used to store data. These types of variable need to be declared, usually at the beginning of the program codes.Example; Dim Salary as IntegerThe above example, would create a hidden memory box, named SALARY, where is set to store the data of INTEGER (number) type.
• Variable names MUST begin with Alphabets, NOT numberExample: StudentName
• Variables names can contain numberExample: Student3, Marks4, Row5Col6
• Variable names MUST NOT contain space.Example: ‘Total 10’ should be written as Total10
• However, names could be separated using ‘underscore’Example: Total_10
• Variable names should not contain symbols, such as &,%,!, etc. (however, at an advance stage of programming, you might come across the use of some symbols, such as the @ and & to indicate special variables)
• Variable names must reflect the object that are being referred. For example, the variable name to store Student’s age should could named as StuAge, instead of Age1
Types of Program Variables
· When creating a variable, it is necessary to describe the TYPE of the variable along. This is to have a control of the type of data that will be stored and used in the variable (memory box)
· The common types of variables are:
o INTEGER – used for storing whole numbers. An integer and later be added to another integer to produce an integer output. Declaring: Dim Marks1 as Integer
o DOUBLE - used when a number need to be presented as a floating number (number with decimal number). Double number present more accurate value of the assigned number. Declaring; Dim Length2 as double = 4.23
o STRING - used to store ALPHANUMERIC characters, which includes alphabets, numbers and symbols. Variable of type STRING cannot be use for calculation.Declaration: Dim Address as String
o BOOLEAN - used when the output of an object needs to be in form of two absolute answers such as TRUE or FALSE. Example: Variable MARRIED return the output of either TRUE or FALSE only.
o TEXT - are similar to STRING, where it ca be used to describe all data of mixed types such as numbers, alphabets and symbols. Text cannot be used for calculation an cannot contain images.
Monday, November 17, 2008
Subscribe to:
Posts (Atom)