Data Type.!
Data type
Storage
size
Range
Byte
1 byte
0 to 255
Boolean
2 bytes
True or False
Integer
2 bytes
-32,768 to 32,767
4 bytes
-2,147,483,648 to 2,147,483,647
Currency (scaled
integer)
-922,337,203,685,477.5808 to
922,337,203,685,477.5807
8 bytes
Data Type.!
Data type
Storage size
Range
Date
8 bytes
Object
4 bytes
String (variable-length)
0 to approximately 2 billion
String (fixed-length)
Length of string
1 to approximately 65,400
16 bytes
Number required by
elements
Data Type.!
Variables
Variables
Variable Names.
Variable Names
The following are the rules when naming the variables in Visual
Basic
------ It must be less than 255 characters
------No spacing is allowed
------It must not begin with a number
-------Period is not permitted
Examples of valid and invalid variable names are displayed
below:
Valid Name
Invalid Name
My_Car
My.Car
this year
1NewBoy
Long_Name_Can_beUSE
He&HisFather
*& is not acceptable
Assigning Values to
Variables.
Assigning Values to
Variables.
Label1.Visible = True
Command1.Visible = false
Label4.Caption = textbox1.Text
ThirdNumber = Val(usernum1.Text)
total = firstNumber + secondNumber
+ThirdNumber
Assigning Data to an
Existing Variable
Assignment statement
variablename = value
Value does not change while an application is running
Declaring Variable....
Declaring Variable....
Declaring Variable....
Declaring Variable....
In this final example, what are the types assigned to the three
variables:
Dim Amount1, Amount2,
Amount3 As Single
All Single-precision floating point, But only Amount3 is Single.
Amount1 and Amount2 are considered Variant because VB
specifies that each variable in a statement must be explicitly
declared. Thus Amount1 and Amount2 take the default data type.
Named Constants
Named constant
Named Constants
(continued)
Definition
Example
Result
4^2
16
Multiply
5*4
20
Divide
20 / 4
Add
3+4
Subtract
7-3
Mod
Remainder of
division
20 Mod 6
Integer division
20 \ 6
&
String concatenation
"Joan Smith"
Logical operators.
Operator
Definition
Example
Result
Equal to
9 = 11
False
>
Greater than
11 > 9
True
<
Less than
11 < 9
False
>=
Greater or equal
15 >= 15
True
<=
Less or equal
9 <= 15
True
<>
Not equal
9 <> 9
False
AND
Logical AND
(9 = 9) AND (7 False
= 6)
OR
Logical OR
(9 = 9) OR (7
= 6)
True
Suffixes..
Suffixes..
Logical Operators..
Logical Operators
In addition to conditional operators, there are a few
logical operators which offer added power to the VB
programs. There are shown below
Operator
Meaning
And
Both sides must be true
or
One side or other must be true
Xor One side or other must be true but not both
Not
Negates truth
Thank You
Making Decisions in
Programs
Sequence structure
Selection structure
Repetition structure
Selection structure
The MessageBox.Show
Method
Syntax
MessageBox.Show(text, [caption,
buttons, icon[,defaultButton])
The If/ElseIf/Else
Structure
Repeating Program
Instructions
Objectives
Pretest loop
Posttest loop
Repetition statements
For...Next
Do...Loop
For Each...Next
The DoLoop
Statement(continued)
Function
InputBox function
Thank You