+ All Categories
Home > Documents > Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable...

Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable...

Date post: 04-Jan-2016
Category:
Upload: jade-ellis
View: 218 times
Download: 0 times
Share this document with a friend
50
Visual Basic .NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application
Transcript
Page 1: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

Visual Basic .NETComprehensive Concepts

and Techniques

Chapter 8

Debugging, Creating Executable Files, and

Distributing a Windows Application

Page 2: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

2Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Objectives

• Describe the difference between syntax, logic, and run-time errors

• Find syntax errors during design time

• Fund run-time errors and logic errors during run time

• Set breakpoints

• Execute one statement at a time by stepping

Page 3: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

3Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Objectives

• Set the next statement to execute

• Evaluate variables using DataTips

• Evaluate variables and expressions using the QuickWatch and Watch windows

• Change values of variables using debug tools

• Use the Autos, Locals, and Me windows to examine variables and objects

Page 4: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

4Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Objectives

• Use the Command window to execute commands

• Set the icon for an executable file

• Create an executable file

• Create a setup program to distribute a Windows application

Page 5: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

5Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 6: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

6Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Starting Visual Basic .NET and Opening an Existing Project• Insert the Data Disk in drive A• Start Visual Basic .NET. When the Start Page

appears, click the Open Project button• Double-click the Chapter8 folder on the Data

Disk• Double-click the Today’s Sales Check folder. If

necessary, click the Today’s Sales Check solution file

• Click the Open button

Page 7: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

7Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 8: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

8Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Visual Basic .NET Error Types

• Syntax Errors– Code violates a rule of the Visual Basic .NET

language

• Logic Errors– Code executes, but program results are

incorrect

• Run-time Errors– Program halts during run-time due to an

invalid statement or operation (divide by zero)

Page 9: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

9Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Syntax Errors

• Occur when the code violates a rule of the Visual Basic .NET language– Misspelled keywords– Misspelled variable names– Missing keywords

• Visual Basic .NET underlines syntax errors, and Intellisense™ displays a description of the error when the mouse hovers over

Page 10: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

10Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Finding and Fixing Syntax Errors Using the Task List Window• Click View on the menu bar, select Other

Windows, and click Task List• Double-click the third task in the Task List• Double-click the fourth task in the Task List• Click line 169 and enter Dim sngTotalAdvertised As Single as the new line of code. After entering the code, click a different line to move the insertion point to another line of code

• Double-click the first task in the Task List window

Page 11: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

11Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Finding and Fixing Syntax Errors Using the Task List Window• Right-click the word, Check in line 148 on the left

side of the assignment statement• Click the ListMembers command• Double-click the property, Checked, in the

Members list. Click another line in the code window

• Double-click the value, Fales, on line 148. Type False to correct the spelling mistake. Click another line in the code window

Page 12: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

12Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using Breakpoints with Stepping and DataTips• Click the Start button on the Visual Basic .NET

Standard toolbar• Click the Close button in the Today’s Sales

Check window to close the window. Click the Today’s Sales Form.vb tab in the main work area

• Scroll to the frmTodaysSalesCheck_Resize event procedure.

• Click the column at the left side of the code window, directly to the left of line 213

Page 13: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

13Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 14: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

14Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using Stepping and DataTips with Breakpoints• With a breakpoint set at line 213, click the Start

button on the Standard toolbar to enter run time. When the execution halts at line 213, click the Breakpoints tab

• Move the mouse pointer over the property, Me.Width, on line 213. Move your mouse pointer over intColumn0Width on line 213

• DataTip displays with the property or variable name, along with their current value

• Press the F8 key to step through the statements

Page 15: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

15Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Disabling a Breakpoint and Correcting a Logic Error• Right-click anywhere in line 213. When the code

window shortcut menu appears, click the Disable Breakpoint command

• Click the Stop Debugging button on the Debug toolbar. Use the code window scroll bar to scroll the code window to the right, until the end of line 213 displays. Click after the text, lstTodaysSales.Columns(2).Width. Enter - lstTodaysSales.Columns(3).Width and then press the SPACEBAR

Page 16: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

16Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 17: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

17Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 18: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

18Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Breaking on a Run-Time Error and Using a QuickWatch• Click the Start button on the Standard toolbar to

run the project• Click the Enter Today’s Sales button. Enter the

test data in table 8-4 on page VB 8.26• Click the OK button after entering the second

item, without entering a description in the Item Description text box

• Click the Total Today’s Sales button• Click the Break button in the Microsoft

Development Environment dialog box

Page 19: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

19Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Breaking on a Run-Time Error and Using a QuickWatch• Right-click the variable, intIndex, in line 174, the

