1 / 37

Objectives

Tutorial 6 – Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic.

roland
Download Presentation

Objectives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 6 – Enhancing the Inventory ApplicationIntroducing Variables, Memory Concepts and Arithmetic Outline6.1 Test-Driving the Enhanced Inventory Application6.2 Variables6.3 Handling the TextChanged Event6.4 Memory Concepts6.5 Arithmetic6.6 Using the Debugger: Breakpoints6.7 Internet and Web Resources6.8 Wrap-Up

  2. Objectives • In this tutorial, you will learn to: • Create variables. • Handle the TextChanged event. • Apply basic memory concepts using variables. • Use the precedence rules of arithmetic operators. • Set breakpoints to debug applications.

  3. 6.1 Test-Driving the Enhanced Inventory Application

  4. 6.1 Test-Driving the Enhanced Inventory Application • Running the application Figure 6.1 Inventory application GUI displayed when the application is executed.

  5. 6.1 Test-Driving the Enhanced Inventory Application • Using the application • Enter data into the TextBoxes and click theCalculate TotalButton • Notice the result Figure 6.2 Running the Inventory application.

  6. Cleared output Label 6.1 Test-Driving the Enhanced Inventory Application • Notice the new feature • The output Label is cleared when new data is entered Figure 6.3 Modified Inventory application clears output Label after new input.

  7. 6.2 Variables • Adding code to the application • Declaring a variable • Keyword Dim • Data types • Built-in data type • Primitive data type

  8. Click event handler Variable declarations 6.2 Variables Figure 6.4 Declaring variables in event handler btnCalculate_Click.

  9. 6.2 Variables • Retrieving data from the user • Data is stored in the TextBox’s Text property • The Val function • Returns data type Double • Implicit conversion

  10. Assigning user input to variables 6.2 Variables Figure 6.5 Retrieving numerical input from TextBoxes.

  11. 6.2 Variables

  12. 6.2 Variables • Perform the multiplication • Displaying the result • Set the multiplication result to the Label’s Text property

  13. Calculating and displaying the result 6.2 Variables Figure 6.7 Multiplication, using variables in btnCalculate_Click.

  14. Result of calculation 6.2 Variables • Running the application • Enter data • Click the Calculate TotalButton • Notice the result Figure 6.8 Displaying the multiplication result using variables.

  15. 6.3 Handling the TextChanged Event • Create the event handler for the first TextBox • Double click the TextBox • TextChangedevent handler is created • Clearing the value • Use empty string • Repeat for second TextBox

  16. TextChanged event handler 6.3 Handling the TextChanged Event Figure 6.9 TextChanged event handler for Cartons per shipment:TextBox.

  17. 6.3 Handling the TextChanged Event Figure 6.10 TextChanged event handler for Items per carton:TextBox.

  18. Use keyword Dim to declare variables inside an event handler Assigning a property’s value to a variable Assigning a variable to a property Inventory.vb(1 of 2)

  19. Setting a TextBox’s Text property to an empty string Inventory.vb(2 of 2)

  20. 6.4 Memory Concepts • A simple variable • Corresponds to actual location in the computer’s memory • Name • Type • Size • Value Figure 6.12 Memory location showing name and value of variable intCartons. intCartons 12

  21. 10 12 6.4 Memory Concepts • Visualizing data • The value of each variable is stored in a separate memory location Figure 6.13 Memory locations after values for variables intCartons and intItems have been input. intCartons intItems

  22. 6.4 Memory Concepts • Using the variable’s data • Nondestructive when value is read from memory Figure 6.14 Memory locations after a multiplication operation. intCartons 12 intItems 10 120 intResult

  23. 6.5 Arithmetic • Operator precedence • Operators in expressions contained within a pair of parentheses are evaluated first • Exponentiation is applied next • Unary positive and negative are applied • Multiplication and floating-point division operations • Division is applied • Modulus operations are second to last • Lastly, Addition and subtraction operations

  24. 6.5 Arithmetic

  25. 6.6 Using the Debugger: Breakpoints • Enable the debugger • Enabled by default • Change Solution ConfigurationComboBox to Debugif not enabled

  26. Solution Configuration ComboBox 6.6 Using the Debugger: Breakpoints Figure 6.16 Setting Solution Configuration to Debug.

  27. 6.6 Using the Debugger: Breakpoints • Methods of inserting breakpoints • Click inside the margin indicator bar • Right click the line of code and select Insert Breakpoint • Breakpoints • You can set as many as you like • Solid maroon circle appears for each breakpoint • Can be set during design more, break mode, or run mode

  28. Margin indicator bar Breakpoints 6.6 Using the Debugger: Breakpoints Figure 6.17 Setting two breakpoints.

  29. 6.6 Using the Debugger: Breakpoints • Run the application • Click the Calculate TotalButton Figure 6.18 Inventory application running.

  30. Title bar displays [break] 6.6 Using the Debugger: Breakpoints • The IDE title bar displays the application’s mode Figure 6.19 Title bar of the IDE displaying [break].

  31. 6.6 Using the Debugger: Breakpoints • Debugging the application • Program execution suspends at the first break point • Yellow arrow indicate next statement to execute

  32. Next executable statement Yellow arrow Breakpoints 6.6 Using the Debugger: Breakpoints Figure 6.20 Program execution suspended at the first breakpoint.

  33. 6.6 Using the Debugger: Breakpoints • To resume execution, select Debug > Continue • The application continues its normal execution • Quick Info box • Displays variable’s current value

  34. Quick Info box displays variable intResult’s value 6.6 Using the Debugger: Breakpoints Figure 6.21 Displaying a variable value by placing the mouse pointer over a variable name.

  35. 6.6 Using the Debugger: Breakpoints • Use the Debug > Continue command to complete the application • No more breakpoints, program will not suspend • The entire application executes to completion Figure 6.22 Program output.

  36. Disabled breakpoint 6.6 Using the Debugger: Breakpoints Figure 6.23 Disabled breakpoint.

  37. 6.6 Using the Debugger: Breakpoints • Disabling a breakpoint • Right click the line of code with the breakpoint • Select Disable Breakpoint • A hollow maroon circle indicates disabled breakpoint • Removing a breakpoint • Right click the line of code with the breakpoint • Select Remove Breakpoint • Or click the maroon circle in the margin indicator bar

More Related