Com 211
Com 211
Com 211
Okimba P.E.
During this week you will learn:
◦ Basic character sets
◦ Data Types
Visual Basic uses building blocks such as
Variables, Data Types, Procedures, Functions
and Control Structures in its programming
environment.
Modules
Code in Visual Basic (VB) is stored in the form of
modules. There are three kinds of modules in
VB;
Form Modules,
Standard Modules and
Class Modules.
Form -the container for all the controls that make up the user interface.
Standard Module - separate module containing a procedure
created to implements common code.
Class module -(CLS filename extension) are the foundation of the
object oriented programming in Visual Basic.
Note:
A Module contains Declarations and Procedures
Character set refers to those characters acceptable or
allowed in VB programming e.g. GB is unknown in
English likewise X is unknown in Yoruba, Igbo and
Hausa languages.
The Microsoft character sets consist of the following:
Alphabet A/ a – Z/z (Both Upper and Lower Case)
Numeric Digits 0 – 9
Decimal point (.)
Grouping Characters (e.g. Comma, colons,
Semicolons, single and double apostrophe,
parenthesis)
Relational Operators (eg. =, <>,>,< etc) Arithmetic
Operators (eg. +, -, /, =. etc) Blank character
The VB programming language works with all kinds
of data. Before you learn how to manipulate data,
you will learn how to distinguish among the various
data types that supports the language. Some data
falls into more than one category. For example, a
dollar amount can be considered both as a currency
data type and as a single data type. When you write
a program, you need to decide which data type best
fits your program's data values. Thus, we are
considering data types in two categories;
Numeric data types
Non-numeric data types
Literals are values that you assign to a data.
In some cases, we need to add a suffix behind a
literal so that VB can handle the calculation
more accurately. For example, we can use
num=1.3089# for a Double type data.
Examples of other suffix used in VB are; !, @
and &
In this Lesson you will learn:
◦ Declaring Variables
◦ Assigning Values to Variables
◦ Mathematical Expressions
◦ Conditional Operators
Definition: To define a variable means to
create and name a variable.
A variable is a letter or name that can store a
value.
When you create computer programs, you can
use variables to store numbers, such as the
height of a building, or words, such as a
person's name. Simply put, you can use
variables to represent any kind of information
your program needs.
Storing Information in Variables
There are three steps to using a variable:
Declare the variable. Tell the program the
name and kind of variable you want to use.
Assign the variable. Give the variable a value
to hold.
Use the variable. Retrieve the value held in
the variable
Declaring Variables
A program can have as many variables as you
need it to have. When you declare a variable,
you have to decide what to name it and
what data type to assign to it (That is a variable
must have; name and data type).
Example.
totalCandy, W123, name21478 etc.
Dim statement.
Dim - Dimension
This statement is used for declaring variables in VB
programming.
i.e. Dim VariableName As DataType
Note:
Using Dim, you are telling the interpreter
◦ that you need a variable
◦ what to name the variable
◦ what kind of variable you want
Format of Dim Statement:
Dim VarName AS DataType
Rules for Variable names formation.
A name must begin with a letter and it can be either uppercase
or lowercase letters.
After the initial letter, names can contain letters, numbers, or
underscores in names.
May be as much as 255 characters long (but don't forget that
somebody has to type the stuff!).
Must not contain a space or an embedded period or type-
declaration characters used to specify a data type; these are ! # %
$&@
Must not be a reserved word (that is part of the code, like
Option, for example)
The dash, although legal, should be avoided because it may be
confused with the minus sign. Instead of First-name use
First_name or FirstName.
Never define two variables with the same name
Examples of variable names are;