M Dixon 1 04 – Data Types & Debugging. Questions: Expressions a)What is the result of: 7 + Int(8.245) b)Write an expression to: put a random number into.

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Advertisements

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Mark Dixon, SoCCE SOFT 136Page 1 02 – Software Development Life-Cycle.
Mark Dixon Page 1 05 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon Page 1 02 – Dynamic HTML (client-side scripting)
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging & Graphics.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Tutorial 10 Programming with JavaScript
How to Debug VB .NET Code.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Software Development Lifecycle, & User Interface Design.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon Page 1 04 – Data Types. Mark Dixon Page 2 Admin: On-line Quiz.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
02 – Client-side code: JavaScript
Mark Dixon 1 07 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
Mark Dixon 1 05 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6 words) currently.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Input, Output, and Processing
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Mark Dixon 1 11 – Array Variables. Mark Dixon 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon Page 1 06 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Mark Dixon 1 08 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Introduction to Programming with RAPTOR
Mark Dixon Page 1 05 – Problem Solving & Data Types.
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
M Dixon 1 03 – Dynamic HTML (client-side scripting)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon 1 03 – Information Processing. Mark Dixon 2 Questions: Events Consider the following code: a) How many unique events does it contain? b) Name.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon 1 9 – Case Study. Mark Dixon 2 Session Aims and Objectives Aims –To give an overview of the development of a web-page from initial idea to.
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
1 JavaScript in Context. Server-Side Programming.
Mark Dixon 1 06 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 7 50 minutes short answer (5 - 6 words max)
Mark Dixon Page 1 05 – Problem Solving & Data Types.
M Dixon 1 02 – Dynamic HTML (client-side scripting)
31/01/ Selection If selection construct.
Mark Dixon Page 1 04 – Conditional Execution. Mark Dixon Page 2 Questions: Expressions a)What is the result of: 10 * Int( ) b)How many functions.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Mark Dixon Page 1 03 – Information Processing: Expressions, Operators & Functions.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Mark Dixon Page 1 09 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of VBScript code to declare a variable called h Write.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
Mark Dixon Page 1 03 – Information Processing: Expressions, Operators & Functions.
A variable is a name for a value stored in memory.
04 – Information Processing: Expressions, Operators & Functions
02 – Information Processing
06 – Conditional Execution
Testing and Debugging.
CIS16 Application Development Programming with Visual Basic
Tonga Institute of Higher Education
Presentation transcript:

M Dixon 1 04 – Data Types & Debugging

Questions: Expressions a)What is the result of: 7 + Int(8.245) b)Write an expression to: put a random number into txtRand 15 txtRand.value = Rnd()

Question: Pseudo-code Write VBScript code that does the following: when btnDown is clicked read txtNum subtract 1 put in txtRes Sub btnDown_onClick() End Sub txtNum.value - 1 txtRes.value =

M Dixon 4 Session Aims & Objectives Aims –to introduce the idea of types of data –introduce you to the interactive debugger Objectives, after this week’s sessions, you should be able to: –recognise different types of data numeric string (text) –correct errors relating to data types –Use Debugger to locate and fix errors

Example: AddNum v1 Add Numbers Sub btnAdd_OnClick() parResult.innerText = txtNum1.value + txtNum2.value End Sub Doesn't work!

Types of Information Numeric (numbers)29 (integer/whole) (real/decimal) String (text)"Hello there!" "BOO" Pictures (numbers) Sound (numbers)

AddNum problem The + operator works with: –numbers, and –text "23" + "16" "2316" double quotes enclose text Text input boxes store text: txtNum1.value + txtNum2.value We need to convert text to numbers

String Functions CInt("63") convert to integer result is 63 Left("boo",2) left stringresult is "bo" Right("hello",3) right stringresult is "llo" Mid("hello",2,3) middle stringresult is "ell" Len("S Smith") lengthresult is 7 Space(5) spacesresult is " "

The Empty String Two double quotes (no space between) "" Used to clear contents: txtNum.value = ""

String Expressions

Questions: String Expressions a)What is the result of: Mid("what is the time?", 3, 4) b)What is the result of: Left("bob", 2) & Right("sal", 1) c)Write an expression to: convert "16" to a number d)Write an expression to: give the first two letters of "Mr John Smith" "at i" "bol" CInt("16") Left("Mr John Smith", 2)

String Expressions same pattern as numeric expressions: "What is " & txtN1.value & " times " data operator data operator

String Expressions & Errors "What is twice " txtN1.value & "?" "What is 6 minus " & & txtN1.value & "?" "This is a number & txtN1.value ERROR! missing data ERROR! missing operator ERROR! missing "

Example: AddNum v2 Add Numbers Sub btnAdd_OnClick() parResult.innerText = CInt (txtNum1.value) + CInt (txtNum2.value) End Sub

M Dixon 15 Error Types –syntax: computer unable to understand your instructions (program does not execute), e.g. –run-time: program can't execute instruction and exits (future lecture) –logical: program executes but does not match specification (do what was intended), e.g. 3 error types :

