Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 8 What’s Wrong with It?

Slides:



Advertisements
Similar presentations
Chapter 7: Sub and Function Procedures
Advertisements

Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Finding and Debugging Errors
Chapter 2: Input, Processing, and Output
Visual Basic Debugging Tools Appendix D 6/27/20151Dr. Monther Aldwairi.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Apply Sub Procedures/Methods and User Defined Functions
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Variables and Constants
CS0004: Introduction to Programming Variables – Numbers.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Programming Translators.
Tutorial 11 Using and Writing Visual Basic for Applications Code
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Chapter 12: How Long Can This Go On?
Problem Solving with the Sequential Logic Structure Lesson 5 McManusCOP10061.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
Chapter 02 (Part III) Introduction to C++ Programming.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
ME 142 Engineering Computation I Debugging Techniques.
VB – Debugging Tools Appendix D. Why do we need debugging? Every program has errors, and the process of finding these errors is debugging Types of errors.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Problem Solving with Decisions
Lesson 5 McManus COP  Algorithm Instructions  Sequential Logic Structure  Solution Development McManusCOP10062.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 3: Chapter 3: Slide 1 Unit 3 Formatting Chapter 3 Input, Variables, Constants,
Debug in Visual Studio Windows Development Fundamentals LESSON 2.5A.
5.01 Understand Different Types of Programming Errors
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
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.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
Debugging M-Files Steve Gu Feb 08, Outline What’s Debugging? Types of Errors Finding Errors Debugging Example Using Debugging Features.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Visual Basic Fundamental Concepts
A variable is a name for a value stored in memory.
5.01 Understand Different Types of Programming Errors
ME 142 Engineering Computation I
1-1 Logic and Syntax A computer program is a solution to a problem.
Chapter 2: Input, Processing, and Output
Data Types, Arithmetic Operations
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Microsoft Access Illustrated
Introduction to VB programming
5.01 Understand Different Types of Programming Errors
Visual Basic..
CIS16 Application Development Programming with Visual Basic
Programming Right from the Start with Visual Basic .NET 1/e
CHAPTER FOUR VARIABLES AND CONSTANTS
Chapter 2: Input, Processing, and Output
Presentation transcript:

Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 8 What’s Wrong with It?

Objectives Locate syntax errors using the Error List window Locate a logic error by stepping through the code Locate logic errors using breakpoints Fix syntax and logic errors Clearly Visual Basic: Programming with Visual Basic 20082

There’s a Bug in my Soup! Downside to variables and named constants –Their use requires additional lines of code Bug –Error in a program’s code Debugging –Process of locating and correcting any bugs in a program Program bugs –Typically caused by either syntax errors or logic errors Clearly Visual Basic: Programming with Visual Basic 20083

Finding Syntax Errors Syntax error –Occurs when you break one of the language’s rules Code Editor –Detects most syntax errors as you enter instructions Clearly Visual Basic: Programming with Visual Basic 20084

Locating Logic Errors Logic error –Can occur for a variety of reasons –Difficult type of error to locate –Cannot be detected by Code Editor Clearly Visual Basic: Programming with Visual Basic 20085

Locating Logic Errors (continued) Debug the Discount application –Letter D at end of a value indicates value’s data type is Decimal Clearly Visual Basic: Programming with Visual Basic 20086

7

8

Locating Logic Errors (continued) Use a breakpoint to pause execution at a specific line in the code Debug the Hours Worked application –.0 at end of a number indicates that number’s data type is Double Clearly Visual Basic: Programming with Visual Basic 20089

10

Hawkins Solution

Public Class frmMain Dim decBegin As Decimal Dim decEarned As Decimal Dim decSpent As Decimal Dim decEnding As Decimal Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click ' calculates the ending balance based on the beginning ' balance, amount earned, and amount spent ' assign input to variables Decimal.TryParse(txtBegin.Text, decBegin) Decimal.TryParse(txtSpent.Text, decSpent) ' calculate and display ending balance decEnding = decBegin + decEarned - decSpent lblEnding = decEnding.ToString("C2") End Sub End Class

' calculates and displays your weight on planets and the moon ' Jupiter is 2.54 times earth weight, Venus is.91, Mars is.38, moon is.17

Public Class frmMain Dim dblEarth As Double Dim dblJupiter As Double: Dim dblVenus As Double Dim dblMars As Double: Dim dblMoon As Double Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click ' calculates and displays your weight on planets and the moon ' Jupiter is 2.54 times earth weight, Venus is.91, Mars is.38, moon is.17 ' calculate weights dblJupiter = dblEarth * 2.54 : dblVenus = dblEarth * 0.91 dblMars = dblEarth * 0.38 : dblMoon = dblEarth * 0.17 ' display weights lblJupiter.Text = dblJupiter.ToString("N2") lblVenus.Text = dblVenus.ToString("N2") lblMars.Text = dblMars.ToString("N2") lblMoon.Text = dblMars.ToString("N2") End Class

Martins Solution Answer should be $53.35

16 Private Sub btnGainLoss_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGainLoss.Click ' calculates and displays the gain or loss on a stock Dim intShares As Integer Dim decOpenPrice As Decimal Dim decClosePrice As Decimal Dim decGainLoss As Decimal ' assign input to variables Integer.TryParse(txtShares.Text, intShares) Decimal.TryParse(txtOpening.Text, decClosePrice) Decimal.TryParse(txtClosing.Text, decClosePrice) ' calculate and display gain or loss decGainLoss = decClosePrice - decOpenPrice * intShares lblGainLoss.Text = decGainLoss.ToString("C2") End Sub

Summary Program errors (bugs) –Caused by either syntax errors or logic errors Syntax errors in an application’s code –Listed in Error List window when you start the application You can locate logic errors by stepping through the code Letter D at the end of a value –Indicates value’s data type is Decimal Clearly Visual Basic: Programming with Visual Basic

Summary (continued).0 at the end of a number –Indicates that the number’s data type is Double Before viewing value stored in a control or variable –First consider the value you expect to find Clearly Visual Basic: Programming with Visual Basic