Visual Basic 6 Programming
Visual Basic 6 Programming
Programming.
11/04/21 1
Course Methods.
Lectures.
Handout notes.
Supervised practical work.
Weekly submission of exercises.
Weekly feedback on exercises.
Model Answers.
Final project : 12.00 Wed. 19th May 2004.
Clinics for final Project.
11/04/21 2
Introduction.
A course in Visual Basic 6.
Why Visual Basic 6 (VB6)?
Objectives :
• General education in computing.
• Introduction to programming.
• First write a simple program, then…
• Write a more complex program.
Course Benefits :
• I.T. is a part of all our lives and getting more so!
• VB6 and computing skills for other courses.
• Future employment.
11/04/21 3
Tools For The Job.
Programming Environment :
11/04/21 4
Programming
Languages.
You are users!
How computers work.
Machine code.
High level languages.
BASIC : Beginners All purpose Symbolic
Instruction Code.
Other languages :
• FORTRAN, C/C++ & Java
11/04/21 5
Programming Cycle.
Analyse the task.
Plan the program, a structured approach!
Flowcharts & Pseudo-code (Week 2).
Edit your source code.
Execute and debug program (Week 2)
Edit source code as necessary.
11/04/21 6
Setting up VB6 on CFS.
VB6 is part of MS Visual Studio 6.
Select :
Start Menu
Programs
Installable Software
Then navigate to :
Central Software
Programming Languages
Double click on :
Install MS Visual Studio V6 SP5
11/04/21 7
VB6 Help : MSDN.
Visual Studio 6 has an extensive, inbuilt
help system call MSDN. MicroSoft
Developer Network.
11/04/21 8
Starting VB6.
After setup a new folder is added to your programs
menu.
11/04/21 11
Structure of VB
Program.
VB programs are made up of different
subroutines (or procedures) of the form:
‘ A Comment!
Terminate a program.
End
11/04/21 13
Computers store and add
numbers (very fast).
Computer memory is divided into separate sections.
Each is identified by a number (its address).
0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1
Strings.
And others coming later…
Variants.
All types automatically converting.
DANGEROUS! – Don’t go there!
11/04/21 17
Variable Names.
Data is stored as variables, each with a
different name. Variable names are:
Case insensitive.
Up to 255 characters long.
First character must be a letter.
Can use any combination of alphanumeric
characters and the underscore character.
11/04/21 18
Examples.
Value yes
3radius no
Question&Reply no
Density_of_water yes
lngRadius1 yes
11/04/21 19
Hungarian Notation.
A convention of prefixes for variable
names, depending on variable type.
11/04/21 20
Variable Types I
VB6 has 14 standard types.
strText$=“Hello.”
strEmptyText = “”
11/04/21 21
Variable Types II.
Integer : Range –32,768 to +32,767. Can
be identified by %.
intValue% = 1
intValue2 = 1000
11/04/21 23
Variable Types IV.
Boolean : True or False?
blnAnswer = False
11/04/21 24
Variable Type Declarations I
Declare all variables before use! Good programming practice.
Also avoids having to use the suffixes $, #, ! etc.
11/04/21 25
Variable Type Declarations II
Declaring all variables before use is good programming practice. Use the
“Option Explicit” command to make VB insist of variables being declared
before you can use them.
Option Explicit
This also avoids having to use the suffixes $, #, ! etc, as all variable types are
explicitly defined.
Note : This check is carried out when the program is run, not at the editing
stage!
11/04/21 26
Assignments I.
5 basic mathematical operators:
Addition (+) Subtraction (-)
Division(/) Multiplication (*)
Exponentiation (^)
Precedence follows BODMAS.
Parentheses can be used to over ride
precedence.
6*5+4*3 gives 42
(((6 * 5) + 4) * 3) gives 102
11/04/21 27
Assignments II.
<variable> = <value> | <variable> | <expression>
Examples :
intValue = 1
strText2 = strText1
intValue = intValue + 1
sngVol = sngLength^3.0
strText = “Hello”
dblVol= (4#/3#)*dblPi*dblRadius^3
11/04/21 28
Print Statements.
Print <expression>
Print “Hello!”
Print “Value is “; intValue
Print “A : “; intA; “ cm.”
Print dblRadius
11/04/21 30
References.
11/04/21 31