last line executed before the line that causes the error, to check the value of the variable prior to the error. When the code window shortcut menu appears, click the QuickWatch command

• Click the Close button in the QuickWatch window. Repeat the previous process with the intListCount variable in line 174

• Click the Close button in the QuickWatch window

Page 20: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

20Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Adding a Watch to the Watch Window• With the application in break mode and

paused on line 175, right-click the intIndex variable on line 174. When the code window shortcut menu appears, click the Add Watch command

• Repeat the process above with the lstTodaysSales.Items(intIndex).SubItems(1).Text property on line 175, and the intListCount variable on line 174.

Page 21: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

21Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Adding a Watch to the Watch Window• Click the Stop Debugging button on the

Debug toolbar

• Click to the left of line 175 to set a breakpoint at line 175

Page 22: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

22Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Watching Variables and Using a Breakpoint in a Loop• Click the Start button on the Standard

toolbar

• Click the Enter Today’s Sales button. Enter the test data in table 8-4 on page VB 8.26 and click the OK button after entering the second item, without entering a description in the Item Description text box

• Click the Total Today’s Sales button

Page 23: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

23Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Watching Variables and Using a Breakpoint in a Loop• Press the F5 key to

resume running the project

• Press the F5 key (again) to resume running the project

• Click the Stop Debugging button on the Debug toolbar

Page 24: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

24Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Fixing a Run-Time Error in a For…Next Loop• Click the end of line

174. Type – 1 to fix the error

• Right-click line 175. When the code window shortcut menu displays, click the Disable Breakpoint command

Page 25: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

25Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using the Autos Window

• Click the Start button on the Standard toolbar• Click the Enter Today’s Sales button. Enter the

test data in table 8-4 on page VB 8.26 and click the OK button after entering the second item, without entering a description in the Item Description text box

• Click the Total Today’s Sales button to determine if the application displays the expected results in the Daily Sales Totals message box

Page 26: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

26Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using the Autos Window

• Click the breakpoint status check box in the Breakpoints window to enable the breakpoint on line 175

• Click the Today’s Sales Check application button on the Windows taskbar. When the Today’s Sales Check window displays, click the OK button in the Daily Sales Totals message box. Click the Total Today’s Sales button. When VB .NET enters break mode, press the F8 key eight times

• Click the Autos tab at the bottom of the IDE

Page 27: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

27Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Fixing a Logic Error

• Click the Stop Debugging button on the Debug toolbar

• Change the index of the SubItems item in line 185 from the value, 2, to the value, 3

• Right-click anywhere in line 175 and then click Disable Breakpoint on the code window shortcut menu

Page 28: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

28Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using the Locals Window to Evaluate Variables• Click the Start button on the Standard toolbar• Click the Enter Today’s Sales button. Enter the

test data in table 8-4 on page VB 8.26 and click the OK button after entering the second item, without entering a description in the Item Description text box

• Click the Total Today’s Sales button to determine if the application displays the expected results in the Daily Sales Totals message box

Page 29: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

29Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using the Locals Window to Evaluate Variables• Click the breakpoint status check box in the

Breakpoints window to enable the breakpoint on line 175

• Click the Today’s Sales Check application button in the Windows taskbar. When the Today’s Sales Check window appears, click the OK button in the Daily Sales Totals message box. Click the Total Today’s Sales button, and click the Locals tab at the bottom of the IDE

• Scroll the variable list in the Locals window until the intListCount variable displays. Press F8 nine times

Page 30: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

30Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Fixing an Assignment Logic Error

• Click the Stop Debugging button on the Debug toolbar

• Select the variable, sngTotalAdvertised, on the right side of the assignment statement in line 186. Type sngItemSales to replace the variable, sngTotalAdvertised

• Right-click anywhere in line 175 and then click Disable Breakpoint on the code window shortcut menu

• Test and save the project, using the test data on page VB 8.26 in table 8-4

Page 31: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

31Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using the Command Window –Entering Commands• Right-click the filled red circle icon to the left of

line 175 and then click Disable Breakpoint. Click the empty red circle icon to the left of line 213 to enable the breakpoint at line 213, and press F5 to enter run time

• Click the Debug menu and point to the Windows command. Click the Immediate command on the Windows submenu

• At the insertion point in the Command window, type ?intColumn0Width and then press the ENTER key

Page 32: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

32Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Using the Command Window –Entering Commands• Press the F8 key to execute line 213. Type ?intColumn0Width in the Command window and then press the ENTER key

• Type >cmd in the Command window and then press the ENTER key

• Enter Debug.sto in the Command window, as shown in figure 8-54 on page VB 8.53

• Click the Debug.StopDebugging command in the Intellisense™ list and then press the ENTER key

