P. 1


|Views: 47|Likes:
Publicado pordjdan143

More info:

Categories:Types, Research
Published by: djdan143 on Apr 07, 2010
Direitos Autorais:Public Domain


Read on Scribd mobile: iPhone, iPad and Android.
download as PPT or read online from Scribd
See more
See less



Visual Basic 6 isual Program ogramming.



Course M urse Methods. 

Lectures. res. Handout no out notes. Supervised p vised practical work. Weekly submission of exercises. ly sub Weekly feedback on exercises. ly feed Model Answ l Answers. Final project : 12.00 Wed. 19th May 2004. projec Clinics for final Project. s f

Introduc troduction. 

A course in V e Visual Basic 6. Why Visual B isual Basic 6 (VB6)? Objectives : ves
‡ ‡ ‡ ‡ General education in computing. Gen Introduction to programming. Intro First write a simple program, then« Firs Write a more complex program. Wri 

Course Benef : Benefits
‡ I.T. is a part of all our lives and getting more so! ‡ VB6 and computing skills for other courses. Future ‡ Futu employment.



Tools For The Job. ols Fo 

Programmin Environment : amming 

CFS clien PC. S client Windows 2000. ndows Microsoft Visual Studio 6 SP5. rosoft Computer in G73 only at present! puters



Program ogramming Languag nguages. 

You are users! re use How compu computers work. Machine code. ine cod High level languages. l BASIC : Be C Beginners All purpose Symbolic Instruction C ction Code. Other languages : langu
‡ FOR FORTRAN, C/C++ & Java



Program ogramming Cycle. 

Analyse the task. se Plan the program, a structured approach! he pro Flowcharts & Pseudo-code (Week 2). harts Edit your source code. our so Execute and debug program (Week 2) te Edit source code as necessary. ource



Setting up VB6 on CFS. tting u
VB6 is part of MS Visual Studio 6. Select : Start Menu enu ms Programs Installable Software Insta ate Then navigate to : l Softw Central Software Programming Languages Progr k Double click on : Install MS Visual Studio V6 SP5 V
07/04/2010 7

VB6 Hel : MSDN. 6 Help 

Visual Stud 6 has an extensive, inbuilt l Studio help system call MSDN. MicroSoft ystem Developer Network. loper N Before this can be used select Setup Help e c for this session in the MS VS6 folder on sess the Program menu. ograms Only run this once per login session. thi 



Starting VB6. rting 

After setup a new folder is added to your tup programs menu. s men Select Micros Visual Basic 6 from the MS icrosoft Visual Studio V6 SP5 folder. Tip : Create a short cut on your desktop. reate This will start the VB6 IDE. ll Integrated Programming Environment. ted Pro Select Standa EXE as project type. ndard


The VB IDE. e 

Has Standar MicroSoft ³feel´. tandard Title Bar. St Status : Design, run, debug. Menu Bar. Pull down menus. P Tool Bar. Tool Box. For adding controls. F Project Explorer. List project modules. ct Exp Properties W rties Window. Form Layout. Layou

On we go go«



Structur of VB ucture Program ogram.
VB programs are made up of different rams subroutines (or procedures) of the form: nes (o Private S Sub <name>() Comment statement(s) t Declara ation statement(s) BASIC s statement(s) End Sub
07/04/2010 12

VB Statements. State 

Comments : Used to document programs ents and make them more readable. SE ake th THEM !!! M µ A C Comment! 

Terminate a program. inate End



Computers sto and add ers store numbers (very fast). s
Computer memory is divided into separate sections. ivided Each is identified by a numbe (its address). umber Alan Bruce Claire Dan Ethel ««.. A computer language allows us to identify these by names. ws Then to manipulate the number in them. umbers

Alan = Bruce + Claire Cla An assignment statement. nment
07/04/2010 14

Bits, bytes and nibb (its half a byte!). nibbles
8 bits make a byte 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 Each bit can be set to 1 or 0, so within one byte (8 bits) we can w represent numbers in the range 0 to 255 i.e. 2^8. nge Combining multiple bytes, we can store numbers: 16 bits = 2 bytes 32 bits = 4 bytes stores stores 2^16 = 0 to 65535 2^32 = 0 to 4294967295

These are whole numbers (integer no decimals allowed. integers), We are restricted to numbers +/- 2 billion. rs
07/04/2010 15

Different Forms of Storage. t Form 

A large number on a calculator is represented in exponential (also ator called scientific) format e.g. 1.23456E+23. . 1.23 If we take 4 bytes of memory, and store the mantissa (1.23456) in 3 ry, bytes, and the exponent (+23) in one byte, we can store real 3) o numbers, with a greater range. ge. Represent letters by a numerical code from 0 ± 255 (ASCII) and store rical c them in one byte. Text can then be stored as a linked set of bytes, b called a String. 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 ASCII 107 is k A ASCII 43 is +


