Variables: Variables Are Named Memory Locations Used To Store Values During Program Execution
Variables: Variables Are Named Memory Locations Used To Store Values During Program Execution
3. Long
4. Single
5. Double
6. Currency
7. Boolean
8. Date
9. Object
10. String
11. variant
Byte
occupies 8 bits( 1 byte ) of memory.
contain unsigned whole number.
small numbers.
Integer
occupies 16 bits ( 2 byes ) of memory
Hold whole numbers between -32,768
to 32,767
not appropriate for calculations
loops.
Long
long integers can be assigned much larger and
much smaller values than integers.
occupies 32 bits ( 4 bytes ) of memory.
precision.
Appropriate for very precise financial
flaoting-point numbers.
used for calculations requiring extreme
precision.
Calculations involving double data type
are slow.
currency
reserved for storing monitory values
such as bank account balances, prices.
currency values stored as very large
by 10000.
Boolean
Boolean variables accepts True or
False values.
stored internally as integer numbers.
True - -1
False - 0
The default value is 0 (False)
understand.
Date
date variables contains date and time
data.
Occupies 8 bytes of memory.
number.
String
string variable stores text data such
as name, addresses.
Also contains non-printable characters
such as Ctrl+G
String
Fixed length Strings
contains at most approximately
65,000 characters
declaration:
billion characters
declaration:
Basic projects
Object
example:
reusable code.
Variant
variant is default data type in Visual Basic
variant can accept any value.
Syntax
declaration.
Declaring Variables
It is possible to convert value of a variable
and asign to another variable.
explicit variable declarations are
unambiguous
example:
explicit declaration.
it is inserted at the top of a module
module as variant
requiring a variable declaration is a good
declaration.
a variable that can be seen and used by any procedure
throughout an application
public can be used only at module level and
a form.
Variable Scope and Lifetime
Scope
sStr = 12345.67890
dDbl = sStr
MsgBox Value of dDbl: & dDbl & vbCrLf & TypeName(dDbl) : &
TypeName( dDbl )
End Sub
message box reprts the value of dDbl as 12345.67890 and data type as
double.
Converting between
data types
automatic conversion is called coercion .
coercion will generate runtime error.
assigned to integers.
VBA language provide built-in conversion
functions.
Converting between
data types
automatic conversion is called coercion .
coercion will generate runtime error.
assigned to integers.
VBA language provide built-in conversion
functions.
data converted by the VBA conversion
elements
Declaring arrays
2 types:
types.
if no LowerBound value is provided, Vb
automatically assigns 0 .
Arrays
the Datatype of an array can be any valid VB
data type.
if the data type portion of the declaration is
Arrays limitations
Runtime errors
caused by hardware failures of one type or another.
example: failure of hard disk
errors is difficult.
there is API ( Windows application programming
together
within each data type group , arrange
selected line and you can check the values. Visual basic
shows a large brown dot in the margin to remind that there
is a breakpoint in that line.
o For example if you wanted to check the volume
Background Compile
variables, procedures , so on
insert Debug.Print statement to output messages
Sub MsgBoxCheck()
Dim i For i = 1 to 5
MsgBox I
Next I
End Sub
Traditional Debugging
Techniques
Uses of MsgBox
easy to use and can output any type of data
immediate window.
simple
Problems of MsgBox
example:
Traditional Debugging
Techniques
Traditional Debugging
Techniques
Benefits -Debug.Print
output goes to the Immediate window:
the user
Problems
window. But you can copy the contents to the windows clipboard
Long strings do not wrap in the immediate window unless
concatenate vbCrLf
immediate window must be brought to the inorder to view its
output.
more number of Debug.Print statement can slow the application.
Visual Basic Debugging Tools
suspending execution:
Examine variables:
toolbar.
to open this toolbar:-