Page 33: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

33Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating an Executable File• Click the Today’s Sales Check project in the

Solution Explorer window. Click the Property Pages icon on the Properties toolbar in the Properties window. When the Today’s Sales Check Property Pages appear, click the Build item in the Command Properties folder

• Click the Application icon ellipsis button. Select the CHECKMRK.ICO file located in the same folder as the project file, and click Open

• Click the Configuration Properties folder• Click the OK button

Page 34: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

34Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating an Executable File

• Click the Solution Configurations box arrow on the Standard toolbar. Select Release in the Solution Configurations list. Click Build on the menu bar

• Click the Build Solution command on the Build menu

• Open Windows Explorer and navigate to the folder, A:\Chapter8\Today’s Sales Check\Today’s Sales Check\bin

• Click the Windows Explorer Close button. In the VB .NET IDE, click File on the menu bar and then click Close Solution

Page 35: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

35Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 36: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

36Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating a Setup Project and Adding an Executable File• With the Today’s Sales Check solution

closed, click Project on the New submenu of the File menu. When the New Project dialog box appears, select Setup and Deployment Projects in the Project types box. Enter Today’s Sales Check Setup in the Name text box and then click the Setup Project icon in the Templates box

Page 37: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

37Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating a Setup Project and Adding an Executable File• Click the OK button. After VB .NET creates the

new project, right-click the Application Folder folder in the File System window. When the shortcut menu appears, point to the Add command

• Click the File command on the Add submenu. When the Add Files dialog box appears, navigate to A:\Chapter8\Today’s Sales Check\Today’s Sales Check\bin and select the executable file (with the checkmark icon)

• Click the Open button

Page 38: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

38Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating a Startup Menu Shortcut

• Right-click the User’s Programs Menu folder in the Folders window. Click the Add command on the User’s Programs Menu shortcut menu

• Click the Folder command. When the new folder displays in the Folders window, type Todays Sales Check as the folder name and then press the ENTER key

• Right-click anywhere in the Files window

Page 39: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

39Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating a Startup Menu Shortcut

• Click the Create New Shortcut command. When the Select Item in Project dialog box appears, double-click the Application Folder folder

• Click the OK button. In the Files window, type Todays Sales Check as the name for the shortcut

• Click the Icon property value in the Properties window. Click the Icon property box arrow and then click Browse in the Icon property values list

Page 40: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

40Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Creating a Startup Menu Shortcut

• When the icon dialog box appears, click the Browse button. When the Select Item in Project dialog box appears, double-click the Application Folder folder

• Select Executable Files (*.exe) in the Files of type list. Click the Todays Sales Check.exe file and then click the OK button

• Click the OK button in the Icon dialog box

Page 41: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

41Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 42: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

42Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Setting Options and Building a Setup Program• Click the Todays Sales Check Setup

project in the Solution Explorer window. Then, click the Property Pages button in the Properties window

• When the Property Pages window appears, click the Bootstrapper box arrow

• Click None in the Bootstrapper list. Click the OK button

Page 43: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

43Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Setting Options and Building a Setup Program• When the Property Pages window closes,

click the Build Solution command on the Build menu

• When the Output window indicates that the build is complete, close Visual Basic .NET

Page 44: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

44Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Testing a Setup Program

• Open Windows Explorer and navigate to the folder, A:\Chapter8\Todays Sales Check Setup\Todays Sales Check Setup\Debug

• Double-click the Todays Sales Check Setup Windows Installer Package icon

• Click the Next button in the three subsequent dialog boxes

Page 45: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

45Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Testing a Setup Program

• When the Todays Sales Check Setup dialog box displays the Installation Complete message, click the Close button

• Click the Start button on the taskbar and then point to All Programs on the Start menu. When the All Programs submenu appears, point to the Todays Sales Check command

Page 46: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

46Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Page 47: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

47Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Summary

• Describe the difference between syntax, logic, and run-time errors

• Find syntax errors during design time

• Fund run-time errors and logic errors during run time

• Set breakpoints

• Execute one statement at a time by stepping

Page 48: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

48Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Summary

• Set the next statement to execute

• Evaluate variables using DataTips

• Evaluate variables and expressions using the QuickWatch and Watch windows

• Change values of variables using debug tools

• Use the Autos, Locals, and Me windows to examine variables and objects

Page 49: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

49Chapter 8: Debugging, Creating Executable Files, and Distributing a Windows Application

Summary

• Use the Command window to execute commands

• Set the icon for an executable file

• Create an executable file

• Create a setup program to distribute a Windows application

Page 50: Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.

Visual Basic .NETComprehensive Concepts

and Techniques

Chapter 8 Complete


Recommended