370 likes | 452 Views
Tutorial 6 – Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic.
E N D
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
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.
6.1 Test-Driving the Enhanced Inventory Application • Running the application Figure 6.1 Inventory application GUI displayed when the application is executed.
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.
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.
6.2 Variables • Adding code to the application • Declaring a variable • Keyword Dim • Data types • Built-in data type • Primitive data type
Click event handler Variable declarations 6.2 Variables Figure 6.4 Declaring variables in event handler btnCalculate_Click.
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
Assigning user input to variables 6.2 Variables Figure 6.5 Retrieving numerical input from TextBoxes.
6.2 Variables • Perform the multiplication • Displaying the result • Set the multiplication result to the Label’s Text property
Calculating and displaying the result 6.2 Variables Figure 6.7 Multiplication, using variables in btnCalculate_Click.
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.
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
TextChanged event handler 6.3 Handling the TextChanged Event Figure 6.9 TextChanged event handler for Cartons per shipment:TextBox.
6.3 Handling the TextChanged Event Figure 6.10 TextChanged event handler for Items per carton:TextBox.
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)
Setting a TextBox’s Text property to an empty string Inventory.vb(2 of 2)
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
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
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
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
6.6 Using the Debugger: Breakpoints • Enable the debugger • Enabled by default • Change Solution ConfigurationComboBox to Debugif not enabled
Solution Configuration ComboBox 6.6 Using the Debugger: Breakpoints Figure 6.16 Setting Solution Configuration to Debug.
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
Margin indicator bar Breakpoints 6.6 Using the Debugger: Breakpoints Figure 6.17 Setting two breakpoints.
6.6 Using the Debugger: Breakpoints • Run the application • Click the Calculate TotalButton Figure 6.18 Inventory application running.
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].
6.6 Using the Debugger: Breakpoints • Debugging the application • Program execution suspends at the first break point • Yellow arrow indicate next statement to execute
Next executable statement Yellow arrow Breakpoints 6.6 Using the Debugger: Breakpoints Figure 6.20 Program execution suspended at the first breakpoint.
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
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.
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.
Disabled breakpoint 6.6 Using the Debugger: Breakpoints Figure 6.23 Disabled breakpoint.
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