Visual Basic 6.0
Visual Basic 6.0
2
Title Bar
Menu Bar
Tool Bar
Project Explorer
Toolbox
View Code
Window
Form Designer
Properties Window
View Object
Window
3
INTRODUCTION TO VISUAL BASIC CONTROLS
4
INTRODUCTION
Variables
Data name, used to store a data value which can be changed during program
execution.
Constants
Constants refer to fixed values that do not change during the execution of a program.
Operators
An operator is a symbol that tells the computer to perform certain mathematical or
logical manipulations.
6
RULES FOR DECLARING VARIABLES
Variable name must begin with an alphabet.
Variable names cannot exceed 255 characters.
Variables should not contain a period(.)
Variable names should be unique in the declared context.
7
KEYWORDS
Reserved words.
Cannot be used as names for the program variables or other user-defined program
elements.
Loop LSet Me Mod
8
OPERATORS
Type Operators
Arithmetic Operators +, -, *, /, mod, ^
Comparison Operators =, <>, >, <, >=, <=
Logical/Relational Operators AND, OR, NOT, XOR
Concatenation Operators + (effective on strings), &
9
EXAMPLE
10
SCOPE OF THE VARIABLES
Description
• Variables declared using “Dim” keyword
at script level are available to all the
procedures within the same script.
Dim
• Variables declared using “Dim” keyword
at a Procedure level are available only
within the same procedure.
Variables declared using "Public" keyword
Public are available to all the procedures across all
the associated scripts.
Variables that are declared as "Private" have
Private scope only within that script in which they
are declared.
11
SIMPLE If STATEMENT
An if statement consists of a Boolean expression followed by one or more statements.
If the Boolean expression evaluates to true, then the block of code inside the if
statement will be executed. If the Boolean expression evaluates to false, then the first
set of code after the end of the if statement will be executed.
13
EXAMPLE
14
If…Else STATEMENT
An if statement can be followed by an optional else statement, which executes when
the Boolean expression is false.
If the Boolean expression evaluates to true, then the if block will be executed,
otherwise, the else block will be executed.
15
EXAMPLE
16
NESTED If OR If…Else STATEMENTS
Use of one if or if…else statement inside another if or if…else statement(s).
17
EXAMPLE
18
If…ElseIf LADDER STATEMENT
The if…elseif statement is used to execute one code from multiple conditions.
19
EXAMPLE
20
Select Case STATEMENT
A select case statement allows a variable to be tested for equality against a list of
values known as case.
21
EXAMPLE
22
Option Button
23
Check Box
24
WHAT IS LOOP?
A loop in VBScript is used to execute a block of code or a part of the program for
several times.
It saves code.
26
TYPES OF LOOPS
LOOPS
do do…loop do for...next
while…wend
while…loop while until…loop loop
27
Do While…Loop
The do while statements will be executed as long as condition is True.
28
EXAMPLE
29
While…Wend
Tests the condition before executing the loop body.
30
EXAMPLE
31
Do…Loop While
Iterates the code until the condition is false.
Condition is given after the code. So at least once the code is executed whether the
condition is true or false.
32
EXAMPLE
33
Do Until…Loop
The do..until statements will be executed as long as condition is False.
34
EXAMPLE
35
For...Next LOOP
A for loop is a repetition control structure that allows a developer to efficiently write a
loop that needs to execute a specific number of times.
36
EXAMPLE
37
WHAT IS AN ARRAY?
Collection of elements (data) in a single variable.
Linear Data Structure
- A data structure (data organization and storage format that enables efficient
access and modification) is said to be linear if the elements form a sequence.
39
EXAMPLE (1D ARRAY)
40
EXAMPLE (2D ARRAY)
41
FUNCTION VS SUB PROCEDURE
Function Sub Procedure
A single block of code written to A single block of code written to
perform a specific task that may perform a specific task that does
or may not return a value. not return a value.
Functions are always enclosed Sub procedures are always
within Function and End Function enclosed within Sub and End
statements. Sub statements.
43
EXAMPLE (FUNCTION)
44
EXAMPLE (PROCEDURE)
45
STEPS (VB 6.0 – MS ACCESS CONNECTION)
47
EXAMPLE
48
EXAMPLE
50
EXAMPLE
52
EXAMPLE
54
EXAMPLE
56
EXAMPLE
58
EXAMPLE
60
REFERENCES
Courtesy of FreeTutes - Visual Basic Tutorials. URL:
http://www.freetutes.com/learnvb6
Courtesy of TutorialsPoint – VBScript Tutorial. URL:
http://www.tutorialspoint.com/vbscript
Courtesy of JavaTPoint – C Programming Language Tutorial. URL:
http://www.javatpoint.com/c-programming-language-tutorial
61