Professional Documents
Culture Documents
Variable, Expressions, Statements and Operators: By: Daniel T. Ursulum, Jr. CSU - SM Graduate School (MIT)
Variable, Expressions, Statements and Operators: By: Daniel T. Ursulum, Jr. CSU - SM Graduate School (MIT)
and Operators
By: Daniel T. Ursulum, Jr.
CSU SM Graduate School (MIT)
Goal
Variables and its types
Scope, lifetime and access level of variables
Constant
Expression
Statement
Procedure
Sub Procedure
Functions
Variable
It is the name of memory location where we put
our data.
Declaring variable
Use Dim keyword
Assigning values
(sometimes declared with default value assigned)
Using variable
For data manipulation / mathematical calculation
Variables
Dim x as integer = 2
Dim L as double = 10
Dim p as double = 5
Dim R1 as double, R2 as double
Sub calcReac()
R2 = P*x / L
R1 = P R2
End sub
Data Types
Common
language Nominal
Visual Basic
runtime storage Value range
type
type allocation
structure
Boolean Boolean Depends on True or False
implementing
platform
Byte Byte 1 byte 0 through 255
(unsigned)
Char (single chara Char 2 bytes 0 through 65535
cter) (unsigned)
Date DateTime 8 bytes 0:00:00 (midnight)
on January 1,
0001 through
11:59:59 PM on
December 31,
9999
Data Types
Decimal Decimal 16 bytes 0 through +/-
79,228,162,514,264,337,593,543,950,33
5 (+/-7.9...E+28) with no decimal point;
0 through +/-
7.9228162514264337593543950335 with
28 places to the right of the decimal;
smallest nonzero number is +/-
0.0000000000000000000000000001 (+/-
1E-28)
Double (doub Double 8 bytes -1.79769313486231570E+308 through
le-precision -4.94065645841246544E-324 for
floating-po negative values;
int) 4.94065645841246544E-324 through
1.79769313486231570E+308 for
positive values
End Sub
Scope of variable (Assign)
Normally, a variable is in scope, or visible for
reference, throughout the region in which you
declare it.
In some cases, the variable's access level can
influence its scope.
Scope of variable
To make a variable visible only within a block
1. Place the Dim Statement (Visual Basic) for the variable between the
initiating and terminating declaration statements of that block, for
example between the For and Next statements of a For loop.
2. You can refer to the variable only from within the block.
To make a variable visible only within a procedure
1. Place the Dim statement for the variable inside the procedure but
outside any block (such as a With...End With block).
2. You can refer to the variable only from within the procedure, including
inside any block contained in the procedure.
Scope at Module or Namespace Level
1. For convenience, the single term module level applies equally to
modules, classes, and structures. The access level of a module level
variable determines its scope. The namespace that contains the
module, class, or structure also influences the scope.
Scope of variable
To make a variable visible throughout a module, class, or
structure
1. Place the Dim statement for the variable inside the module, class, or
structure, but outside any procedure.
2. Include the Private (Visual Basic) keyword in the Dim statement.
3. You can refer to the variable from anywhere within the module, class, or
structure, but not from outside it.
Expression
Constants and variables combined with algebraic /
logical operator is called expression
Can be algebraic or logical
If x > 3 then
Do something
End if
If 3*x = 4 then
Do something
End if
Statement
A single line of code which is compiled
successfully is called statement
Sub Procedure
Function
Sub Procedure
Sub-Procedure is a block of code which do
operation and do not report any result
or
Any code within sub / end sub is called sub
procedure
Sub are within block of sub / end sub
Statements within sub / end sub should be
limited to a dozen line of code
Sub may or may not accept arguments
Function
Function is a procedure which do required
operation and reports the result as well
Code within Function / End Function is called a
functions
Function always need arguments
These are also called mini-programs
Q&A
Define:
Variable
Constant
Expression
Statement
Scope of variable
Procedure
Sub Procedure
Function
Thanks