M Dixon 16 Errors: Syntax Code cannot be understood missing ( syntax error Browsers often ignore code with errors

M Dixon 17 Errors: Run time Code cannot be executed Computer –just symbol matching –No intelligence missing e run time error

M Dixon 18 Errors: Logical Code does not do what you wanted blue instead of red

M Dixon 19 Questions: Errors Spot the errors (you should find 6), and decide whether they are syntax or logical Hello Sub btnBlue_OnCluck() document.bgColor = "Red" End Sub Sub btnRed_Onlick() document.bgColor "Red" End Sub Sub window_OnClick() document.bgColour = "White" End Sib

M Dixon 20 Debugging key skill: –locate the cause of a bug using testing methods first step –narrow it down as much as possible typical pattern in early tutorials: –student: it doesn't work –lecturer: what doesn't work –student: my code –lecturer: yes, but which bit exactly –student: ???? –lecturer: run your program, take me through it, which bits work, and where exactly does it go wrong –student: when I click this, nothing happens –lecturer: which bit of code is responsible for doing that? –student: this bit

M Dixon 21 Debugging Process What happens when run? –Nothing? –Errors (syntax, or run-time)? –Does the wrong thing (logical error)?

M Dixon 22 Debugging Process murder investigation –who-done-it? doctor treating patient –diagnosis –treatment scientific: –observation –experimentation (systematic)

Example: Drinks SPECIFICATION User Requirements –Students wish to decide which supermarket sells drinks at the best price Software Requirements –Functional: –user enters offer details (bottle size, number of bottles, and price) –computer calculates bottle price and price per pint –Non-functional should be easy to use

Example: Drinks What happens when run? –Nothing? –think of murder investigation who-done-it? –input boxes, button, and text displays therefore: html works! –button does not respond therefore: prime suspect is button code

Example: Drinks (with ERRORS) Bottle Size: ml Quantity: Price (£): £ per bottle £ per pint Sub Calc_onClick() lblBottlePrice.innerText = txtQty.valu / txtPrice.value lblPintPrice.innerText = lblBottlePrice.innerText * (568 / txtBottleSize.value) End Sub

Breakpoints Examine code line by line –can help, but time consuming Breakpoint (press F9 on keyboard):

Breakpoints Breakpoint: like DVD pause, when line hit Logic: –if breakpoint hit, code will pause, therefore event handler is OK, must be code –if nothing happens, breakpoint not hit, therefore event handler not working (this is what happens – check name)

Example: Drinks (with ERRORS) Bottle Size: ml Quantity: Price (£): £ per bottle £ per pint Sub Calc_onClick() lblBottlePrice.innerText = txtQty.valu / txtPrice.value lblPintPrice.innerText = lblBottlePrice.innerText * (568 / txtBottleSize.value) End Sub

Debugging: Breakpoint hit After event-handler fixed –breakpoint hit, code paused

Debugging Can run 1 line – press F8 on keyboard Always click Break (this means pause) Always read message

Debugging – Stop Button Click Stop button, to edit code

Debugging: Check output Is this right? –if each bottle is 0.8, then 0.8 * quantity should be same as price –0.8 * 4 = 3.2 –this is wrong –therefore: bottle price must be wrong

Debugging: Immediate Window Use ? to ask ‘what is in txtQty.value’ F8 run single line

Remarks Comments – ignored by computer: ' VB uses an apostrophe for comments. Sub btnClear_onClick() txtNum1.Value = 0 ' put 0 into txtNum1 End Sub useful for: –learning (you can explain your code) –giving additional information (professional) –disable line (rather than delete it)

Example: Ball Character (design) WHEN Right button Clicked move ball character right WHEN Left button Clicked move ball character left WHEN Up button Clicked move ball character up WHEN Down button Clicked move ball character down

Absolute Positioning change properties – change position picBall.style.posTop picBall.style.posLeftpicBall.width picBall.height document.body.clientWidth

Example: Ball Character (script) Ball Character Sub window_onLoad () picBall.style.posLeft = 200 picBall.style.posTop = 100 End Sub Sub btnRight_onClick () picBall.style.posLeft = picBall.style.posLeft + 10 End Sub

Substitution Programming = different to maths = Right hand side Reads (source) Left hand side Writes (destination)

Tutorial Exercises: AddNum LEARNING OBJECTIVE: use a function to convert string (text) to integer (number) data Task 1: get the addnum examples (v1 and v2) working

Tutorial Exercises: Drinks LEARNING OBJECTIVE: use interactive debugger to identify and correct errors Task 1: Create a new project, and type in the code for the drinks example. Running it should display the html, but the calc button does nothing. Task 2: Use the interactive debugger to identify and correct the errors in the code.

Tutorial Exercise: Ball Char LEARNING OBJECTIVE: to understand objects, events, properties, and event handler procedures, so that you can create dynamic content in your web-pages TASK 1: Get the Right and Down buttons from the Ball Character example working. (code provided, images in resources area on server). TASK 2: Get the Left and Up buttons working. (You will need to work out what code to use. Use the code provided as inspiration) TASK 3: Make the Ball Character blink when the user moves the mouse over it. (add code that changes the picture – like the Puppy example) TASK 4: Add a button to move the Ball Character diagonally. (You will need two lines of code in the same event handler)