Types of Variables. pes 

Integers (whole numbers) rs (wh Real numbe umbers.
Single. gle.  Double (t uble (twice the number of bytes).  


Strings. s. And others c thers coming later« Variants. nts.
All types automatically converting.  DANGER NGEROUS! ± Don¶t go there! 



Variable Names. riable
Data is stored as variables, each with a store different name. Variable names are: ent nam 

Case insensitive. insens Up to 255 c characters long. First charac must be a letter. haracter Can use any combination of alphanumeric se characters and the underscore character. cters a


Example amples.
Value 3radius Question& &Reply Density_o of_water lngRadius s1 yes no no yes yes



Hungari Notation. ngarian
A conventio of prefixes for variable vention names, depending on variable type. s, depe String : str Long Integer : lng Intege Double : db le dbl Currency : cur ncy c Integer : int Single : sng Boolean : bln Variant : vnt



Variable Types I riable
VB6 has 14 standard types. 

String : Hold characters, approx 231, can Hol be null (empty). Can be identified by $. ll (emp strTe ext$=³Hello.´ strEm mptyText = ³´



Variable Types II. riable 

Integer : Range ±32,768 to +32,767. Can r Ra be identified by %. ntified intVa alue% = 1 intVa alue2 = 1000 Long Integer : Larger range (231). Intege lngVa alue1& = 56000 lngVa alue2 = -56000


Variable Types III. riable 

Single Precision : Real numbers. Accuracy of 7 Precisi digits. sngRe eal_Number1! = 1.23 sngRe eal_Number2 = -0.345 Double Precision : Accuracy of 16 digits Precis dblVa alue1# = 0.435827348593 dblVa alue2 = 23.4782947373 

Reals are slower than integers in calculations!
07/04/2010 23

Variable Types IV. riable 

Boolean : True or False? an T blnAn nswer = False 

Other types include : Currency, Date, Byte (range 0 to 255) and variant (can be any e 2 data type ± very flexible, but dangerous!). ype v



Variable Type D ype Declarations I
Declare all variables before use! Good programming practice. efore u Also avoids having to use the suffixes $, #, ! etc. th Use the Dim statement. e.g. t. Dim <variable> as < <data type> Dim intDays as Inte teger Dim strText as Stri ring, dblAns as Double
07/04/2010 25

Variable Type De pe Declarations II
Declaring all variables before use is good programming befor practice. Use the ³Option Explicit´ command to make VB insist ion Ex of variables being declared before you can use them. lared b Option Explicit g us This also avoids having to use the suffixes $, #, ! etc, as all icitly d variable types are explicitly defined. rried o Note : This check is carried out when the program is run, not at the editing stage!
07/04/2010 26

Assignm signments I.  

5 basic math ic mathematical operators: Addition (+) ion (+ Subtraction (-) Division(/) ion(/) Multiplication (*) nentiation Exponentiat (^) Precedence follows BODMAS. dence Parentheses can be used to over ride theses precedence. dence. 6*5+4*3 gives 42 (((6 * 5) + 4) * 3) gives 102 (6


Assignm signments II.
<variable> = <value> | < lue> <variable> | <expression> Examples : intValue = 1 ext1 strText2 = strTe alue + 1 intValue = intVa gth^3.0 sngVol = sngLeng o´ strText = ³Hello *dblPi*dblRadius^3 dblVol= (4#/3#)*
07/04/2010 28

Print Statements. int Sta
Print <expr pression> Print Print Print Print ³Hell llo!´ ³Valu is ³; intValue lue ³A : ³; intA; ³ cm.´ dblRa Radius

We shall be using ³Text Boxes´! ll u
07/04/2010 29

Good Pr od Programming Style. le. 

Comment your program! ent yo Hungarian n arian notation for variable names. Use descrip escriptive variable names. Blanks lines may be used to improve s readability. bility. Indent code with ³tabs´. t



Referenc ferences.

MSDN On-lin Help. On-line Active subsection : subsec Visual Basic Documentation.



You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->