Professional Documents
Culture Documents
Valencia
A2A
VARIABLES
CONSTANT
A constant can be
- a number, like 25 or 3.6
- a character, like a or $
- a character string, like "this is a string"
DATA TYPES
A data type in a programming language is a set of data with values
having predefined characteristics. Examples of data types are: integer,
floating point unit number, character, string, and pointer. Usually, a
limited number of such data types come built into a language. The
language usually specifies the range of values for a given data type,
how the values are processed by the computer, and how they are
stored.
Boolean values
There is a duality built in our world. There is a Heaven and Earth, water
and fire, jing and jang, man and woman, love and hatred. In Visual
Basic the Boolean data type is a primitive data type having one of two
values: True or False. This is a fundamental data type. Very common in
computer programs.
Type casting
We often work with multiple data types at once. Converting one data
type to another one is a common job in programming. Type conversion
or typecasting refers to changing an entity of one data type into
another. There are two types of conversion. Implicit and explicit.
Implicit type conversion, also known as coercion, is an automatic type
conversion by the compiler.
Date
A Date is value type, which contain date values, time values, or date
and time values.
Arrays
Array is a complex data type which handles a collection of elements.
Each of the elements can be accessed by an index. All the elements of
an array must be of the same data type.
Enumerations
Enumerated type (also called enumeration or enum) is a data type
consisting of a set of named values. A variable that has been declared
as having an enumerated type can be assigned any of the
enumerators as a value. Enumerations make the code more readable.
Floating point numbers
Floating point numbers represent real numbers in computing. Real
numbers measure continuous quantities, like weight, height, or speed.
In Visual Basic we have three important floating point types: Single,
Double, and Decimal.
Integers
Integers are a subset of the real numbers. They are written without a
fraction or a decimal component. Integers fall within a set Z = {..., -2,
-1, 0, 1, 2, ...} Integers are infinite.In computer languages, integers are
primitive data types. Computers can practically work only with a
subset of integer values, because computers have finite capacity.
Integers are used to count discrete entities. We can have 3, 4, 6
humans, but we cannot have 3.33 humans. We can have 3.33
kilograms.
Variables are declared using the Visual Basic Dim keyword. The syntax for a
simple declaration of a variable is as follows:
Dim variableName As variableType
In the above outline, Dim is the keyword which indicates to Visual Basic that a
variable is being declared. variableName is the name assigned to the variable.
Try to use a descriptive variable name and prefix the name with something which
indicates the variable type. For example, when declaring a String variable prefix
the name with str (e.g. strFirstName). The As keyword precedes the declaration
of the variable type (String, Date, Integer etc). For a complete list of Visual Basic
variable types see Understanding Visual Basic Variable & Constant Types.
In the case where the variables are of different types the type of variable must be
declared at the end of each group of the same type. For example:
DimstrCustomerNameAsString="Fred",intInterestRate=5
AsInteger,intExchangeRateAsInteger=10
DimintInterestRateAsInteger=10
intInterestRate=20
A Visual Basic constant is referenced using the name defined when the constant
was declared. For example, the following Visual Basic code sets the Text
property of a Label control to the string value contained in the companyName
constant:
ConstcompanyNameAsString="Techotopia"
companyLabel.Text=companyName