Download presentation
Presentation is loading. Please wait.
1
Visual Basic 6 Programming.
Lecture 1 : January 2005 Dr. Andrew Paul Myers 22/09/2018
2
Course Methods. Lectures. Handout notes. Supervised practical work.
Weekly submission of exercises. Weekly feedback on exercises. Model Answers. Final project : Wed. 19th May 2004. Clinics for final Project. 22/09/2018
3
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. 22/09/2018
4
Tools For The Job. Programming Environment : CFS client PC.
Windows 2000. Microsoft Visual Studio 6 SP5. Computers in G73 only at present! 22/09/2018
5
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 22/09/2018
6
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. 22/09/2018
7
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 22/09/2018
8
VB6 Help : MSDN. Visual Studio 6 has an extensive, inbuilt help system call MSDN. MicroSoft Developer Network. Before this can be used select Setup Help for this session in the MS VS6 folder on the Programs menu. Only run this once per login session. 22/09/2018
9
Starting VB6. After setup a new folder is added to your programs menu.
Select Microsoft Visual Basic 6 from the MS Visual Studio V6 SP5 folder. Tip : Create a short cut on your desktop. This will start the VB6 IDE. Integrated Programming Environment. Select Standard EXE as project type. 22/09/2018
10
The VB IDE. Has Standard MicroSoft “feel”.
Title Bar. Status : Design, run, debug. Menu Bar. Pull down menus. Tool Bar. Tool Box. For adding controls. Project Explorer. List project modules. Properties Window. Form Layout. 22/09/2018
11
On we go… 22/09/2018
12
Structure of VB Program.
VB programs are made up of different subroutines (or procedures) of the form: Private Sub <name>() Comment statement(s) Declaration statement(s) BASIC statement(s) End Sub 22/09/2018
13
VB Statements. Comments : Used to document programs and make them more readable. USE THEM !!! ‘ A Comment! Terminate a program. End 22/09/2018
14
Computers store and add numbers (very fast).
Computer memory is divided into separate sections. Each is identified by a number (its address). Alan Bruce Claire Dan Ethel …….. A computer language allows us to identify these by names. Then to manipulate the numbers in them. Alan = Bruce + Claire An assignment statement. 22/09/2018
15
Bits, bytes and nibbles (its half a byte!).
8 bits make a byte 1 Each bit can be set to 1 or 0, so within one byte (8 bits) we can represent numbers in the range 0 to 255 i.e. 2^8. Combining multiple bytes, we can store numbers: 16 bits = 2 bytes stores 2^16 = 0 to 65535 32 bits = 4 bytes stores 2^32 = 0 to These are whole numbers (integers), no decimals allowed. We are restricted to numbers +/- 2 billion. 22/09/2018
16
Different Forms of Storage.
A large number on a calculator is represented in exponential (also called scientific) format e.g E+23. If we take 4 bytes of memory, and store the mantissa ( ) in 3 bytes, and the exponent (+23) in one byte, we can store real numbers, with a greater range. Represent letters by a numerical code from 0 – 255 (ASCII) and store them in one byte. Text can then be stored as a linked set of bytes, called a String. 1 ASCII 107 is k ASCII 43 is + 22/09/2018
17
Types of Variables. Integers (whole numbers) Real numbers. Strings.
Single. Double (twice the number of bytes). Strings. And others coming later… Variants. All types automatically converting. DANGEROUS! – Don’t go there! 22/09/2018
18
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. 22/09/2018
19
Examples. Value yes 3radius no Question&Reply no Density_of_water yes
lngRadius1 yes 22/09/2018
20
Hungarian Notation. A convention of prefixes for variable names, depending on variable type. String : str Integer : int Long Integer : lng Single : sng Double : dbl Boolean : bln Currency : cur Variant : vnt 22/09/2018
21
Variable Types I VB6 has 14 standard types.
String : Hold characters, approx 231, can be null (empty). Can be identified by $. strText$=“Hello.” strEmptyText = “” 22/09/2018
22
Variable Types II. Integer : Range –32,768 to +32,767. Can be identified by %. intValue% = 1 intValue2 = 1000 Long Integer : Larger range (231). lngValue1& = 56000 lngValue2 = 22/09/2018
23
Variable Types III. Single Precision : Real numbers. Accuracy of 7 digits. sngReal_Number1! = 1.23 sngReal_Number2 = Double Precision : Accuracy of 16 digits dblValue1# = dblValue2 = Reals are slower than integers in calculations! 22/09/2018
24
Variable Types IV. Boolean : True or False? blnAnswer = False
Other types include : Currency, Date, Byte (range 0 to 255) and variant (can be any data type – very flexible, but dangerous!). 22/09/2018
25
Variable Type Declarations I
Declare all variables before use! Good programming practice. Also avoids having to use the suffixes $, #, ! etc. Use the Dim statement. e.g. Dim <variable> as <data type> Dim intDays as Integer Dim strText as String, dblAns as Double 22/09/2018
26
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! 22/09/2018
27
Assignments I. 5 basic mathematical operators:
Addition (+) Subtraction (-) Division(/) Multiplication (*) Exponentiation (^) Precedence follows BODMAS. Parentheses can be used to over ride precedence. 6 * * 3 gives 42 (((6 * 5) + 4) * 3) gives 102 22/09/2018
28
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 22/09/2018
29
Print Statements. We shall be using “Text Boxes”!
Print <expression> Print “Hello!” Print “Value is “; intValue Print “A : “; intA; “ cm.” Print dblRadius We shall be using “Text Boxes”! 22/09/2018
30
Good Programming Style.
Comment your program! Hungarian notation for variable names. Use descriptive variable names. Blanks lines may be used to improve readability. Indent code with “tabs”. 22/09/2018
31
References. Visual BASIC 6 from the ground up. Gary Cornell.
(Osborne). MSDN On-line Help. Active subsection : Visual Basic Documentation. 22/09/2018
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.