Beruflich Dokumente
Kultur Dokumente
Programming.
Lecture 1 : January 2005
Dr. Andrew Paul Myers
10/04/2019 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.
10/04/2019 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.
10/04/2019 3
Tools For The Job.
Programming Environment :
10/04/2019 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
10/04/2019 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.
10/04/2019 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
10/04/2019 7
VB6 Help : MSDN.
Visual Studio 6 has an extensive, inbuilt
help system call MSDN. MicroSoft
Developer Network.
10/04/2019 8
Starting VB6.
After setup a new folder is added to your
programs menu.
10/04/2019 11
Structure of VB
Program.
VB programs are made up of different
subroutines (or procedures) of the form:
‘ A Comment!
Terminate a program.
End
10/04/2019 13
Computers store and add
numbers (very fast).
Computer memory is divided into separate sections.
Each is identified by a number (its address).
1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1
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!
10/04/2019 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.
10/04/2019 18
Examples.
Value yes
3radius no
Question&Reply no
Density_of_water yes
lngRadius1 yes
10/04/2019 19
Hungarian Notation.
A convention of prefixes for variable
names, depending on variable type.
10/04/2019 20
Variable Types I
VB6 has 14 standard types.
strText$=“Hello.”
strEmptyText = “”
10/04/2019 21
Variable Types II.
Integer : Range –32,768 to +32,767. Can
be identified by %.
intValue% = 1
intValue2 = 1000
10/04/2019 23
Variable Types IV.
Boolean : True or False?
blnAnswer = False
10/04/2019 24
Variable Type Declarations I
Declare all variables before use! Good programming practice.
Also avoids having to use the suffixes $, #, ! etc.
10/04/2019 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
Note : This check is carried out when the program is run, not at
the editing stage!
10/04/2019 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
10/04/2019 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
10/04/2019 28
Print Statements.
Print <expression>
Print “Hello!”
Print “Value is “; intValue
Print “A : “; intA; “ cm.”
Print dblRadius
10/04/2019 30
References.
Visual BASIC 6 from the ground up.
Gary Cornell.
(Osborne).
10/04/2019 31