mark dixon, socce soft 131page 1 03 – debugging, sound, and graphics

23
Mark Dixon, SoCCE SOFT 131 Page 1 03 – Debugging, Sound, and Graphics

Post on 22-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 1

03 – Debugging, Sound,and Graphics

Page 2: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 2

Session Aims & Objectives• Aims

– introduce you to the fundamentals of:• debugging• sound, and• graphics

• Objectives, by end of this week’s sessions, you should be able to:

– identify & correct simple errors in your applications– put bitmap (raster) graphics into your applications– draw simple vector graphics in your applications– play MP3 and WAV files in your applications

Page 3: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 3

Testing & Debugging: Errors• 3 error types :

– syntax: computer unable to understand your instructions (program does not execute), e.g.

• variable not defined (probably most common)

– run-time: program can't execute instruction and exits (future lecture)

• Device unavailable (e.g. floppy drive)

– logical: program executes but does not not match specification (do what was intended), e.g.

• clicking on button does nothing, when you thought you attached code to it

• clicking on blue button changes colour to red (when it should change to blue)

Page 4: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 4

• Computer – just symbol matching– No intelligence

Example: Hello Errors

Sub Command1_Cluck LabelL.Caption = "Hello"End Sub

L instead of 1: causes syntax error (variable not defined)

u instead of i: causes logical error (Command1 button does nothing)

Page 5: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 5

Exercise: Errors

• The following example is from lecture 1,– Spot the errors (you should find 6), and– decide whether they are syntax or logical

Private Sub btnBlue_Cluck() lblResult.BackColor = vbRedEnd Sub

Private Sub btnRed_lick() lblResult.BackColor vbRedEnd Sub

Private Sub lb1Result_DblClick() lblResult.BackColour = vbWhiteEnd Sub

Page 6: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 6

Debugging: Testing

• Functional Decomposition– break it into logical chunks

• Incremental Development– type a bit– test it

• Testing– test all/most combinations

• Regression Testing– repeat all previous tests

Page 7: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 7

Types of Graphics: Raster

• Raster graphics – made of dots (pixels – picture elements)– stored in .jpg, .bmp, and .gif files– suitable for complex, static pictures (e.g. photos)– difficult to change programmatically– loses quality when enlarged:

Page 8: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 8

Types of Graphics: Vector

• Vector graphics – made of objects (lines, circles, etc.)– suitable for simple, dynamic pictures (diagrams)– No loss of quality when enlarged

Page 9: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 9

Example: PicView - AnalysisSPECIFICATION

• User Requirements – display photos quickly and easily one after another

• Software Requirements– Functional:

–change current folder and drive–display list of picture files in current folder–display picture (*.jpg, *.bmp, and *.gif) from files

in current folder– Non-functional

should be quick and easy to use PicView

Page 10: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 10

Controls

• Picture Box: display pictures

• Drive List Box: allow user to select disk drive

• Directory List Box: allow user to select folder

• File List Box: allow user to select file

Page 11: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 11

Controls' Properties• Picture Box (pic)

– Picture: allows display of bitmap (raster graphic) as background

• Drive List Box (drv)– Drive: the currently selected disk drive

• Directory List Box (dir)– Path: the currently selected directory (folder)

• File List Box (fil)– Path: the currently selected folder/directory– Pattern: only display this type of file (e.g. .jpg)– FileName: the currently selected file

Page 12: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 12

Example: PicView - Design

• User interface design:

• Functional design:

Trigger (when) Actions (what)click event of Drive Box make drive current (directory box

points to this drive)

click event of Directory Box make folder current (file box points to this folder)

click event of File Box display selected picture in picture box

Page 13: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 13

Example: PicView - Code

Option Explicit

Private Sub drvMain_Change() dirMain.Path = drvMain.DriveEnd Sub

Private Sub dirMain_Change() filMain.Path = dirMain.PathEnd Sub

Private Sub filMain_Click() picMain.Picture = LoadPicture(filMain.Path & "\" & filMain.FileName)End Sub

drvMain

dirMain

picMain

filMain

Page 14: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 14

Vector Graphics: Grid System

• the origin (position 0,0) is at top left– in mathematics it is always bottom left

200010000

0

1000

Page 15: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 15

Picture Box: Drawing Methods

• Methods (vector graphics)– Line: draws a straight line between 2 points– Circle: draws a circle– PSet: draws a dot (point)– Cls: clears (screen) drawing area

Page 16: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 16

Example: Shapes

• Form and Picture Box control support graphics methods:

0 200010000

1000

picDisplayArea.Line (500, 200)-(1900, 800)picDisplayArea.Line -(2600, 600)picDisplayArea.Line -Step(-600, -400)

picDisplayArea.PSet (1500, 1000)picDisplayArea.Circle (700, 900), 300

Shapes

Page 17: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 17

Example: StickMan

• Enabled property (true or false)

StickMan

200010000

0

1000

Page 18: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 18

Example: Face

Face

Page 19: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 19

Example: Music Player - Analysis

• User Requirement: – to play different music for long time without

interruption, at same location (while working or at party)

• Software Requirements Specificationsoftware should:– allow user to:

• select track (MP3 file) from folder on disk• play selected track

– automatically• move to next track in folder• go back to first after last has played

later lecture

Page 20: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 20

Additional Controls

• VB has hundreds of controls

• To include additional controls in your project:– Project menu– Components item

• Multimedia Control– plays

MP3 & WAV files

Page 21: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 21

Multimedia Controls' Properties

• Multi-media Control– FileName: name of file to play– Command: controls playback

Page 22: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 22

Example: Music Player - Design

• Compare the following User Interface Designs:

V0 V1

Page 23: Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics

Mark Dixon, SoCCE SOFT 131 Page 23

Example: Music Player - CodeOption Explicit

Private Sub drvMain_Change() dirMain.Path = drvMain.DriveEnd Sub

Private Sub dirMain_Change() filMain.Path = dirMain.PathEnd Sub

Private Sub filMain_Click() mmcMain.Command = "Close" mmcMain.FileName = filMain.Path & "\" & filMain.FileName mmcMain.Command = "Open"End Sub

drvMain dirMain

filMainmmcMain