Tutorial 1, Lesson A



Programming with Microsoft Visual Basic 6.0 – Enhanced Edition

Answers to Questions and Exercises

Table of Contents

Tutorial 1, Lesson A Page 1

Tutorial 1, Lesson B Page 4

Tutorial 1, Lesson C Page 7

Tutorial 1, Debugging Page 17

Tutorial 2, Lesson A Page 20

Tutorial 2, Lesson B Page 24

Tutorial 2, Lesson C Page 26

Tutorial 2, Debugging Page 74

Tutorial 3, Lesson A Page 75

Tutorial 3, Lesson B Page 76

Tutorial 3, Lesson C Page 82

Tutorial 3, Debugging Page 93

Tutorial 4, Lesson A Page 95

Tutorial 4, Lesson B Page 106

Tutorial 4, Lesson C Page 109

Tutorial 4, Debugging Page 113

Tutorial 5, Lesson A Page 116

Tutorial 5, Lesson B Page 122

Tutorial 5, Lesson C Page 126

Tutorial 5, Debugging Page 134

Tutorial 6, Lesson A Page 135

Tutorial 6, Lesson B Page 156

Tutorial 6, Lesson C Page 161

Tutorial 6, Debugging Page 174

Tutorial 7, Lesson A Page 175

Tutorial 7, Lesson B Page 176

Tutorial 7, Lesson C Page 179

Tutorial 7, Debugging Page 194

Tutorial 8, Lesson A Page 196

Tutorial 8, Lesson B Page 203

Tutorial 8, Lesson C Page 213

Tutorial 8, Debugging Page 227

Tutorial 9, Lesson A Page 230

Tutorial 9, Lesson B Page 234

Tutorial 9, Lesson C Page 244

Tutorial 9, Debugging Page 251

Tutorial 10, Lesson A Page 252

Tutorial 10, Lesson B Page 274

Tutorial 10, Lesson C Page 283

Tutorial 10, Debugging Page 292

Tutorial 11, Lesson A Page 293

Tutorial 11, Lesson B Page 294

Tutorial 12, Lesson A Page 297

Tutorial 12, Lesson B Page 299

Tutorial 1, Lesson A

Questions

1. b form

2. b toolbox

3. d Properties

4. e .frm

5. e .vbp

6. a BackColor

7. a Caption

8. c Caption

9. d Name

10. d Name

11. H Form window I Properties List

D Main window A Properties window

C Menu bar J Settings box

E Object box B Toolbar

G Project window F Toolbox window

12. A form’s Caption property controls the text that appears in the form’s title bar and on the application’s button on the Windows 95 taskbar when the application is running. The Name property is used by the programmer to refer to an object in code. The user sees the Caption property; the programmer uses the Name property.

13. To open a new project, click File on the menu bar, then click New Project; or press Ctrl+N. When the New Project dialog box appears, click Standard EXE, and then click the OK button.

14. To open an existing project, click the Open Project button on the Standard toolbar. You also can press Ctrl+O; or click File, then click Open Project. Select the appropriate drive and folder. Click the project name in the list of file names, and then click the Open button.

15. To display the Project window, click the Project Explorer button on the Standard toolbar. You also can click View, then click Project Explorer; or press Ctrl+R. To display the Properties window, click the Properties Window button on the Standard toolbar. You also can press the F4 key; or click View, and then click Properties Window; or right-click an object and then click Properties.

Exercises

1. Text shaded gray indicates specific application requirements to note. The student should submit a printout of the Form As Text.

|VERSION 5.00 |BeginProperty Font |

|Begin VB.Form frmCharity |Name = "MS Sans Serif" |

|BackColor = &H00800000& |Size = 18 |

|Caption = "Charities Unlimited" |Charset = 0 |

|ClientHeight = 4140 |Weight = 700 |

|ClientLeft = 1035 |Underline = 0 'False |

|ClientTop = 1515 |Italic = -1 'True |

|ClientWidth = 8220 |Strikethrough = 0 'False |

|LinkTopic = "Form1" |EndProperty |

|PaletteMode = 1 'UseZOrder |Height = 1935 |

|ScaleHeight = 4140 |Left = 120 |

|ScaleWidth = 8220 |TabIndex = 0 |

|Begin VB.Label Label1 |Top = 720 |

|BackColor = &H00FFFF80& |Width = 7935 |

|Caption = "Please help Charities Unlimited help |End |

|others." |End |

2. Text shaded gray indicates specific application requirements to note. The student should submit a printout of the Form As Text.

|VERSION 5.00 |Begin VB.Image Image1 |

|Begin VB.Form frmPhotos |Height = 3495 |

|BackColor = &H000000FF& |Left = 480 |

|Caption = "Photos Inc." |Picture = "La2.frx":0000 |

|ClientHeight = 4140 |Stretch = -1 'True |

|ClientLeft = 1200 |Top = 360 |

|ClientTop = 1515 |Width = 5775 |

|ClientWidth = 6690 |End |

|LinkTopic = "Form1" |End |

|PaletteMode = 1 'UseZOrder | |

|ScaleHeight = 4140 | |

|ScaleWidth = 6690 | |

3. A Caption B ForeColor

B Enabled C Icon

B FillColor A Left

B FillStyle A Name

C Font C Picture

4. (Discovery)

a. Debug toolbar buttons: Start, Break, End, Toggle Breakpoint, Step Into, Step Over, Step Out, Locals Window, Immediate Window, WatchWindow, Quick Watch, Call Stack

b. Edit toolbar button: List Properties/Methods, List Constants, Quick Info, Parameter Info, Complete Word, Indent, Outdent, Toggle Breakpoint, Comment Block, Uncomment Block, Toggle Bookmark, Next Bookmark, Previous Bookmark, Clear All Bookmarks

c. Form Editor toolbar buttons: Bring To Front, Send To Back, Align (Lefts, Centers, Rights, Tops, Middles, Bottoms, to Grid), Center (Horizontally, Vertically), Make Same Size (Width, Height, Both), Lock Controls Toggle

d. Customize tabs: The Toolbars tab allows you to create, rename, delete, and reset your toolbars. The Commands tab contains commands you can drag to your menus and toolbars. The Options tab allows you to change the size of your toolbar buttons, to show ScreenTips (ToolTips) and shortcut keys, and to add animation to your menus.

5. (Discovery)

BorderStyle property: Returns/sets the border style for an object.

Icon property: Returns the icon displayed when a form is minimized at run time.

MaxButton property: Determines whether a form has a Maximize button.

WindowState property: Returns/sets the visual state of a form window at run time. The three values of the WindowState property are 0-Normal, 1-Minimized, and 2-Maximized.

Tutorial 1, Lesson B

Questions

1. a F1

2. d Label

3. d twips

4. c points

5. e AutoSize

6. a Form

7. a) To select multiple controls, click the first control you want to select in the form and then press and hold down the Control (Ctrl) key as you click the other controls you want to select. b) To deselect one of the selected controls, press and hold down the Ctrl key as you click the control. c) To deselect all of the selected controls, click the form or any unselected control in the form.

8. To size a control, first select the control, and then position the mouse pointer on one of the sizing handles and drag until the control is the desired size. To move a control, position the mouse pointer on the control, being careful not to position the pointer on any of the sizing handles, and then drag the control to its new location. To delete a control, select the control, and then press the Delete key. In order to delete a control, the Form window must be the active window.

9. To save an existing form and an existing project under a different name, click File on the menu bar, then click Save As to save the form. Enter the new name for the form in the File name text box, select the appropriate drive and folder in the Save in list box, and then click the Save button. Click File on the menu bar, and then click Save Project As to save the project. Enter the new name for the project in the File name text box, select the appropriate drive and folder in the Save in list box, and then click the Save button.

Exercises

1. lb1Done project—Text shaded gray indicates specific application requirements to note. The student should submit a printout of the Form As Text.

|VERSION 5.00 |Height = 300 |

|Begin VB.Form frmIMA |Left = 795 |

|BackColor = &H00FFFFFF& |TabIndex = 0 |

|Caption = "IMA" |Top = 1000 |

|ClientHeight = 3915 |Width = 4365 |

|ClientLeft = 1155 |End |

|ClientTop = 1545 |End |

|ClientWidth = 6585 | |

|LinkTopic = "Form1" | |

|ScaleHeight = 3915 | |

|ScaleWidth = 6585 | |

|Begin VB.Label Label1 | |

|AutoSize = -1 'True | |

|Caption = "International Mechanics Association" | |

|BeginProperty Font | |

|Name = "MS Sans Serif" | |

|Size = 12 | |

|Charset = 0 | |

|Weight = 700 | |

|Underline = 0 'False | |

|Italic = 0 'False | |

|Strikethrough = 0 'False | |

|EndProperty | |

2. lb2Done project—Text shaded gray indicates specific application requirements to note. The student should submit a printout of the Form Image and the Form As Text.

[pic]

|VERSION 5.00 |BeginProperty Font |

|Begin VB.Form frmJefferson |Name = "Arial" |

|BackColor = &H00FFFFC0& |Size = 24 |

|Caption = "Jefferson Cleaning Inc." |Charset = 0 |

|ClientHeight = 3915 |Weight = 400 |

|ClientLeft = 1440 |Underline = 0 'False |

|ClientTop = 1515 |Italic = 0 'False |

|ClientWidth = 6585 |Strikethrough = 0 'False |

|LinkTopic = "Form1" |EndProperty |

|ScaleHeight = 3915 |ForeColor = &H000000FF& |

|ScaleWidth = 6585 |Height = 540 |

|Begin VB.Label Label2 |Left = 2055 |

|AutoSize = -1 'True |TabIndex = 0 |

|BackColor = &H00FFFFFF& |Top = 1200 |

|Caption = "Jefferson Cleaning Inc." |Width = 2670 |

|BeginProperty Font |End |

|Name = "Arial" |End |

|Size = 24 | |

|Charset = 0 | |

|Weight = 400 | |

|Underline = 0 'False | |

|Italic = 0 'False | |

|Strikethrough = 0 'False | |

|EndProperty | |

|ForeColor = &H000000FF& | |

|Height = 540 | |

|Left = 960 | |

|TabIndex = 1 | |

|Top = 1920 | |

|Width = 4890 | |

|End | |

|Begin VB.Label Label1 | |

|AutoSize = -1 'True | |

|BackColor = &H00FFFFFF& | |

|Caption = "Welcome To" | |

3. lb3Done project—In this exercise, the student is allowed to choose the form’s name and color, as well as the color, font type, style, and size for the two label controls. The shaded text indicates where these changes would appear. The student should submit a printout of the Form Image and the Form As Text.

[pic]

|VERSION 5.00 |Begin VB.Label Label1 |

|Begin VB.Form frmYorktown |AutoSize = -1 'True |

|BackColor = &H0080FFFF& |BackColor = &H0080FFFF& |

|Caption = "Yorktown Shopping Center" |Caption = "The Yorktown Mall of Kentucky" |

|ClientHeight = 3915 |BeginProperty Font |

|ClientLeft = 1155 |Name = "Arial" |

|ClientTop = 1545 |Size = 12 |

|ClientWidth = 6585 |Charset = 0 |

|LinkTopic = "Form1" |Weight = 700 |

|ScaleHeight = 3915 |Underline = 0 'False |

|ScaleWidth = 6585 |Italic = 0 'False |

|Begin VB.Label Label2 |Strikethrough = 0 'False |

|AutoSize = -1 'True |EndProperty |

|BackColor = &H0080FFFF& |Height = 285 |

|Caption = "Your one-stop shopping center" |Left = 1530 |

|BeginProperty Font |TabIndex = 0 |

|Name = "Arial" |Top = 1440 |

|Size = 12 |Width = 3540 |

|Charset = 0 |End |

|Weight = 700 |End |

|Underline = 0 'False | |

|Italic = -1 'True | |

|Strikethrough = 0 'False | |

|EndProperty | |

|Height = 270 | |

|Left = 1560 | |

|TabIndex = 1 | |

|Top = 2040 | |

|Width = 3480 | |

|End | |

4. (Discovery) The student should submit handwritten answers to steps f and g.

Step f: To display Help screens that contain the phrase msdn library, enclose the phrase—in this case, “msdn library”—in quotation marks.

Step g: To create a list of favorite topics, click the Contents, Index, or Search tab and open a topic you want to make a favorite topic. Click the Favorites tab. The topic that you opened will be displayed in the Current topic area. Click Add to add the topic to your favorites list. (Note: If you want to rename the displayed topic, type the new name in the Current topic area and then click Add.) To return to a favorite topic, highlight the topic and then click Display. You also can double-click the topic name. To remove a favorite topic, select the topic and then click Remove.

5. (Discovery) In this exercise, the student learns about the Align and Make Same Size commands on Visual Basic’s Format menu. The student is not instructed to submit anything for this exercise.

Tutorial 1, Lesson C

Questions

1. e Picture

2. b End

3. b Form As Text

4. a Code

5. b events

6. c event procedures

7. e syntax

8. e keyword

9. a BorderStyle

10. e Selection

11. a Current Module

12. c Form As Text

13. To place an existing control inside a frame, cut the existing control from the form, then select the frame, and then paste the control inside the frame.

14. To draw a control on either a form or a frame control, click the appropriate tool in the toolbox. Position the crosshair on the form or inside the frame, and then drag until the control is the desired size.

15. When the Procedure View button is selected, each procedure appears in its own Code window. When the Full Module View button is selected, the application’s code appears as a single listing.

16. You open an object’s Code window by double-clicking the object.

17. An event procedure is a block of code that tells an object how to respond to an event (such as clicking, double-clicking, and so on).

18. The Code window’s Object box allows you to choose either the form or one of the controls on the form. The Code window’s Procedure box lists the event procedures to which the selected object is capable of responding.

19. Syntax is the rules of a programming language.

20. The File menu’s Make command saves a project’s compiled code in a separate file. You would use this command to create a file that can be run outside of Visual Basic, on any computer system that is running Microsoft Windows and has the msvbvm60.dll file in its Windows\System folder.

Exercises

1. lc1Done project—Text shaded gray indicates specific application requirements to note. The student should submit a printout of the Form Image and the Form As Text, as well as an executable file. (The student cannot use the Working Model to make an executable file.)

[pic]

|VERSION 5.00 |Begin VB.Image imgLogo |

|Begin VB.Form frmAnimal |Height = 2820 |

|BackColor = &H00FFFFFF& |Left = 840 |

|Caption = "Peoria Animal Shelter" |Picture = "lc1Done.frx":0000 |

|ClientHeight = 5130 |Stretch = -1 'True |

|ClientLeft = 1155 |Top = 1080 |

|ClientTop = 1545 |Width = 4755 |

|ClientWidth = 6585 |End |

|LinkTopic = "Form1" |Begin VB.Label lblTitle |

|ScaleHeight = 5130 |AutoSize = -1 'True |

|ScaleWidth = 6585 |Caption = "Welcome to the Peoria Animal Shelter" |

|Begin VB.Frame Frame1 |BeginProperty Font |

|Caption = "Click the logo" |Name = "MS Sans Serif" |

|BeginProperty Font |Size = 12 |

|Name = "MS Sans Serif" |Charset = 0 |

|Size = 12 |Weight = 700 |

|Charset = 0 |Underline = 0 'False |

|Weight = 400 |Italic = 0 'False |

|Underline = 0 'False |Strikethrough = 0 'False |

|Italic = 0 'False |EndProperty |

|Strikethrough = 0 'False |Height = 300 |

|EndProperty |Left = 840 |

|Height = 4935 |TabIndex = 1 |

|Left = 120 |Top = 600 |

|TabIndex = 0 |Visible = 0 'False |

|Top = 120 |Width = 4560 |

|Width = 6375 |End |

|Begin mandButton cmdExit |End |

|Caption = "Exit" |End |

|BeginProperty Font | |

|Name = "MS Sans Serif" |Code: |

|Size = 12 |Private Sub cmdExit_Click() |

|Charset = 0 |End |

|Weight = 400 |End Sub |

|Underline = 0 'False | |

|Italic = 0 'False |Private Sub imgLogo_Click() |

|Strikethrough = 0 'False |lblTitle.Visible = True |

|EndProperty |End Sub |

|Height = 495 | |

|Left = 5280 | |

|TabIndex = 2 | |

|Top = 4320 | |

|Width = 855 | |

|End | |

2. (Discovery) In this exercise, the student designs his or her own user interface. The interface should include an Exit button that will end the application. It also should include one or more label controls, image controls, and frame controls, as well as the Scroller control (assuming the student is not using the Working Model). The image control(s) can contain either the Interlocking picture used in the tutorial, or it can contain one of Visual Basic’s icons. Object that will either be coded or used in code should be named. The color and font types, styles, and sizes will vary. The student should submit an executable file and printouts of the form, properties, and code. (The student will not be able to use the Working Model to make an executable file.)

3. (Discovery) lc3Done project—Text shaded gray indicates specific application requirements to note. (The control names may differ.) The student should submit a printout of the Form As Text and code.

|VERSION 5.00 |Begin VB.Image imgOnOff |

|Begin VB.Form frmOnOff |Height = 1410 |

|Caption = "On and Off" |Left = 720 |

|ClientHeight = 2940 |Picture = "lc3Done.frx":0000 |

|ClientLeft = 2415 |Stretch = -1 'True |

|ClientTop = 1560 |Top = 240 |

|ClientWidth = 4440 |Width = 2955 |

|LinkTopic = "Form1" |End |

|ScaleHeight = 2940 |End |

|ScaleWidth = 4440 | |

|Begin mandButton cmdExit |Code: |

|Caption = "Exit" |Private Sub cmdExit_Click() |

|Height = 495 |End |

|Left = 2880 |End Sub |

|TabIndex = 2 | |

|Top = 2040 |Private Sub cmdOff_Click() |

|Width = 1215 |imgOnOff.Visible = False |

|End |End Sub |

|Begin mandButton cmdOff | |

|Caption = "Off" |Private Sub cmdOn_Click() |

|Height = 495 |imgOnOff.Visible = True |

|Left = 1560 |End Sub |

|TabIndex = 1 | |

|Top = 2040 | |

|Width = 1215 | |

|End | |

|Begin mandButton cmdOn | |

|Caption = "On" | |

|Height = 495 | |

|Left = 240 | |

|TabIndex = 0 | |

|Top = 2040 | |

|Width = 1215 | |

|End | |

4. (Discovery) In this exercise, the student uses Visual Basic’s Package and Deployment Wizard to create setup disks for the lc1Done project. To use the Package and Deployment Wizard, the student must have saved and compiled the lc1Done project. The student will not be able to create the compiled (executable) project with the Working Model. The student is instructed to submit the setup disks.

5. (Discovery) In this exercise, the student learns how to set the attributes for the lcCopy.exe file created in Lesson C. The student will not be able to complete this exercise with the Working Model. The student is not instructed to submit anything for this exercise.

6. (Discovery) In this exercise, the student learns how to step through an application’s code. The student is not instructed to submit anything for this exercise.

7. (Discovery) In this exercise, the student learns how to use the line continuation character. The student is not instructed to submit anything for this exercise.

8. (Discovery) lc8Splas and lc8About projects. In this exercise, the student uses Visual Basic’s Application Wizard to create a splash screen and an About box. The student should submit the files for this exercise.

9. (Discovery) In this exercise, the student learns how to create a ToolTip (Ends the application) for the Exit button in the lcCopy project created in Lesson C. The student is not instructed to submit anything for this exercise.

10. (Discovery) In this exercise, the student learns how to display a picture (graphic) in the lcCopy project’s Exit button. The student uses the command button’s Style and DownPicture properties. The student is not instructed to submit anything for this exercise.

Tutorial 1 – Debugging

Technique

The simplest technique a programmer uses for debugging an application is to print the application’s properties (Form As Text) and code. In the printout of the properties, the programmer looks for a property that is set incorrectly. In the code printout, the programmer looks for an instruction that is either in the wrong object’s Code window or in the wrong event procedure.

Exercises

1. Text shaded gray indicates specific application requirements to note. For the lblTitle control, the student may change either the AutoSize property or the Width property. The student should submit the Form As Text with the corrections circled.

|VERSION 5.00 |Begin VB.Label LblTitle |

|Begin VB.Form frmGlamour |Appearance = 0 'Flat |

|Appearance = 0 'Flat |AutoSize = -1 'True |

|BackColor = &H00C0C0C0& |BackColor = &H80000005& |

|Caption = "Glamour-Us" |BackStyle = 0 'Transparent |

|ClientHeight = 4320 |Caption = "Glamour-Us Beauty Salon" |

|ClientLeft = 1275 |BeginProperty Font |

|ClientTop = 1455 |Name = "MS Sans Serif" |

|ClientWidth = 7485 |Size = 24 |

|BeginProperty Font |Charset = 0 |

|Name = "MS Sans Serif" |Weight = 700 |

|Size = 8.25 |Underline = 0 'False |

|Charset = 0 |Italic = 0 'False |

|Weight = 700 |Strikethrough = 0 'False |

|Underline = 0 'False |EndProperty |

|Italic = 0 'False |ForeColor = &H80000008& |

|Strikethrough = 0 'False |Height = 555 |

|EndProperty |Left = 720 |

|ForeColor = &H80000008& |TabIndex = 0 |

|LinkTopic = "Form1" |Top = 1200 |

|MaxButton = 0 'False |Width = 5925 |

|PaletteMode = 1 'UseZOrder |End |

|ScaleHeight = 4320 |End |

|ScaleWidth = 7485 | |

2. In this exercise, the student learns how to remove excess code from an application. The student should submit two printouts of the code.

|Code from step h: |Code from step k: |

|Private Sub Command1_Click() |Private Sub cmdExit_Click() |

|End |End |

|End Sub |End Sub |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

3. Text shaded gray indicates specific application requirements to note. The student should submit a printout of the code with the correction circled.

|Private Sub cmdDisplay_Click() |Private Sub cmdExit_Click() |

|lblMessage.Caption = "OK" |End |

|End Sub |End Sub |

4. Text shaded gray indicates specific application requirements to note. The student should submit a printout of the code and Form As Text from step a, and a printout of the code and Form As Text from step f with the corrections circled.

|Step a |Begin VB.Label lblNote |

|VERSION 5.00 |Appearance = 0 'Flat |

|Begin VB.Form frmDebug4 |AutoSize = -1 'True |

|Appearance = 0 'Flat |BackColor = &H00C0C0C0& |

|BackColor = &H00C0C0C0& |BackStyle = 0 'Transparent |

|BorderStyle = 1 'Fixed Single |Caption = "The command button should end the |

|Caption = "Debugging Exercise 4" |application:" |

|ClientHeight = 2160 |BeginProperty Font |

|ClientLeft = 1845 |Name = "MS Sans Serif" |

|ClientTop = 2175 |Size = 8.25 |

|ClientWidth = 5355 |Charset = 0 |

|BeginProperty Font |Weight = 400 |

|Name = "MS Sans Serif" |Underline = 0 'False |

|Size = 8.25 |Italic = 0 'False |

|Charset = 0 |Strikethrough = 0 'False |

|Weight = 700 |EndProperty |

|Underline = 0 'False |ForeColor = &H80000008& |

|Italic = 0 'False |Height = 195 |

|Strikethrough = 0 'False |Left = 240 |

|EndProperty |TabIndex = 0 |

|ForeColor = &H80000008& |Top = 1080 |

|LinkTopic = "Form1" |Width = 3465 |

|MaxButton = 0 'False |End |

|PaletteMode = 1 'UseZOrder |End |

|ScaleHeight = 2160 | |

|ScaleWidth = 5355 | |

|Begin mandButton cmdExit |Code: |

|Appearance = 0 'Flat |Private Sub cmdExit_DragDrop(Source As Control, X As Single,|

|BackColor = &H00C0C0C0& |Y As Single) |

|Caption = "Command1" |End |

|BeginProperty Font | |

|Name = "MS Sans Serif" |End Sub |

|Size = 8.25 | |

|Charset = 0 | |

|Weight = 400 | |

|Underline = 0 'False | |

|Italic = 0 'False | |

|Strikethrough = 0 'False | |

|EndProperty | |

|Height = 495 | |

|Left = 3840 | |

|TabIndex = 1 | |

|Top = 960 | |

|Width = 1215 | |

|End | |

|Step f |Begin VB.Label lblNote |

|VERSION 5.00 |Appearance = 0 'Flat |

|Begin VB.Form frmDebug4 |AutoSize = -1 'True |

|Appearance = 0 'Flat |BackColor = &H00C0C0C0& |

|BackColor = &H00C0C0C0& |BackStyle = 0 'Transparent |

|BorderStyle = 1 'Fixed Single |Caption = "The command button should end the |

|Caption = "Debugging Exercise 4" |application:" |

|ClientHeight = 2160 |BeginProperty Font |

|ClientLeft = 1845 |Name = "MS Sans Serif" |

|ClientTop = 2175 |Size = 8.25 |

|ClientWidth = 5355 |Charset = 0 |

|BeginProperty Font |Weight = 400 |

|Name = "MS Sans Serif" |Underline = 0 'False |

|Size = 8.25 |Italic = 0 'False |

|Charset = 0 |Strikethrough = 0 'False |

|Weight = 700 |EndProperty |

|Underline = 0 'False |ForeColor = &H80000008& |

|Italic = 0 'False |Height = 195 |

|Strikethrough = 0 'False |Left = 240 |

|EndProperty |TabIndex = 0 |

|ForeColor = &H80000008& |Top = 1080 |

|LinkTopic = "Form1" |Width = 3465 |

|MaxButton = 0 'False |End |

|PaletteMode = 1 'UseZOrder |End |

|ScaleHeight = 2160 | |

|ScaleWidth = 5355 |Code: |

|Begin mandButton cmdExit |Private Sub cmdExit_Click() |

|Appearance = 0 'Flat |End |

|BackColor = &H00C0C0C0& |End Sub |

|Caption = "Exit" | |

|BeginProperty Font | |

|Name = "MS Sans Serif" | |

|Size = 8.25 | |

|Charset = 0 | |

|Weight = 400 | |

|Underline = 0 'False | |

|Italic = 0 'False | |

|Strikethrough = 0 'False | |

|EndProperty | |

|Height = 495 | |

|Left = 3840 | |

|TabIndex = 1 | |

|Top = 960 | |

|Width = 1215 | |

|End | |

Tutorial 2, Lesson A

Questions

1. c label

2. e text box

3. a command button

4. e TOE

5. a either horizontally or vertically

6. d upper-left corner

7. e either a (a frame) or d (white space)

8. e either a (centered along the bottom of the screen) or c (stacked in either the upper-right or lower-right

corner of the screen

9. d six

10. a first

11. d A command button’s caption should end with a colon (:).

12. b sentence capitalization

13. c Labels for controls (other than command buttons) shoud be entered using book title capitalization.

14. b sentence capitalization

15. a book title capitalization

16. 2 Identify the objects to which you will assign those tasks.

4 Draw a sketch of the user interface.

1 Identify the tasks the application needs to perform.

3 Identify the events required to trigger an object into performing its assigned tasks.

17. 4 Test and debug the application.

2 Build the user interface.

3 Code the application.

5 Assemble the documentation.

1 Plan the application.

Exercises

1. The student is instructed to submit a TOE chart ordered by task and a TOE chart ordered by object. The student also is instructed to submit two sketches of the user interface—one using a vertical arrangement and the other using a horizontal arrangement.

|Task |Object |Event |

|Get the following from the user: | | |

|name |txtName |None |

|territory |txtTerritory |None |

|sales |txtSales |None |

|Calculate the commission |cmdCalc |Click |

|Display the following: | | |

|name |txtName |None |

|territory |txtTerritory |None |

|sales |txtSales |None |

|commission |cmdCalc, lblComm |Click, None |

|Print the interface |cmdPrint |Click |

|End the application |cmdExit |Click |

|Clear the screen |cmdClear |Click |

|Task |Object |Event |

|Calculate the commission |cmdCalc |Click |

|Display the commission in the lblComm | | |

|control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the commission (from cmdCalc) |lblComm |None |

|Get and display the name, territory, and |txtName, txtTerritory, txtSales |None |

|sales | | |

Sketch of a horizontal arrangement: Sketch of a vertical arrangement:

[pic] [pic]

2. The student is instructed to submit a TOE chart ordered by task and a TOE chart ordered by object. The student is also instructed to submit two sketches of the user interface—one using a vertical arrangement and the other using a horizontal arrangement.

|Task |Object |Event |

|Get the following from the user: | | |

|current year’s sales for each region |txtNsales, txtSsales, txtEsales, txtWsales |None |

|projected increase % for each region |txtNinc, txtSinc, txtEinc, txtWinc |None |

|Calculate the projected sales for each region |cmdCalc |Click |

|Display the following: | | |

|current year’s sales for each region |txtNsales, txtSsales, txtEsales, txtWsales |None |

|projected increase % for each region |txtNinc, txtSinc, txtEinc, txtWinc |None |

|projected sales for each region |cmdCalc, lblNsales, lblSsales, lblEsales, lblWsales|Click, None, None,|

| | |None, None |

|Print the interface |cmdPrint |Click |

|End the application |cmdExit |Click |

|Clear the screen |cmdClear |Click |

|Task |Object |Event |

|Calculate the projected sales for each |cmdCalc |Click |

|region | | |

|Display the projected sales in the | | |

|lblNsales, lblSsales, lblEsales, and | | |

|lblWsales controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the projected sales (from cmdCalc) |lblNsales, lblSsales, lblEsales, |None |

| |lblWsales | |

|Get and display the projected increase % for|txtNinc, txtSinc, txtEinc, txtWinc |None |

|each region | | |

|Get and display the current year’s sales for|txtNsales, txtSsales, txtEsales, |None |

|each region |txtWsales | |

Sketch of a horizontal arrangement: Sketch of a vertical arrangement:

[pic] [pic]

1. la3Done project – Students’ answers may vary based on vertical/horizontal orientation, location of command buttons, and use of margins or frames.

[pic]

Tutorial 2, Lesson B

Questions

1. c TabIndex

2. b two or three

3. a the same height

4. c the same height and the same width

5. e both b (color before black and white) and c (graphics before text)

6. b dark text on a light background

7. b 8, 10, or 12 point

8. a one or two

9. a sans serif

10. a one

11. d all of the above

12. d BorderStyle

13. a Appearance

14. b BackStyle

15. a &

16. b Caption

17. The first choice for an access key is the first letter of the caption, unless another letter provides a more meaningful association. If you can’t use the first letter and no other letter provides a more meaningful association, then use a distinctive consonant in the caption. The last choice is a vowel in the caption.

18. To give keyboard access to a text box, assign an access key to its identifying label. Then set the label’s TabIndex property to a number that is one less than the TabIndex property value of the text box it identifies.

Exercises

1. lb1Done project – The student is instructed to print the interface. The background color is a pale yellow.

[pic]

2. lb2Done project – The student is instructed to print the interface. The background color is a pale blue.

[pic]

3. lb3Done project – The student is instructed to print the interface. The access keys may vary.

[pic]

Tutorial 2, Lesson C

Questions

1. e PrintForm

2. d txtName.Text = “Jones”

3. e None of the above is valid

4. e All of the above are correct

5. a Close

6. d ControlBox

7. b Format

8. e Val

9. 5 Assemble the documentation.

1 Plan the application.

3 Code the application.

2 Build the user interface.

4 Test and debug the application

10. a a logic error

11. b a syntax error

Exercises

1. lc1Done project - The student should submit a printout of the interface and the code. The background color is a pale yellow.

[pic]

|Private Sub cmdCalc_Click() |Private Sub cmdPrint_Click() |

|lblComm.Caption = Val(txtSales.Text) * 0.1 |cmdCalc.Visible = False |

|lblComm.Caption = Format(lblComm.Caption, "currency") |cmdPrint.Visible = False |

|cmdPrint.SetFocus |cmdClear.Visible = False |

|End Sub |cmdExit.Visible = False |

| |PrintForm |

|Private Sub cmdClear_Click() |cmdCalc.Visible = True |

|txtName.Text = "" |cmdPrint.Visible = True |

|txtTerritory.Text = "" |cmdClear.Visible = True |

|txtSales.Text = "" |cmdExit.Visible = True |

|lblComm.Caption = "" |cmdClear.SetFocus |

|txtName.SetFocus |End Sub |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

2. lc2Done project - The student should submit a printout of the interface and the code. The background color is a pale blue.

[pic]

|Private Sub cmdCalc_Click() |Private Sub cmdExit_Click() |

|lblNSales.Caption = Val(txtNsales.Text) + _ |End |

|Val(txtNsales.Text) * Val(txtNinc.Text) |End Sub |

|lblSsales.Caption = Val(txtSsales.Text) + _ | |

|Val(txtSsales.Text) * Val(txtSinc.Text) |Private Sub cmdPrint_Click() |

|lblEsales.Caption = Val(txtEsales.Text) + _ |cmdCalc.Visible = False |

|Val(txtEsales.Text) * Val(txtEinc.Text) |cmdPrint.Visible = False |

|lblWsales.Caption = Val(txtWsales.Text) + _ |cmdClear.Visible = False |

|Val(txtWsales.Text) * Val(txtWinc.Text) |cmdExit.Visible = False |

|lblNSales.Caption = Format(lblNSales.Caption, "standard") |PrintForm |

|lblSsales.Caption = Format(lblSsales.Caption, "standard") |cmdCalc.Visible = True |

|lblEsales.Caption = Format(lblEsales.Caption, "standard") |cmdPrint.Visible = True |

|lblWsales.Caption = Format(lblWsales.Caption, "standard") |cmdClear.Visible = True |

|cmdPrint.SetFocus |cmdExit.Visible = True |

|End Sub |cmdClear.SetFocus |

| |End Sub |

|Private Sub cmdClear_Click() | |

|txtNsales.Text = "" | |

|txtSsales.Text = "" | |

|txtEsales.Text = "" | |

|txtWsales.Text = "" | |

|txtNinc.Text = "" | |

|txtSinc.Text = "" | |

|txtEinc.Text = "" | |

|txtWinc.Text = "" | |

|lblNSales.Caption = "" | |

|lblSsales.Caption = "" | |

|lblEsales.Caption = "" | |

|lblWsales.Caption = "" | |

|txtNsales.SetFocus | |

|End Sub | |

3. lc3Done project - The student should submit a printout of the interface and the code.

[pic]

|Private Sub cmdCalc_Click() | |

|lblWeekDay.Caption = Val(txtMon.Text) + Val(txtTues.Text) + _ | |

|Val(txtWed.Text) + Val(txtThurs.Text) + Val(txtFri.Text) | |

|lblWeekEnd.Caption = Val(txtSat.Text) + Val(txtSun.Text) | |

|cmdPrint.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|cmdCalc.Visible = False | |

|cmdPrint.Visible = False | |

|cmdExit.Visible = False | |

|PrintForm | |

|cmdCalc.Visible = True | |

|cmdPrint.Visible = True | |

|cmdExit.Visible = True | |

|txtMon.SetFocus | |

|End Sub | |

4. lc4Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The student also is instructed to make an executable file. (The student cannot use the Working Model to make an executable file.) The design of the interface will vary.

|Task |Object |Event |

|Convert twips to inches |cmdConvert |Click |

|Display inches in lblInches control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the number of inches (from cmdConvert) |lblInches |None |

|Get and display the number of twips |txtTwips |None |

Pseudocode:

cmdConvert: Calculate inches = twips / 1440

Display inches in lblInches control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtTwips control

Clear the Caption property of the lblInches control

Send the focus to the txtTwips control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin VB.TextBox txtTwips |

|Begin VB.Form frmTwips |Height = 285 |

|Caption = "Twips to Inches" |Left = 1200 |

|ClientHeight = 2895 |TabIndex = 1 |

|ClientLeft = 2625 |Top = 240 |

|ClientTop = 1950 |Width = 975 |

|ClientWidth = 3915 |End |

|LinkTopic = "Form1" |Begin VB.Label lblInches |

|LockControls = -1 'True |Appearance = 0 'Flat |

|MaxButton = 0 'False |BackColor = &H80000005& |

|ScaleHeight = 2895 |BackStyle = 0 'Transparent |

|ScaleWidth = 3915 |BorderStyle = 1 'Fixed Single |

|Begin mandButton cmdExit |ForeColor = &H80000008& |

|Caption = "E&xit" |Height = 255 |

|Height = 495 |Left = 1200 |

|Left = 2400 |TabIndex = 7 |

|TabIndex = 5 |Top = 600 |

|Top = 2040 |Width = 975 |

|Width = 1215 |End |

|End |Begin VB.Label Label2 |

|Begin mandButton cmdClear |AutoSize = -1 'True |

|Caption = "C&lear Screen" |Caption = "Inches:" |

|Height = 495 |Height = 195 |

|Left = 2400 |Left = 240 |

|TabIndex = 4 |TabIndex = 6 |

|Top = 1440 |Top = 600 |

|Width = 1215 |Width = 525 |

|End |End |

|Begin mandButton cmdPrint |Begin VB.Label Label1 |

|Caption = "&Print" |AutoSize = -1 'True |

|Height = 495 |Caption = "Enter &twips:" |

|Left = 2400 |Height = 195 |

|TabIndex = 3 |Left = 240 |

|Top = 840 |TabIndex = 0 |

|Width = 1215 |Top = 240 |

|End |Width = 825 |

|Begin mandButton cmdConvert |End |

|Caption = "&Convert" |End |

|Height = 495 | |

|Left = 2400 | |

|TabIndex = 2 | |

|Top = 240 | |

|Width = 1215 | |

|End | |

|Private Sub cmdClear_Click() |Private Sub cmdPrint_Click() |

|txtTwips.Text = "" |cmdConvert.Visible = False |

|lblInches.Caption = "" |cmdPrint.Visible = False |

|txtTwips.SetFocus |cmdClear.Visible = False |

|End Sub |cmdExit.Visible = False |

| |PrintForm |

|Private Sub cmdConvert_Click() |cmdConvert.Visible = True |

|lblInches.Caption = Val(txtTwips.Text) / 1440 |cmdPrint.Visible = True |

|cmdPrint.SetFocus |cmdClear.Visible = True |

|End Sub |cmdExit.Visible = True |

| |cmdClear.SetFocus |

|Private Sub cmdExit_Click() |End Sub |

|End | |

|End Sub | |

5. lc5Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate ending balance |cmdCalc |Click |

|Display ending balance in lblEnd control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the ending balance (from cmdCalc) |lblEnd |None |

|Get and display the beginning balance, monthly earnings, |txtBegin, txtEarn, |None |

|monthly expenses |txtExpense | |

Pseudocode:

cmdCalc: Calculate ending balance = beginning balance + monthly earnings – monthly

expenses

Display ending balance in lblEnd control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtBegin, txtEarn, txtExpense controls

Clear the Caption property of the lblEnd control

Send the focus to the txtBegin control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin VB.TextBox txtBegin |

|Begin VB.Form frmLee |Height = 285 |

|Caption = "John Lee's Finances" |Left = 1680 |

|ClientHeight = 2895 |TabIndex = 1 |

|ClientLeft = 2625 |Top = 240 |

|ClientTop = 1950 |Width = 975 |

|ClientWidth = 4620 |End |

|LinkTopic = "Form1" |Begin VB.Label Label4 |

|LockControls = -1 'True |AutoSize = -1 'True |

|MaxButton = 0 'False |Caption = "&Monthly &expenses:" |

|ScaleHeight = 2895 |Height = 195 |

|ScaleWidth = 4620 |Left = 240 |

|Begin VB.TextBox txtExpense |TabIndex = 4 |

|Height = 285 |Top = 960 |

|Left = 1680 |Width = 1320 |

|TabIndex = 5 |End |

|Top = 960 |Begin VB.Label Label3 |

|Width = 975 |AutoSize = -1 'True |

|End |Caption = "Ending balance:" |

|Begin VB.TextBox txtEarn |Height = 195 |

|Height = 285 |Left = 240 |

|Left = 1680 |TabIndex = 11 |

|TabIndex = 3 |Top = 1320 |

|Top = 600 |Width = 1155 |

|Width = 975 |End |

|End |Begin VB.Label lblEnd |

|Begin mandButton cmdExit |Appearance = 0 'Flat |

|Caption = "E&xit" |BackColor = &H80000005& |

|Height = 495 |BackStyle = 0 'Transparent |

|Left = 3120 |BorderStyle = 1 'Fixed Single |

|TabIndex = 9 |ForeColor = &H80000008& |

|Top = 2040 |Height = 255 |

|Width = 1215 |Left = 1680 |

|End |TabIndex = 10 |

|Begin mandButton cmdClear |Top = 1320 |

|Caption = "C&lear Screen" |Width = 975 |

|Height = 495 |End |

|Left = 3120 |Begin VB.Label Label2 |

|TabIndex = 8 |AutoSize = -1 'True |

|Top = 1440 |Caption = "&Monthly earnings:" |

|Width = 1215 |Height = 195 |

|End |Left = 240 |

|Begin mandButton cmdPrint |TabIndex = 2 |

|Caption = "&Print" |Top = 600 |

|Height = 495 |Width = 1245 |

|Left = 3120 |End |

|TabIndex = 7 |Begin VB.Label Label1 |

|Top = 840 |AutoSize = -1 'True |

|Width = 1215 |Caption = "&Beginning balance:" |

|End |Height = 195 |

|Begin mandButton cmdCalc |Left = 240 |

|Caption = "&Calculate" |TabIndex = 0 |

|Height = 495 |Top = 240 |

|Left = 3120 |Width = 1365 |

|TabIndex = 6 |End |

|Top = 240 |End |

|Width = 1215 | |

|End | |

|Private Sub cmdCalc_Click() |Private Sub cmdPrint_Click() |

|lblEnd.Caption = Val(txtBegin.Text) + Val(txtEarn.Text) _ |cmdCalc.Visible = False |

|- Val(txtExpense.Text) |cmdPrint.Visible = False |

|cmdPrint.SetFocus |cmdClear.Visible = False |

|End Sub |cmdExit.Visible = False |

| |PrintForm |

|Private Sub cmdClear_Click() |cmdCalc.Visible = True |

|txtBegin.Text = "" |cmdPrint.Visible = True |

|txtEarn.Text = "" |cmdClear.Visible = True |

|txtExpense.Text = "" |cmdExit.Visible = True |

|lblEnd.Caption = "" |cmdClear.SetFocus |

|txtBegin.SetFocus |End Sub |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

6. lc6Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate average of three numbers |cmdCalc |Click |

|Display average in lblAverage control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the average (from cmdCalc) |lblAverage |None |

|Get and display the first number, second number, and third |txtFirst, |None |

|number |txtSecond,txtThird | |

Pseudocode:

cmdCalc: Calculate average = (first number + second number + third number) / 3

Display average in lblAverage control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtFirst, txtSecond, txtThird controls

Clear the Caption property of the lblAverage control

Send the focus to the txtFirst control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin VB.TextBox txtFirst |

|Begin VB.Form frmJones |Height = 285 |

|Caption = "Average Calculator" |Left = 1680 |

|ClientHeight = 2895 |TabIndex = 1 |

|ClientLeft = 2625 |Top = 240 |

|ClientTop = 1950 |Width = 975 |

|ClientWidth = 4620 |End |

|LinkTopic = "Form1" |Begin VB.Label Label4 |

|LockControls = -1 'True |AutoSize = -1 'True |

|MaxButton = 0 'False |Caption = "&Third number:" |

|ScaleHeight = 2895 |Height = 195 |

|ScaleWidth = 4620 |Left = 240 |

|Begin VB.TextBox txtThird |TabIndex = 4 |

|Height = 285 |Top = 960 |

|Left = 1680 |Width = 975 |

|TabIndex = 5 |End |

|Top = 960 |Begin VB.Label Label3 |

|Width = 975 |AutoSize = -1 'True |

|End |Caption = "Average:" |

|Begin VB.TextBox txtSecond |Height = 195 |

|Height = 285 |Left = 240 |

|Left = 1680 |TabIndex = 11 |

|TabIndex = 3 |Top = 1320 |

|Top = 600 |Width = 645 |

|Width = 975 |End |

|End |Begin VB.Label lblAverage |

|Begin mandButton cmdExit |Appearance = 0 'Flat |

|Caption = "E&xit" |BackColor = &H80000005& |

|Height = 495 |BackStyle = 0 'Transparent |

|Left = 3120 |BorderStyle = 1 'Fixed Single |

|TabIndex = 9 |ForeColor = &H80000008& |

|Top = 2040 |Height = 255 |

|Width = 1215 |Left = 1680 |

|End |TabIndex = 10 |

|Begin mandButton cmdClear |Top = 1320 |

|Caption = "C&lear Screen" |Width = 975 |

|Height = 495 |End |

|Left = 3120 |Begin VB.Label Label2 |

|TabIndex = 8 |AutoSize = -1 'True |

|Top = 1440 |Caption = "&Second number:" |

|Width = 1215 |Height = 195 |

|End |Left = 240 |

|Begin mandButton cmdPrint |TabIndex = 2 |

|Caption = "&Print" |Top = 600 |

|Height = 495 |Width = 1170 |

|Left = 3120 |End |

|TabIndex = 7 |Begin VB.Label Label1 |

|Top = 840 |AutoSize = -1 'True |

|Width = 1215 |Caption = "&First number:" |

|End |Height = 195 |

|Begin mandButton cmdCalc |Left = 240 |

|Caption = "&Calculate" |TabIndex = 0 |

|Height = 495 |Top = 240 |

|Left = 3120 |Width = 900 |

|TabIndex = 6 |End |

|Top = 240 |End |

|Width = 1215 | |

|End | |

|Private Sub cmdCalc_Click() |Private Sub cmdExit_Click() |

|lblAverage.Caption = (Val(txtFirst.Text) + _ |End |

|Val(txtSecond.Text) + Val(txtThird.Text)) / 3 |End Sub |

|cmdPrint.SetFocus | |

|End Sub |Private Sub cmdPrint_Click() |

| |cmdCalc.Visible = False |

|Private Sub cmdClear_Click() |cmdPrint.Visible = False |

|txtFirst.Text = "" |cmdClear.Visible = False |

|txtSecond.Text = "" |cmdExit.Visible = False |

|txtThird.Text = "" |PrintForm |

|lblAverage.Caption = "" |cmdCalc.Visible = True |

|txtFirst.SetFocus |cmdPrint.Visible = True |

|End Sub |cmdClear.Visible = True |

| |cmdExit.Visible = True |

| |cmdClear.SetFocus |

| |End Sub |

7. lc7Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the paperback value, hardcover value, total number |cmdCalc |Click |

|of paperback and hardcover versions, and total value of the | | |

|paperback and hardcover versions | | |

|Display the calculated amounts in the lblPaperVal, lblHardVal,| | |

|lblTotalNum, and lblTotalVal controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the paperback value, hardcover value, total number of |lblPaperVal, lblHardVal, |None |

|paperbacks and hardcover versions, and total value of |lblTotalNum, lblTotalVal | |

|paperback and hardcover versions (from cmdCalc) | | |

|Get and display the title, number of paperback versions, |txtTitle, txtNumPaper, |None |

|number of hardcover versions, cost of paperback version, cost |txtNumHard, txtCostPaper, | |

|of hardcover version |txtCostHard | |

Pseudocode:

cmdCalc: Calculate paperback value = number of paperback versions * paperback cost

Calculate hardcover value = number of hardcover versions * hardcover cost

Calculate total number of paperback and hardcover versions = number of

paperback versions + number of hardcover versions

Calculate total value of paperback and hardcover versions = paperback value +

hardcover value

Display paperback value, hardcover value, total number of paperback and

hardcover versions, and total value of paperback and hardcover versions in lblPaperVal, lblHardVal, lblTotalNum, and lblTotalVal controls

Send the focus to the Print button

cmdClear: Clear the Text property of the txtTitle, txtNumPaper, txtNumHard,

txtCostPaper, and txtCostHard controls

Clear the Caption property of the lblPaperVal, lblHardVal, lblTotalNum, and

lblTotalVal controls

Send the focus to the txtTitle control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin mandButton cmdExit |

|Begin VB.Form frmBookworms |Caption = "E&xit" |

|Caption = "Bookworms Inc." |Height = 495 |

|ClientHeight = 3540 |Left = 4200 |

|ClientLeft = 2370 |TabIndex = 13 |

|ClientTop = 1770 |Top = 2760 |

|ClientWidth = 5655 |Width = 1215 |

|LinkTopic = "Form1" |End |

|LockControls = -1 'True |Begin mandButton cmdClear |

|MaxButton = 0 'False |Caption = "C&lear Screen" |

|ScaleHeight = 3540 |Height = 495 |

|ScaleWidth = 5655 |Left = 2880 |

|Begin VB.TextBox txtNumHard |TabIndex = 12 |

|Height = 285 |Top = 2760 |

|Left = 697 |Width = 1215 |

|TabIndex = 7 |End |

|Top = 1440 |Begin mandButton cmdPrint |

|Width = 975 |Caption = "&Print" |

|End |Height = 495 |

|Begin VB.TextBox txtCostHard |Left = 1560 |

|Height = 285 |TabIndex = 11 |

|Left = 2377 |Top = 2760 |

|TabIndex = 9 |Width = 1215 |

|Top = 1440 |End |

|Width = 975 |Begin mandButton cmdCalc |

|End |Caption = "&Calculate" |

|Begin VB.TextBox txtCostPaper |Height = 495 |

|Height = 285 |Left = 240 |

|Left = 2377 |TabIndex = 10 |

|TabIndex = 5 |Top = 2760 |

|Top = 840 |Width = 1215 |

|Width = 975 |End |

|End |Begin VB.TextBox txtTitle |

|Begin VB.TextBox txtNumPaper |Height = 285 |

|Height = 285 |Left = 1177 |

|Left = 697 |TabIndex = 1 |

|TabIndex = 3 |Top = 240 |

|Top = 840 |Width = 2535 |

|Width = 975 |End |

|End | |

|Begin VB.Label lblHardVal |Begin VB.Label Label7 |

|Appearance = 0 'Flat |AutoSize = -1 'True |

|BackColor = &H80000005& |Caption = "Number of &hardcover:" |

|BackStyle = 0 'Transparent |Height = 195 |

|BorderStyle = 1 'Fixed Single |Left = 697 |

|ForeColor = &H80000008& |TabIndex = 6 |

|Height = 255 |Top = 1200 |

|Left = 3697 |Width = 1545 |

|TabIndex = 21 |End |

|Top = 1440 |Begin VB.Label Label6 |

|Width = 975 |AutoSize = -1 'True |

|End |Caption = "&Har&dcover cost:" |

|Begin VB.Label lblPaperVal |Height = 195 |

|Appearance = 0 'Flat |Left = 2377 |

|BackColor = &H80000005& |TabIndex = 8 |

|BackStyle = 0 'Transparent |Top = 1200 |

|BorderStyle = 1 'Fixed Single |Width = 1140 |

|ForeColor = &H80000008& |End |

|Height = 255 |Begin VB.Label Label5 |

|Left = 3697 |AutoSize = -1 'True |

|TabIndex = 20 |Caption = "Hardcover value:" |

|Top = 840 |Height = 195 |

|Width = 975 |Left = 3697 |

|End |TabIndex = 16 |

|Begin VB.Label Label10 |Top = 1200 |

|AutoSize = -1 'True |Width = 1230 |

|Caption = "Total versions:" |End |

|Height = 195 |Begin VB.Label Label4 |

|Left = 697 |AutoSize = -1 'True |

|TabIndex = 19 |Caption = "&Paper&back cost:" |

|Top = 2040 |Height = 195 |

|Width = 1035 |Left = 2377 |

|End |TabIndex = 4 |

|Begin VB.Label Label9 |Top = 600 |

|AutoSize = -1 'True |Width = 1170 |

|Caption = "Total value:" |End |

|Height = 195 |Begin VB.Label Label3 |

|Left = 3697 |AutoSize = -1 'True |

|TabIndex = 18 |Caption = "Paperback value:" |

|Top = 2040 |Height = 195 |

|Width = 840 |Left = 3697 |

|End |TabIndex = 15 |

|Begin VB.Label lblTotalVal |Top = 600 |

|Appearance = 0 'Flat |Width = 1260 |

|BackColor = &H80000005& |End |

|BackStyle = 0 'Transparent |Begin VB.Label lblTotalNum |

|BorderStyle = 1 'Fixed Single |Appearance = 0 'Flat |

|ForeColor = &H80000008& |BackColor = &H80000005& |

|Height = 255 |BackStyle = 0 'Transparent |

|Left = 3697 |BorderStyle = 1 'Fixed Single |

|TabIndex = 17 |ForeColor = &H80000008& |

|Top = 2280 |Height = 255 |

|Width = 975 |Left = 697 |

|End |TabIndex = 14 |

| |Top = 2280 |

| |Width = 975 |

| |End |

|Begin VB.Label Label2 |Begin VB.Label Label1 |

|AutoSize = -1 'True |AutoSize = -1 'True |

|Caption = "&Number of paperback:" |Caption = "&Title:" |

|Height = 195 |Height = 195 |

|Left = 697 |Left = 697 |

|TabIndex = 2 |TabIndex = 0 |

|Top = 600 |Top = 240 |

|Width = 1590 |Width = 345 |

|End |End |

| |End |

|Private Sub cmdCalc_Click() | |

|lblPaperVal.Caption = Val(txtNumPaper.Text) * Val(txtCostPaper.Text) | |

|lblHardVal.Caption = Val(txtNumHard.Text) * Val(txtCostHard.Text) | |

|lblTotalNum.Caption = Val(txtNumPaper.Text) + Val(txtNumHard.Text) | |

|lblTotalVal.Caption = Val(lblPaperVal.Caption) + Val(lblHardVal.Caption) | |

|cmdPrint.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdClear_Click() | |

|txtTitle.Text = "" | |

|txtNumPaper.Text = "" | |

|txtNumHard.Text = "" | |

|txtCostPaper.Text = "" | |

|txtCostHard.Text = "" | |

|lblPaperVal.Caption = "" | |

|lblHardVal.Caption = "" | |

|lblTotalNum.Caption = "" | |

|lblTotalVal.Caption = "" | |

|txtTitle.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|cmdCalc.Visible = False | |

|cmdPrint.Visible = False | |

|cmdClear.Visible = False | |

|cmdExit.Visible = False | |

|PrintForm | |

|cmdCalc.Visible = True | |

|cmdPrint.Visible = True | |

|cmdClear.Visible = True | |

|cmdExit.Visible = True | |

|cmdClear.SetFocus | |

|End Sub | |

8. lc8Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the discount and the new price |cmdCalc |Click |

|Display the discount and the new price in the lblDisc and | | |

|lblNewPrice controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the discount and new price (from cmdCalc) |lblDisc, lblNewPrice |None |

|Get and display the original price |txtOrigPrice |None |

Pseudocode:

cmdCalc: Calculate discount = original price * 25%

Calculate new price = original price – discount

Display the discount in the lblDisc control

Display the new price in the lblNewPrice control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtOrigPrice control

Clear the Caption property of the lblDisc and lblNewPrice controls

Send the focus to the txtOrigPrice control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: (discount and new price may not be formatted) Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin VB.Label Label4 |

|Begin VB.Form frmJackets |AutoSize = -1 'True |

|Caption = "Jackets Unlimited" |Caption = "New price:" |

|ClientHeight = 2895 |Height = 195 |

|ClientLeft = 2625 |Left = 240 |

|ClientTop = 1950 |TabIndex = 9 |

|ClientWidth = 4020 |Top = 960 |

|LinkTopic = "Form1" |Width = 765 |

|LockControls = -1 'True |End |

|MaxButton = 0 'False |Begin VB.Label lblNewPrice |

|ScaleHeight = 2895 |Appearance = 0 'Flat |

|ScaleWidth = 4020 |BackColor = &H80000005& |

|Begin mandButton cmdExit |BackStyle = 0 'Transparent |

|Caption = "E&xit" |BorderStyle = 1 'Fixed Single |

|Height = 495 |ForeColor = &H80000008& |

|Left = 2520 |Height = 255 |

|TabIndex = 5 |Left = 1320 |

|Top = 2040 |TabIndex = 8 |

|Width = 1215 |Top = 960 |

|End |Width = 975 |

|Begin mandButton cmdClear |End |

|Caption = "C&lear Screen" |Begin VB.Label lblDisc |

|Height = 495 |Appearance = 0 'Flat |

|Left = 2520 |BackColor = &H80000005& |

|TabIndex = 4 |BackStyle = 0 'Transparent |

|Top = 1440 |BorderStyle = 1 'Fixed Single |

|Width = 1215 |ForeColor = &H80000008& |

|End |Height = 255 |

|Begin mandButton cmdPrint |Left = 1320 |

|Caption = "&Print" |TabIndex = 7 |

|Height = 495 |Top = 600 |

|Left = 2520 |Width = 975 |

|TabIndex = 3 |End |

|Top = 840 |Begin VB.Label Label2 |

|Width = 1215 |AutoSize = -1 'True |

|End |Caption = "Discount:" |

|Begin mandButton cmdCalc |Height = 195 |

|Caption = "&Calculate" |Left = 240 |

|Height = 495 |TabIndex = 6 |

|Left = 2520 |Top = 600 |

|TabIndex = 2 |Width = 675 |

|Top = 240 |End |

|Width = 1215 |Begin VB.Label Label1 |

|End |AutoSize = -1 'True |

|Begin VB.TextBox txtOrigPrice |Caption = "&Original price:" |

|Height = 285 |Height = 195 |

|Left = 1320 |Left = 240 |

|TabIndex = 1 |TabIndex = 0 |

|Top = 240 |Top = 240 |

|Width = 975 |Width = 960 |

|End |End |

| |End |

|Private Sub cmdCalc_Click() |Private Sub cmdExit_Click() |

|lblDisc.Caption = Val(txtOrigPrice.Text) * 0.25 |End |

|lblNewPrice.Caption = Val(txtOrigPrice.Text) - Val(lblDisc.Caption) |End Sub |

|lblDisc.Caption = Format(lblDisc.Caption, "standard") | |

|lblNewPrice.Caption = Format(lblNewPrice.Caption, "standard") |Private Sub cmdPrint_Click() |

|cmdPrint.SetFocus |cmdCalc.Visible = False |

|End Sub |cmdPrint.Visible = False |

| |cmdClear.Visible = False |

|Private Sub cmdClear_Click() |cmdExit.Visible = False |

|txtOrigPrice.Text = "" |PrintForm |

|lblDisc.Caption = "" |cmdCalc.Visible = True |

|lblNewPrice.Caption = "" |cmdPrint.Visible = True |

|txtOrigPrice.SetFocus |cmdClear.Visible = True |

|End Sub |cmdExit.Visible = True |

| |cmdClear.SetFocus |

| |End Sub |

9. lc9Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the total due |cmdCalc |Click |

|Display the total due in the lblTotal control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the total due (from cmdCalc) |lblTotal |None |

|Get and display the name, number of typed envelopes, and |txtName, txtEnvelopes, txtPages|None |

|number of typed pages | | |

Pseudocode:

cmdCalc: Calculate total due = number of typed envelopes * .10 +

number of typed pages * .25

Display the total due in the lblTotal control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtName, txtEnvelopes, and txtPages controls

Clear the Caption property of the lblTotal control

Send the focus to the txtName control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: (total due may not be formatted) Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin VB.TextBox txtName |

|Begin VB.Form frmTyping |Height = 285 |

|Caption = "Typing Salon" |Left = 1320 |

|ClientHeight = 2775 |TabIndex = 1 |

|ClientLeft = 2625 |Top = 240 |

|ClientTop = 1950 |Width = 1935 |

|ClientWidth = 5040 |End |

|LinkTopic = "Form1" |Begin VB.Label Label3 |

|LockControls = -1 'True |AutoSize = -1 'True |

|MaxButton = 0 'False |Caption = "&Pages:" |

|ScaleHeight = 2775 |Height = 195 |

|ScaleWidth = 5040 |Left = 2280 |

|Begin VB.TextBox txtPages |TabIndex = 4 |

|Height = 285 |Top = 600 |

|Left = 2880 |Width = 495 |

|TabIndex = 5 |End |

|Top = 600 |Begin VB.Label Label2 |

|Width = 375 |AutoSize = -1 'True |

|End |Caption = "&Envelopes:" |

|Begin VB.TextBox txtEnvelopes |Height = 195 |

|Height = 285 |Left = 240 |

|Left = 1320 |TabIndex = 2 |

|TabIndex = 3 |Top = 600 |

|Top = 600 |Width = 795 |

|Width = 375 |End |

|End |Begin VB.Label Label4 |

|Begin mandButton cmdExit |AutoSize = -1 'True |

|Caption = "E&xit" |Caption = "Total due:" |

|Height = 495 |Height = 195 |

|Left = 3480 |Left = 240 |

|TabIndex = 9 |TabIndex = 11 |

|Top = 2040 |Top = 960 |

|Width = 1215 |Width = 720 |

|End |End |

|Begin mandButton cmdClear |Begin VB.Label lblTotal |

|Caption = "C&lear Screen" |Appearance = 0 'Flat |

|Height = 495 |BackColor = &H80000005& |

|Left = 3480 |BackStyle = 0 'Transparent |

|TabIndex = 8 |BorderStyle = 1 'Fixed Single |

|Top = 1440 |ForeColor = &H80000008& |

|Width = 1215 |Height = 255 |

|End |Left = 1320 |

|Begin mandButton cmdPrint |TabIndex = 10 |

|Caption = "&Print" |Top = 960 |

|Height = 495 |Width = 975 |

|Left = 3480 |End |

|TabIndex = 7 |Begin VB.Label Label1 |

|Top = 840 |AutoSize = -1 'True |

|Width = 1215 |Caption = "&Name:" |

|End |Height = 195 |

|Begin mandButton cmdCalc |Left = 240 |

|Caption = "&Calculate" |TabIndex = 0 |

|Height = 495 |Top = 240 |

|Left = 3480 |Width = 465 |

|TabIndex = 6 |End |

|Top = 240 |End |

|Width = 1215 | |

|End | |

|Private Sub cmdCalc_Click() |Private Sub cmdExit_Click() |

|lblTotal.Caption = Val(txtEnvelopes.Text) * 0.1 _ |End |

|+ Val(txtPages.Text) * 0.25 |End Sub |

|lblTotal.Caption = Format(lblTotal.Caption, "standard") | |

|cmdPrint.SetFocus |Private Sub cmdPrint_Click() |

|End Sub |cmdCalc.Visible = False |

| |cmdPrint.Visible = False |

|Private Sub cmdClear_Click() |cmdClear.Visible = False |

|txtName.Text = "" |cmdExit.Visible = False |

|txtEnvelopes.Text = "" |PrintForm |

|txtPages.Text = "" |cmdCalc.Visible = True |

|lblTotal.Caption = "" |cmdPrint.Visible = True |

|txtName.SetFocus |cmdClear.Visible = True |

|End Sub |cmdExit.Visible = True |

| |cmdClear.SetFocus |

| |End Sub |

10. lc10Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the total number of registered employees and the |cmdCalc |Click |

|total cost | | |

|Display the total number of registered employees and the total| | |

|cost in the lblTotalNum and lblTotalCost controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the total number of registered employees and the total|lblTotalNum, lblTotalCost |None |

|cost (from cmdCalc) | | |

|Get and display the name, address, city, state, zip, number of|txtName, txtAddress, txtCity, |None |

|employees registering for the “How to be an Effective Manager”|txtState, txtZip, txtEffective,| |

|seminar, and number of employees registering for the “How to |txtRun | |

|Run a Small Business” seminar | | |

Pseudocode:

cmdCalc: Calculate the total number of registered employees = number of employees

registering for the “How to be an Effective Manager” seminar + number of employees registering for the “How to Run a Small Business” seminar

Calculate the total cost = total number of registered employees * 200

Display the total number of registered employees in the lblTotalNum control

Display the total cost in the lblTotalCost control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtName, txtAddress, txtCity, txtState, txtZip,

txtEffective, and txtRun controls

Clear the Caption property of the lblTotalNum and lblTotalCost controls

Send the focus to the txtName control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: (the total due may not be formatted.) Printout # 2:

[pic] [pic]

|VERSION 5.00 |Begin mandButton cmdCalc |

|Begin VB.Form frmRegister |Caption = "&Calculate" |

|Caption = "Management USA" |BeginProperty Font |

|ClientHeight = 4665 |Name = "MS Sans Serif" |

|ClientLeft = 1620 |Size = 9.75 |

|ClientTop = 1725 |Charset = 0 |

|ClientWidth = 6030 |Weight = 400 |

|LinkTopic = "Form1" |Underline = 0 'False |

|LockControls = -1 'True |Italic = 0 'False |

|MaxButton = 0 'False |Strikethrough = 0 'False |

|PaletteMode = 1 'UseZOrder |EndProperty |

|ScaleHeight = 4665 |Height = 495 |

|ScaleWidth = 6030 |Left = 4320 |

|Begin VB.TextBox txtCity |TabIndex = 14 |

|BeginProperty Font |Top = 2040 |

|Name = "MS Sans Serif" |Width = 1215 |

|Size = 9.75 |End |

|Charset = 0 |Begin VB.TextBox txtName |

|Weight = 400 |BeginProperty Font |

|Underline = 0 'False |Name = "MS Sans Serif" |

|Italic = 0 'False |Size = 9.75 |

|Strikethrough = 0 'False |Charset = 0 |

|EndProperty |Weight = 400 |

|Height = 495 |Underline = 0 'False |

|Left = 1080 |Italic = 0 'False |

|TabIndex = 5 |Strikethrough = 0 'False |

|Top = 1440 |EndProperty |

|Width = 2895 |Height = 495 |

|End |Left = 1080 |

| |TabIndex = 1 |

| |Top = 240 |

| |Width = 2895 |

| |End |

|Begin VB.TextBox txtAddress |Begin VB.TextBox txtEffective |

|BeginProperty Font |BackColor = &H00FFFFFF& |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

|Height = 495 |EndProperty |

|Left = 1080 |Height = 495 |

|TabIndex = 3 |Left = 3000 |

|Top = 840 |TabIndex = 11 |

|Width = 2895 |Top = 2760 |

|End |Width = 975 |

|Begin VB.TextBox txtState |End |

|BeginProperty Font |Begin VB.TextBox txtRun |

|Name = "MS Sans Serif" |BackColor = &H00FFFFFF& |

|Size = 9.75 |BeginProperty Font |

|Charset = 0 |Name = "MS Sans Serif" |

|Weight = 400 |Size = 9.75 |

|Underline = 0 'False |Charset = 0 |

|Italic = 0 'False |Weight = 400 |

|Strikethrough = 0 'False |Underline = 0 'False |

|EndProperty |Italic = 0 'False |

|Height = 495 |Strikethrough = 0 'False |

|Left = 1080 |EndProperty |

|TabIndex = 7 |Height = 495 |

|Top = 2040 |Left = 3000 |

|Width = 735 |TabIndex = 13 |

|End |Top = 3360 |

|Begin VB.TextBox txtZip |Width = 975 |

|BeginProperty Font |End |

|Name = "MS Sans Serif" |Begin mandButton cmdPrint |

|Size = 9.75 |Caption = "&Print" |

|Charset = 0 |BeginProperty Font |

|Weight = 400 |Name = "MS Sans Serif" |

|Underline = 0 'False |Size = 9.75 |

|Italic = 0 'False |Charset = 0 |

|Strikethrough = 0 'False |Weight = 400 |

|EndProperty |Underline = 0 'False |

|Height = 495 |Italic = 0 'False |

|Left = 3000 |Strikethrough = 0 'False |

|TabIndex = 9 |EndProperty |

|Top = 2040 |Height = 495 |

|Width = 975 |Left = 4320 |

|End |TabIndex = 15 |

| |Top = 2640 |

| |Width = 1215 |

| |End |

|Begin mandButton cmdClear |Begin VB.Label Label1 |

|Caption = "C&lear" |AutoSize = -1 'True |

|BeginProperty Font |Caption = "Total registered:" |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

|Height = 495 |EndProperty |

|Left = 4320 |Height = 240 |

|TabIndex = 16 |Left = 4320 |

|Top = 3240 |TabIndex = 20 |

|Width = 1215 |Top = 240 |

|End |Width = 1470 |

|Begin mandButton cmdExit |End |

|Caption = "E&xit" |Begin VB.Label Label2 |

|BeginProperty Font |Caption = "&Name:" |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

|Height = 495 |EndProperty |

|Left = 4320 |Height = 240 |

|TabIndex = 17 |Left = 240 |

|Top = 3840 |TabIndex = 0 |

|Width = 1215 |Top = 240 |

|End |Width = 600 |

|Begin VB.Label lblTotalNum |End |

|Appearance = 0 'Flat |Begin VB.Label Label3 |

|BackColor = &H80000005& |Caption = "&Address:" |

|BackStyle = 0 'Transparent |BeginProperty Font |

|BorderStyle = 1 'Fixed Single |Name = "MS Sans Serif" |

|BeginProperty Font |Size = 9.75 |

|Name = "MS Sans Serif" |Charset = 0 |

|Size = 9.75 |Weight = 400 |

|Charset = 0 |Underline = 0 'False |

|Weight = 400 |Italic = 0 'False |

|Underline = 0 'False |Strikethrough = 0 'False |

|Italic = 0 'False |EndProperty |

|Strikethrough = 0 'False |Height = 240 |

|EndProperty |Left = 240 |

|ForeColor = &H80000008& |TabIndex = 2 |

|Height = 495 |Top = 840 |

|Left = 4320 |Width = 810 |

|TabIndex = 21 |End |

|Top = 480 | |

|Width = 1215 | |

|End | |

|Begin VB.Label Label4 |Begin VB.Label Label7 |

|Caption = "Cit&y:" |AutoSize = -1 'True |

|BeginProperty Font |Caption = "&Effective manager seminar:" |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

|Height = 240 |EndProperty |

|Left = 240 |Height = 240 |

|TabIndex = 4 |Left = 240 |

|Top = 1440 |TabIndex = 10 |

|Width = 375 |Top = 2760 |

|End |Width = 2430 |

|Begin VB.Label Label5 |End |

|Caption = "&State:" |Begin VB.Label Label8 |

|BeginProperty Font |AutoSize = -1 'True |

|Name = "MS Sans Serif" |Caption = "Small &business seminar:" |

|Size = 9.75 |BeginProperty Font |

|Charset = 0 |Name = "MS Sans Serif" |

|Weight = 400 |Size = 9.75 |

|Underline = 0 'False |Charset = 0 |

|Italic = 0 'False |Weight = 400 |

|Strikethrough = 0 'False |Underline = 0 'False |

|EndProperty |Italic = 0 'False |

|Height = 240 |Strikethrough = 0 'False |

|Left = 240 |EndProperty |

|TabIndex = 6 |Height = 240 |

|Top = 2040 |Left = 240 |

|Width = 510 |TabIndex = 12 |

|End |Top = 3360 |

|Begin VB.Label Label6 |Width = 2175 |

|Caption = "&Zip:" |End |

|BeginProperty Font |Begin VB.Label Label11 |

|Name = "MS Sans Serif" |AutoSize = -1 'True |

|Size = 9.75 |Caption = "Total due:" |

|Charset = 0 |BeginProperty Font |

|Weight = 400 |Name = "MS Sans Serif" |

|Underline = 0 'False |Size = 9.75 |

|Italic = 0 'False |Charset = 0 |

|Strikethrough = 0 'False |Weight = 400 |

|EndProperty |Underline = 0 'False |

|Height = 240 |Italic = 0 'False |

|Left = 2640 |Strikethrough = 0 'False |

|TabIndex = 8 |EndProperty |

|Top = 2040 |Height = 240 |

|Width = 330 |Left = 4320 |

|End |TabIndex = 18 |

| |Top = 1080 |

| |Width = 900 |

| |End |

|Begin VB.Label lblTotalCost | |

|Appearance = 0 'Flat | |

|BackColor = &H80000005& | |

|BackStyle = 0 'Transparent | |

|BorderStyle = 1 'Fixed Single | |

|BeginProperty Font | |

|Name = "MS Sans Serif" | |

|Size = 9.75 | |

|Charset = 0 | |

|Weight = 400 | |

|Underline = 0 'False | |

|Italic = 0 'False | |

|Strikethrough = 0 'False | |

|EndProperty | |

|ForeColor = &H80000008& | |

|Height = 495 | |

|Left = 4320 | |

|TabIndex = 19 | |

|Top = 1320 | |

|Width = 1215 | |

|End | |

|End | |

|Private Sub cmdCalc_Click() |Private Sub cmdExit_Click() |

|lblTotalNum.Caption = Val(txtEffective.Text) + Val(txtRun.Text) |End |

|lblTotalCost.Caption = Val(lblTotalNum.Caption) * 200 |End Sub |

|lblTotalCost.Caption = Format(lblTotalCost.Caption, "currency") | |

|cmdPrint.SetFocus |Private Sub cmdPrint_Click() |

|End Sub |cmdCalc.Visible = False |

| |cmdPrint.Visible = False |

|Private Sub cmdClear_Click() |cmdClear.Visible = False |

|txtName.Text = "" |cmdExit.Visible = False |

|txtAddress.Text = "" |PrintForm |

|txtCity.Text = "" |cmdCalc.Visible = True |

|txtState.Text = "" |cmdPrint.Visible = True |

|txtZip.Text = "" |cmdClear.Visible = True |

|txtEffective.Text = "" |cmdExit.Visible = True |

|txtRun.Text = "" |cmdClear.SetFocus |

|lblTotalNum.Caption = "" |End Sub |

|lblTotalCost.Caption = "" | |

|txtName.SetFocus | |

|End Sub | |

11. lc11Done project – The student should submit a TOE chart (ordered by object), pseudocode, two printouts of the form with the test data showing, the Form As Text, and the code. The student also is instructed to create an executable file. (The student cannot use the Working Model to create the executable file.) The design of the interface will vary.

|Task |Object |Event |

|Calculate gross pay, FWT, FICA, state tax, and net pay |cmdCalc |Click |

|Display the calculated amounts in the lblGross, lblFwt, | | |

|lblFica, lblState, and lbllNet controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the gross pay, FWT, FICA, state tax, and net pay |lblGross, lblFwt, lblFica, |None |

|(from cmdCalc) |lblState, lblNet | |

|Get and display the name, hours worked, and rate of pay |txtName, txtHours, txtRate |None |

Pseudocode:

cmdCalc: Calculate the gross pay = hours worked * rate of pay

Calculate the FWT = gross pay * 20%

Calculate the FICA = gross pay * 8%

Calculate the state tax = gross pay * 2%

Calculate the net pay = gross pay – FWT – FICA – state tax

Display the gross pay in the lblGross control

Display the FWT in the lblFwt control

Display the FICA in the lblFica control

Display the state tax in the lblState control

Display the net pay in the lblNet control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtName, txtHours, and txtRate controls

Clear the Caption property of the lblGross, lblFwt, lblFica, lblState, and lblNet controls

Send the focus to the txtName control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: (the amounts may not be formatted.) Printout # 2:

[pic] [pic]

|VERSION 5.00 |Height = 495 |

|Begin VB.Form frmSun |Left = 960 |

|Caption = "Sun Projects Payroll" |TabIndex = 1 |

|ClientHeight = 4665 |Top = 240 |

|ClientLeft = 2520 |Width = 2655 |

|ClientTop = 1665 |End |

|ClientWidth = 3960 |Begin VB.TextBox txtHours |

|LinkTopic = "Form1" |BeginProperty Font |

|LockControls = -1 'True |Name = "MS Sans Serif" |

|MaxButton = 0 'False |Size = 9.75 |

|PaletteMode = 1 'UseZOrder |Charset = 0 |

|ScaleHeight = 4665 |Weight = 400 |

|ScaleWidth = 3960 |Underline = 0 'False |

|Begin VB.TextBox txtRate |Italic = 0 'False |

|BeginProperty Font |Strikethrough = 0 'False |

|Name = "MS Sans Serif" |EndProperty |

|Size = 9.75 |Height = 495 |

|Charset = 0 |Left = 960 |

|Weight = 400 |TabIndex = 3 |

|Underline = 0 'False |Top = 840 |

|Italic = 0 'False |Width = 735 |

|Strikethrough = 0 'False |End |

|EndProperty |Begin mandButton cmdPrint |

|Height = 495 |Caption = "&Print" |

|Left = 2880 |BeginProperty Font |

|TabIndex = 5 |Name = "MS Sans Serif" |

|Top = 840 |Size = 9.75 |

|Width = 735 |Charset = 0 |

|End |Weight = 400 |

|Begin mandButton cmdCalc |Underline = 0 'False |

|Caption = "&Calculate" |Italic = 0 'False |

|BeginProperty Font |Strikethrough = 0 'False |

|Name = "MS Sans Serif" |EndProperty |

|Size = 9.75 |Height = 495 |

|Charset = 0 |Left = 2400 |

|Weight = 400 |TabIndex = 7 |

|Underline = 0 'False |Top = 2640 |

|Italic = 0 'False |Width = 1215 |

|Strikethrough = 0 'False |End |

|EndProperty |Begin mandButton cmdClear |

|Height = 495 |Caption = "C&lear" |

|Left = 2400 |BeginProperty Font |

|TabIndex = 6 |Name = "MS Sans Serif" |

|Top = 2040 |Size = 9.75 |

|Width = 1215 |Charset = 0 |

|End |Weight = 400 |

|Begin VB.TextBox txtName |Underline = 0 'False |

|BeginProperty Font |Italic = 0 'False |

|Name = "MS Sans Serif" |Strikethrough = 0 'False |

|Size = 9.75 |EndProperty |

|Charset = 0 |Height = 495 |

|Weight = 400 |Left = 2400 |

|Underline = 0 'False |TabIndex = 8 |

|Italic = 0 'False |Top = 3240 |

|Strikethrough = 0 'False |Width = 1215 |

|EndProperty |End |

|Begin mandButton cmdExit |Begin VB.Label lblFwt |

|Caption = "E&xit" |Appearance = 0 'Flat |

|BeginProperty Font |BackColor = &H80000005& |

|Name = "MS Sans Serif" |BackStyle = 0 'Transparent |

|Size = 9.75 |BorderStyle = 1 'Fixed Single |

|Charset = 0 |ForeColor = &H80000008& |

|Weight = 400 |Height = 495 |

|Underline = 0 'False |Left = 960 |

|Italic = 0 'False |TabIndex = 17 |

|Strikethrough = 0 'False |Top = 2040 |

|EndProperty |Width = 735 |

|Height = 495 |End |

|Left = 2400 |Begin VB.Label lblGross |

|TabIndex = 9 |Appearance = 0 'Flat |

|Top = 3840 |BackColor = &H80000005& |

|Width = 1215 |BackStyle = 0 'Transparent |

|End |BorderStyle = 1 'Fixed Single |

|Begin VB.Label lblNet |ForeColor = &H80000008& |

|Appearance = 0 'Flat |Height = 495 |

|BackColor = &H80000005& |Left = 960 |

|BackStyle = 0 'Transparent |TabIndex = 16 |

|BorderStyle = 1 'Fixed Single |Top = 1440 |

|ForeColor = &H80000008& |Width = 735 |

|Height = 495 |End |

|Left = 960 |Begin VB.Label Label9 |

|TabIndex = 20 |AutoSize = -1 'True |

|Top = 3840 |Caption = "Net:" |

|Width = 735 |BeginProperty Font |

|End |Name = "MS Sans Serif" |

|Begin VB.Label lblState |Size = 9.75 |

|Appearance = 0 'Flat |Charset = 0 |

|BackColor = &H80000005& |Weight = 400 |

|BackStyle = 0 'Transparent |Underline = 0 'False |

|BorderStyle = 1 'Fixed Single |Italic = 0 'False |

|ForeColor = &H80000008& |Strikethrough = 0 'False |

|Height = 495 |EndProperty |

|Left = 960 |Height = 240 |

|TabIndex = 19 |Left = 240 |

|Top = 3240 |TabIndex = 15 |

|Width = 735 |Top = 3840 |

|End |Width = 360 |

|Begin VB.Label lblFica |End |

|Appearance = 0 'Flat |Begin VB.Label Label1 |

|BackColor = &H80000005& |AutoSize = -1 'True |

|BackStyle = 0 'Transparent |BeginProperty Font |

|BorderStyle = 1 'Fixed Single |Name = "MS Sans Serif" |

|ForeColor = &H80000008& |Size = 9.75 |

|Height = 495 |Charset = 0 |

|Left = 960 |Weight = 400 |

|TabIndex = 18 |Underline = 0 'False |

|Top = 2640 |Italic = 0 'False |

|Width = 735 |Strikethrough = 0 'False |

|End |EndProperty |

| Height = 240 |Height = 240 |

|Left = 960 |Left = 2280 |

|TabIndex = 14 |TabIndex = 4 |

|Top = 1560 |Top = 840 |

|Width = 45 |Width = 480 |

|End |End |

|Begin VB.Label Label2 |Begin VB.Label Label5 |

|Caption = "&Name:" |AutoSize = -1 'True |

|BeginProperty Font |Caption = "Gross:" |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

|Height = 240 |EndProperty |

|Left = 240 |Height = 240 |

|TabIndex = 0 |Left = 240 |

|Top = 240 |TabIndex = 10 |

|Width = 600 |Top = 1440 |

|End |Width = 585 |

|Begin VB.Label Label3 |End |

|AutoSize = -1 'True |Begin VB.Label Label6 |

|Caption = "&Hours:" |AutoSize = -1 'True |

|BeginProperty Font |Caption = "FWT:" |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

|Height = 240 |EndProperty |

|Left = 240 |Height = 240 |

|TabIndex = 2 |Left = 240 |

|Top = 840 |TabIndex = 11 |

|Width = 585 |Top = 2040 |

|End |Width = 495 |

|Begin VB.Label Label4 |End |

|AutoSize = -1 'True |Begin VB.Label Label7 |

|Caption = "&Rate:" |AutoSize = -1 'True |

|BeginProperty Font |Caption = "FICA:" |

|Name = "MS Sans Serif" |BeginProperty Font |

|Size = 9.75 |Name = "MS Sans Serif" |

|Charset = 0 |Size = 9.75 |

|Weight = 400 |Charset = 0 |

|Underline = 0 'False |Weight = 400 |

|Italic = 0 'False |Underline = 0 'False |

|Strikethrough = 0 'False |Italic = 0 'False |

|EndProperty |Strikethrough = 0 'False |

| |EndProperty |

|Height = 240 |Height = 240 |

|Left = 240 |Left = 240 |

|TabIndex = 12 |TabIndex = 13 |

|Top = 2640 |Top = 3240 |

|Width = 480 |Width = 510 |

|End |End |

|Begin VB.Label Label8 |End |

|AutoSize = -1 'True | |

|Caption = "State:" | |

|BeginProperty Font | |

|Name = "MS Sans Serif" | |

|Size = 9.75 | |

|Charset = 0 | |

|Weight = 400 | |

|Underline = 0 'False | |

|Italic = 0 'False | |

|Strikethrough = 0 'False | |

|EndProperty | |

|Private Sub cmdCalc_Click() |Private Sub cmdExit_Click() |

|lblGross.Caption = Val(txtHours.Text) * Val(txtRate.Text) |End |

|lblFwt.Caption = Val(lblGross.Caption) * 0.2 |End Sub |

|lblFica.Caption = Val(lblGross.Caption) * 0.08 | |

|lblState.Caption = Val(lblGross.Caption) * 0.02 |Private Sub cmdPrint_Click() |

|lblNet.Caption = lblGross.Caption - lblFwt.Caption _ |cmdCalc.Visible = False |

|- lblFica.Caption - lblState.Caption |cmdPrint.Visible = False |

|lblGross.Caption = Format(lblGross.Caption, "standard") |cmdClear.Visible = False |

|lblFwt.Caption = Format(lblFwt.Caption, "standard") |cmdExit.Visible = False |

|lblFica.Caption = Format(lblFica.Caption, "standard") |PrintForm |

|lblState.Caption = Format(lblState.Caption, "standard") |cmdCalc.Visible = True |

|lblNet.Caption = Format(lblNet.Caption, "standard") |cmdPrint.Visible = True |

|cmdPrint.SetFocus |cmdClear.Visible = True |

|End Sub |cmdExit.Visible = True |

| |cmdClear.SetFocus |

|Private Sub cmdClear_Click() |End Sub |

|txtName.Text = "" | |

|txtHours.Text = "" | |

|txtRate.Text = "" | |

|lblGross.Caption = "" | |

|lblFwt.Caption = "" | |

|lblFica.Caption = "" | |

|lblState.Caption = "" | |

|lblNet.Caption = "" | |

|txtName.SetFocus | |

|End Sub | |

12. (Discovery) lc12Done project – In this project, the TabStop property for the txtState control has been set to False. The TabStop property returns or sets a value indicating whether a user can use the Tab key to give the focus to an object. In this application, most of the customers are in the state of Illinois, so setting the txtState control’s TabStop property value to False ensures that the State control will not receive the focus while the user is tabbing to enter an order. Should the user want to change the State value, he or she will need to use the mouse to click the control.

13. (Discovery) lc13Done project – The student should submit a TOE chart (ordered by object), pseudocode, a printout of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the number of full boxes and the number remaining |cmdCalc |Click |

|Display the number of full boxes and the number remaining in | | |

|the lblFull and lblRemain controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the number of full boxes and the number remaining |lblFull, lblRemain |None |

|(from cmdCalc) | | |

|Get and display the inventory quantity and the number that can|txtQuantity, txtBoxAmt |None |

|be packed in a box | | |

Pseudocode:

cmdCalc: Calculate the number of full boxes = inventory quantity \ number that can be

packed in a box

Calculate the number remaining = inventory quantity Mod number that can be

packed in a box (Note: the student also could use the following

equation: inventory quantity – number of full boxes * number that can be packed in a box)

Display the number of full boxes in the lblFull control

Display the number remaining in the lblRemain control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtQuantity and txtBoxAmt controls

Clear the Caption property of the lblFull and lblRemain controls

Send the focus to the txtQuantity control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

[pic]

|VERSION 5.00 |Begin VB.Label Label5 |

|Begin VB.Form frmColfax |AutoSize = -1 'True |

|Caption = "Colfax Industries" |Caption = "Number remaining:" |

|ClientHeight = 2895 |Height = 195 |

|ClientLeft = 2625 |Left = 240 |

|ClientTop = 1950 |TabIndex = 11 |

|ClientWidth = 4770 |Top = 1560 |

|LinkTopic = "Form1" |Width = 1320 |

|LockControls = -1 'True |End |

|MaxButton = 0 'False |Begin VB.Label lblRemain |

|ScaleHeight = 2895 |Appearance = 0 'Flat |

|ScaleWidth = 4770 |BackColor = &H80000005& |

|Begin VB.TextBox txtBoxAmt |BackStyle = 0 'Transparent |

|Height = 285 |BorderStyle = 1 'Fixed Single |

|Left = 1680 |ForeColor = &H80000008& |

|TabIndex = 3 |Height = 255 |

|Top = 600 |Left = 1680 |

|Width = 975 |TabIndex = 10 |

|End |Top = 1560 |

|Begin mandButton cmdExit |Width = 975 |

|Caption = "E&xit" |End |

|Height = 495 |Begin VB.Label Label3 |

|Left = 3240 |AutoSize = -1 'True |

|TabIndex = 7 |Caption = "&Box quantity:" |

|Top = 2040 |Height = 195 |

|Width = 1215 |Left = 240 |

|End |TabIndex = 2 |

|Begin mandButton cmdClear |Top = 600 |

|Caption = "C&lear Screen" |Width = 915 |

|Height = 495 |End |

|Left = 3240 |Begin VB.Label lblFull |

|TabIndex = 6 |Appearance = 0 'Flat |

|Top = 1440 |BackColor = &H80000005& |

|Width = 1215 |BackStyle = 0 'Transparent |

|End |BorderStyle = 1 'Fixed Single |

|Begin mandButton cmdPrint |ForeColor = &H80000008& |

|Caption = "&Print" |Height = 255 |

|Height = 495 |Left = 1680 |

|Left = 3240 |TabIndex = 9 |

|TabIndex = 5 |Top = 1200 |

|Top = 840 |Width = 975 |

|Width = 1215 |End |

|End |Begin VB.Label Label2 |

|Begin mandButton cmdCalc |AutoSize = -1 'True |

|Caption = "&Calculate" |Caption = "Full boxes:" |

|Height = 495 |Height = 195 |

|Left = 3240 |Left = 240 |

|TabIndex = 4 |TabIndex = 8 |

|Top = 240 |Top = 1200 |

|Width = 1215 |Width = 750 |

|End |End |

|Begin VB.TextBox txtQuantity |Begin VB.Label Label1 |

|Height = 285 |AutoSize = -1 'True |

|Left = 1680 |Caption = "&Inventory quantity:" |

|TabIndex = 1 |Height = 195 |

|Top = 240 |Left = 240 |

|Width = 975 |TabIndex = 0 |

|End |Top = 240 |

| |Width = 1305 |

| |End |

| |End |

|Private Sub cmdClear_Click() |Private Sub cmdExit_Click() |

|txtQuantity.Text = "" |End |

|txtBoxAmt.Text = "" |End Sub |

|lblFull.Caption = "" | |

|lblRemain.Caption = "" |Private Sub cmdPrint_Click() |

|txtQuantity.SetFocus |cmdCalc.Visible = False |

|End Sub |cmdPrint.Visible = False |

| |cmdClear.Visible = False |

|Private Sub cmdCalc_Click() |cmdExit.Visible = False |

|lblFull.Caption = Val(txtQuantity.Text) \ Val(txtBoxAmt.Text) |PrintForm |

|lblRemain.Caption = Val(txtQuantity.Text) Mod Val(txtBoxAmt.Text) |cmdCalc.Visible = True |

|'Note: The student also could use the following equation: |cmdPrint.Visible = True |

|'lblRemain.Caption = Val(txtQuantity.Text) _ |cmdClear.Visible = True |

|- Val(lblFull.Caption) * Val(txtBoxAmt.Text) |cmdExit.Visible = True |

|cmdPrint.SetFocus |cmdClear.SetFocus |

|End Sub |End Sub |

14. (Discovery) lc14Done project – The student should submit a TOE chart (ordered by object), pseudocode, a printout of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the perimeter of a polygon |cmdCalc |Click |

|Display the perimeter in the lblPerimeter control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the perimeter (from cmdCalc) |lblPerimeter |None |

|Get and display the length of four sides of a polygon |txtSide1, txtSide2, txtSide3, |None |

| |txtSide4 | |

Pseudocode:

cmdCalc: Calculate the perimeter of a polygon = side 1 length + side 2 length + side 3

length + side 4 length

Display the perimeter in the lblPerimeter control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtSide1, txtSide2, txtSide3, txtSide4 controls

Clear the Caption property of the lblPerimeter control

Send the focus to the txtSide1 control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

[pic]

|VERSION 5.00 |Begin mandButton cmdClear |

|Begin VB.Form frmPerimeter |Caption = "C&lear Screen" |

|Caption = "Perimeter of a Polygon" |Height = 495 |

|ClientHeight = 2775 |Left = 2280 |

|ClientLeft = 2625 |TabIndex = 10 |

|ClientTop = 1950 |Top = 1440 |

|ClientWidth = 3780 |Width = 1215 |

|LinkTopic = "Form1" |End |

|LockControls = -1 'True |Begin mandButton cmdPrint |

|MaxButton = 0 'False |Caption = "&Print" |

|ScaleHeight = 2775 |Height = 495 |

|ScaleWidth = 3780 |Left = 2280 |

|Begin VB.TextBox txtSide3 |TabIndex = 9 |

|Height = 285 |Top = 840 |

|Left = 1080 |Width = 1215 |

|TabIndex = 5 |End |

|Top = 960 |Begin mandButton cmdCalc |

|Width = 495 |Caption = "&Calculate" |

|End |Height = 495 |

|Begin VB.TextBox txtSide4 |Left = 2280 |

|Height = 285 |TabIndex = 8 |

|Left = 1080 |Top = 240 |

|TabIndex = 7 |Width = 1215 |

|Top = 1320 |End |

|Width = 495 |Begin VB.TextBox txtSide1 |

|End |Height = 285 |

|Begin VB.TextBox txtSide2 |Left = 1080 |

|Height = 285 |TabIndex = 1 |

|Left = 1080 |Top = 240 |

|TabIndex = 3 |Width = 495 |

|Top = 600 |End |

|Width = 495 |Begin VB.Label Label6 |

|End |AutoSize = -1 'True |

|Begin mandButton cmdExit |Caption = "Side &3:" |

|Caption = "E&xit" |Height = 195 |

|Height = 495 |Left = 240 |

|Left = 2280 |TabIndex = 4 |

|TabIndex = 11 |Top = 960 |

|Top = 2040 |Width = 495 |

|Width = 1215 |End |

|End | |

|Begin VB.Label Label4 |Begin VB.Label Label2 |

|AutoSize = -1 'True |AutoSize = -1 'True |

|Caption = "Side &4:" |Caption = "Perimeter:" |

|Height = 195 |Height = 195 |

|Left = 240 |Left = 240 |

|TabIndex = 6 |TabIndex = 12 |

|Top = 1320 |Top = 1680 |

|Width = 495 |Width = 705 |

|End |End |

|Begin VB.Label Label3 |Begin VB.Label Label1 |

|AutoSize = -1 'True |AutoSize = -1 'True |

|Caption = "Side &2:" |Caption = "Side &1:" |

|Height = 195 |Height = 195 |

|Left = 240 |Left = 240 |

|TabIndex = 2 |TabIndex = 0 |

|Top = 600 |Top = 240 |

|Width = 495 |Width = 495 |

|End |End |

|Begin VB.Label lblPerimeter |End |

|Appearance = 0 'Flat | |

|BackColor = &H80000005& | |

|BackStyle = 0 'Transparent | |

|BorderStyle = 1 'Fixed Single | |

|ForeColor = &H80000008& | |

|Height = 255 | |

|Left = 1080 | |

|TabIndex = 13 | |

|Top = 1680 | |

|Width = 495 | |

|End | |

|Private Sub cmdClear_Click() |Pivate Sub cmdExit_Click() |

|txtSide1.Text = "" |End |

|txtSide2.Text = "" |End Sub |

|txtSide3.Text = "" | |

|txtSide4.Text = "" |Private Sub cmdPrint_Click() |

|lblPerimeter.Caption = "" |cmdCalc.Visible = False |

|txtSide1.SetFocus |cmdPrint.Visible = False |

|End Sub |cmdClear.Visible = False |

| |cmdExit.Visible = False |

|Private Sub cmdCalc_Click() |PrintForm |

|lblPerimeter.Caption = Val(txtSide1.Text) + Val(txtSide2.Text) _ |cmdCalc.Visible = True |

|+ Val(txtSide3.Text) + Val(txtSide4.Text) |cmdPrint.Visible = True |

|cmdPrint.SetFocus |cmdClear.Visible = True |

|End Sub |cmdExit.Visible = True |

| |cmdClear.SetFocus |

| |End Sub |

15. (Discovery) lc15Done project – The student should submit a TOE chart (ordered by object), pseudocode, a printout of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the circumference of a circle and the total price of|cmdCalc |Click |

|railing material | | |

|Display the circumference and the total price in the | | |

|lblCircumference and lblTotalPrice controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the circumference and the total price (from cmdCalc) |lblCircumference, lblTotalPrice|None |

|Get and display the diameter of a circle and the price per |txtDiameter, txtFootPrice |None |

|foot of railing material | | |

Pseudocode:

cmdCalc: Calculate the circumference of a circle = diameter of a circle * 3.14

Calculate the total price of railing material = circumference of a circle *

price per foot of railing material

Display the circumference in the lblCircumference control

Display the total price of railing material in the lblTotalPrice control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtDiameter and txtFootPrice controls

Clear the Caption property of the lblCircumference and lblTotalPrice controls

Send the focus to the txtDiameter control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

(The total price may not be formatted.)

[pic]

|VERSION 5.00 | Begin VB.TextBox txtDiameter |

|Begin VB.Form frmBuilders |Height = 285 |

|Caption = "Builders Inc." |Left = 1440 |

|ClientHeight = 2895 |TabIndex = 1 |

|ClientLeft = 2625 |Top = 240 |

|ClientTop = 1950 |Width = 855 |

|ClientWidth = 3990 |End |

|LinkTopic = "Form1" |Begin VB.Label Label5 |

|LockControls = -1 'True |AutoSize = -1 'True |

|MaxButton = 0 'False |Caption = "Total price:" |

|ScaleHeight = 2895 |Height = 195 |

|ScaleWidth = 3990 |Left = 240 |

|Begin VB.TextBox txtFootPrice |TabIndex = 11 |

|Height = 285 |Top = 1560 |

|Left = 1440 |Width = 795 |

|TabIndex = 3 |End |

|Top = 600 |Begin VB.Label lblTotalPrice |

|Width = 855 |Appearance = 0 'Flat |

|End |BackColor = &H80000005& |

|Begin mandButton cmdExit |BackStyle = 0 'Transparent |

|Caption = "E&xit" |BorderStyle = 1 'Fixed Single |

|Height = 495 |ForeColor = &H80000008& |

|Left = 2520 |Height = 255 |

|TabIndex = 7 |Left = 1440 |

|Top = 2040 |TabIndex = 10 |

|Width = 1215 |Top = 1560 |

|End |Width = 855 |

|Begin mandButton cmdClear |End |

|Caption = "C&lear Screen" |Begin VB.Label Label3 |

|Height = 495 |AutoSize = -1 'True |

|Left = 2520 |Caption = "Price per &foot:" |

|TabIndex = 6 |Height = 195 |

|Top = 1440 |Left = 240 |

|Width = 1215 |TabIndex = 2 |

|End |Top = 600 |

|Begin mandButton cmdPrint |Width = 990 |

|Caption = "&Print" |End |

|Height = 495 |Begin VB.Label lblCircumference |

|Left = 2520 |Appearance = 0 'Flat |

|TabIndex = 5 |BackColor = &H80000005& |

|Top = 840 |BackStyle = 0 'Transparent |

|Width = 1215 |BorderStyle = 1 'Fixed Single |

|End |ForeColor = &H80000008& |

|Begin mandButton cmdCalc |Height = 255 |

|Caption = "&Calculate" |Left = 1440 |

|Height = 495 |TabIndex = 9 |

|Left = 2520 |Top = 1200 |

|TabIndex = 4 |Width = 855 |

|Top = 240 |End |

|Width = 1215 | |

|End | |

|Begin VB.Label Label2 |Begin VB.Label Label1 |

|AutoSize = -1 'True |AutoSize = -1 'True |

|Caption = "Circumference:" |Caption = "&Diameter:" |

|Height = 195 |Height = 195 |

|Left = 240 |Left = 240 |

|TabIndex = 8 |TabIndex = 0 |

|Top = 1200 |Top = 240 |

|Width = 1065 |Width = 675 |

|End |End |

| |End |

|Private Sub cmdClear_Click() |Private Sub cmdExit_Click() |

|txtDiameter.Text = "" |End |

|txtFootPrice.Text = "" |End Sub |

|lblCircumference.Caption = "" | |

|lblTotalPrice.Caption = "" |Private Sub cmdPrint_Click() |

|txtDiameter.SetFocus |cmdCalc.Visible = False |

|End Sub |cmdPrint.Visible = False |

| |cmdClear.Visible = False |

|Private Sub cmdCalc_Click() |cmdExit.Visible = False |

|lblCircumference.Caption = Val(txtDiameter.Text) * 3.14 |PrintForm |

|lblTotalPrice.Caption = Val(lblCircumference.Caption) _ |cmdCalc.Visible = True |

|* Val(txtFootPrice.Text) |cmdPrint.Visible = True |

|lblTotalPrice.Caption = Format(lblTotalPrice.Caption, "currency") |cmdClear.Visible = True |

|cmdPrint.SetFocus |cmdExit.Visible = True |

|End Sub |cmdClear.SetFocus |

| |End Sub |

16. (Discovery) lc16Done project – The student should submit a TOE chart (ordered by object), pseudocode, three printouts of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the number of weeks, days, and hours worked |cmdCalc |Click |

|Display the number of weeks, days, and hours worked in the | | |

|lblWeeks, lblDays, and lblHours controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the number of weeks, days, and hours worked (from |lblWeeks, lblDays, lblHours |None |

|cmdCalc) | | |

|Get and display the number of hours |txtHours |None |

Pseudocode:

cmdCalc: Calculate the number of weeks worked = number of hours \ 40

Calculate the number of days worked = (number of hours mod 40) \ 8

Calculate the number of hours worked = number of hours mod 40 mod 8

Display the number of weeks worked in the lblWeeks control

Display the number of days worked in the lblDays control

Display the number of hours worked in the lblHours control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtHours control

Clear the Caption property of the lblWeeks, lblDays, and lblHours controls

Send the focus to the txtHours control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

Printout # 1: Printout # 2: Printout # 3:

[pic] [pic] [pic]

|VERSION 5.00 |Begin VB.Label lblWeeks |

|Begin VB.Form frmTemp |Appearance = 0 'Flat |

|Caption = "Temp Employers" |BackColor = &H80000005& |

|ClientHeight = 2820 |BackStyle = 0 'Transparent |

|ClientLeft = 2625 |BorderStyle = 1 'Fixed Single |

|ClientTop = 1950 |ForeColor = &H80000008& |

|ClientWidth = 3990 |Height = 255 |

|LinkTopic = "Form1" |Left = 720 |

|LockControls = -1 'True |TabIndex = 11 |

|MaxButton = 0 'False |Top = 360 |

|ScaleHeight = 2820 |Width = 615 |

|ScaleWidth = 3990 |End |

|Begin VB.Frame Frame1 |Begin VB.Label Label2 |

|Caption = "Worked" |AutoSize = -1 'True |

|Height = 1575 |Caption = "Days:" |

|Left = 240 |Height = 195 |

|TabIndex = 6 |Left = 120 |

|Top = 960 |TabIndex = 10 |

|Width = 1575 |Top = 720 |

|Begin VB.Label Label4 |Width = 405 |

|AutoSize = -1 'True |End |

|Caption = "Weeks:" |Begin VB.Label lblDays |

|Height = 195 |Appearance = 0 'Flat |

|Left = 120 |BackColor = &H80000005& |

|TabIndex = 12 |BackStyle = 0 'Transparent |

|Top = 360 |BorderStyle = 1 'Fixed Single |

|Width = 555 |ForeColor = &H80000008& |

|End |Height = 255 |

| |Left = 720 |

| |TabIndex = 9 |

| |Top = 720 |

| |Width = 615 |

| |End |

|Begin VB.Label lblHours |Begin mandButton cmdPrint |

|Appearance = 0 'Flat |Caption = "&Print" |

|BackColor = &H80000005& |Height = 495 |

|BackStyle = 0 'Transparent |Left = 2520 |

|BorderStyle = 1 'Fixed Single |TabIndex = 3 |

|ForeColor = &H80000008& |Top = 840 |

|Height = 255 |Width = 1215 |

|Left = 720 |End |

|TabIndex = 8 |Begin mandButton cmdCalc |

|Top = 1080 |Caption = "&Calculate" |

|Width = 615 |Height = 495 |

|End |Left = 2520 |

|Begin VB.Label Label5 |TabIndex = 2 |

|AutoSize = -1 'True |Top = 240 |

|Caption = "Hours:" |Width = 1215 |

|Height = 195 |End |

|Left = 120 |Begin VB.TextBox txtHours |

|TabIndex = 7 |Height = 285 |

|Top = 1080 |Left = 840 |

|Width = 465 |TabIndex = 1 |

|End |Top = 240 |

|End |Width = 615 |

|Begin mandButton cmdExit |End |

|Caption = "E&xit" |Begin VB.Label Label1 |

|Height = 495 |AutoSize = -1 'True |

|Left = 2520 |Caption = "&Hours:" |

|TabIndex = 5 |Height = 195 |

|Top = 2040 |Left = 240 |

|Width = 1215 |TabIndex = 0 |

|End |Top = 240 |

|Begin mandButton cmdClear |Width = 465 |

|Caption = "C&lear Screen" |End |

|Height = 495 |End |

|Left = 2520 | |

|TabIndex = 4 | |

|Top = 1440 | |

|Width = 1215 | |

|End | |

|Private Sub cmdClear_Click() |Private Sub cmdExit_Click() |

|txtHours.Text = "" |End |

|lblWeeks.Caption = "" |End Sub |

|lblDays.Caption = "" | |

|lblHours.Caption = "" |Private Sub cmdPrint_Click() |

|txtHours.SetFocus |cmdCalc.Visible = False |

|End Sub |cmdPrint.Visible = False |

| |cmdClear.Visible = False |

|Private Sub cmdCalc_Click() |cmdExit.Visible = False |

|lblWeeks.Caption = Val(txtHours.Text) \ 40 |PrintForm |

|lblDays.Caption = (Val(txtHours.Text) Mod 40) \ 8 |cmdCalc.Visible = True |

|lblHours.Caption = Val(txtHours.Text) Mod 40 Mod 8 |cmdPrint.Visible = True |

|cmdPrint.SetFocus |cmdClear.Visible = True |

|End Sub |cmdExit.Visible = True |

| |cmdClear.SetFocus |

| |End Sub |

17. (Discovery) lc17Done project – The student should submit a TOE chart (ordered by object), pseudocode, a printout of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the area of a rectangle and the total price of tile |cmdCalc |Click |

|Display the area and the total price in the lblArea and | | |

|lblTotalPrice controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the area and the total price (from cmdCalc) |lblArea, lblTotalPrice |None |

|Get and display the length of a rectangle, the width of a |txtLength, txtWidth, |None |

|rectangle, and the price per square foot of tile |txtFootPrice | |

Pseudocode:

cmdCalc: Calculate the area of a rectangle = length of rectangle * width of rectangle

Calculate the total price of tile = area of a rectangle * price per square foot of tile

Display the area in the lblArea control

Display the total price of tile in the lblTotalPrice control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtLength, txtWidth, and txtFootPrice controls

Clear the Caption property of the lblArea and lblTotalPrice controls

Send the focus to the txtLength control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

(The total price may not be formatted.)

[pic]

|VERSION 5.00 | Begin VB.Label Label5 |

|Begin VB.Form frmTile |AutoSize = -1 'True |

|Caption = "Tile Limited" |Caption = "Total price:" |

|ClientHeight = 2895 |Height = 195 |

|ClientLeft = 2625 |Left = 240 |

|ClientTop = 1950 |TabIndex = 11 |

|ClientWidth = 4260 |Top = 720 |

|LinkTopic = "Form1" |Width = 795 |

|LockControls = -1 'True |End |

|MaxButton = 0 'False |End |

|ScaleHeight = 2895 |Begin VB.TextBox txtFootPrice |

|ScaleWidth = 4260 |Height = 285 |

|Begin VB.Frame Frame1 |Left = 1680 |

|Height = 1335 |TabIndex = 5 |

|Left = 240 |Top = 960 |

|TabIndex = 10 |Width = 855 |

|Top = 1320 |End |

|Width = 2295 |Begin VB.TextBox txtWidth |

|Begin VB.Label Label2 |Height = 285 |

|AutoSize = -1 'True |Left = 1680 |

|Caption = "Area:" |TabIndex = 3 |

|Height = 195 |Top = 600 |

|Left = 240 |Width = 855 |

|TabIndex = 14 |End |

|Top = 360 |Begin mandButton cmdExit |

|Width = 375 |Caption = "E&xit" |

|End |Height = 495 |

|Begin VB.Label lblArea |Left = 2760 |

|Appearance = 0 'Flat |TabIndex = 9 |

|BackColor = &H80000005& |Top = 2040 |

|BackStyle = 0 'Transparent |Width = 1215 |

|BorderStyle = 1 'Fixed Single |End |

|ForeColor = &H80000008& |Begin mandButton cmdClear |

|Height = 255 |Caption = "Clear &Screen" |

|Left = 1080 |Height = 495 |

|TabIndex = 13 |Left = 2760 |

|Top = 360 |TabIndex = 8 |

|Width = 735 |Top = 1440 |

|End |Width = 1215 |

|Begin VB.Label lblTotalPrice |End |

|Appearance = 0 'Flat |Begin mandButton cmdPrint |

|BackColor = &H80000005& |Caption = "&Print" |

|BackStyle = 0 'Transparent |Height = 495 |

|BorderStyle = 1 'Fixed Single |Left = 2760 |

|ForeColor = &H80000008& |TabIndex = 7 |

|Height = 255 |Top = 840 |

|Left = 1080 |Width = 1215 |

|TabIndex = 12 |End |

|Top = 720 |Begin mandButton cmdCalc |

|Width = 735 |Caption = "&Calculate" |

|End |Height = 495 |

| |Left = 2760 |

| |TabIndex = 6 |

| |Top = 240 |

| |Width = 1215 |

| |End |

|Begin VB.TextBox txtLength |Begin VB.Label Label3 |

|Height = 285 |AutoSize = -1 'True |

|Left = 1680 |Caption = "&Width in feet:" |

|TabIndex = 1 |Height = 195 |

|Top = 240 |Left = 240 |

|Width = 855 |TabIndex = 2 |

|End |Top = 600 |

|Begin VB.Label Label4 |Width = 945 |

|AutoSize = -1 'True |End |

|Caption = "&Tile price/sq. foot:" |Begin VB.Label Label1 |

|Height = 195 |AutoSize = -1 'True |

|Left = 240 |Caption = "&Length in feet:" |

|TabIndex = 4 |Height = 195 |

|Top = 960 |Left = 240 |

|Width = 1290 |TabIndex = 0 |

|End |Top = 240 |

| |Width = 1020 |

| |End |

| |End |

|Private Sub cmdClear_Click() |Private Sub cmdExit_Click() |

|txtLength.Text = "" |End |

|txtWidth.Text = "" |End Sub |

|txtFootPrice.Text = "" | |

|lblArea.Caption = "" |Private Sub cmdPrint_Click() |

|lblTotalPrice.Caption = "" |cmdCalc.Visible = False |

|txtLength.SetFocus |cmdPrint.Visible = False |

|End Sub |cmdClear.Visible = False |

| |cmdExit.Visible = False |

|Private Sub cmdCalc_Click() |PrintForm |

|lblArea.Caption = Val(txtLength.Text) * Val(txtWidth.Text) |cmdCalc.Visible = True |

|lblTotalPrice.Caption = Val(lblArea.Caption) _ |cmdPrint.Visible = True |

|* Val(txtFootPrice.Text) |cmdClear.Visible = True |

|lblTotalPrice.Caption = Format(lblTotalPrice.Caption, "currency") |cmdExit.Visible = True |

|cmdPrint.SetFocus |cmdClear.SetFocus |

|End Sub |End Sub |

18. (Discovery) lc18Done project – The student should submit a TOE chart (ordered by object), pseudocode, a printout of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the volume of a rectangle |cmdCalc |Click |

|Display the volume in the lblVolume control | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the volume (from cmdCalc) |lblVolume |None |

|Get and display the length of a rectangle, the width of a |txtLength, txtWidth, txtHeight |None |

|rectangle, and the height of a rectangle | | |

Pseudocode:

cmdCalc: Calculate the volume of a rectangle = length of rectangle * width of rectangle *

height of rectangle

Display the volume in the lblVolume control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtLength, txtWidth, and txtHeight controls

Clear the Caption property of the lblVolume control

Send the focus to the txtLength control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

[pic]

|VERSION 5.00 |Begin mandButton cmdClear |

|Begin VB.Form frmWillow |Caption = "Clear &Screen" |

|Caption = "Willow Pools" |Height = 495 |

|ClientHeight = 2895 |Left = 2760 |

|ClientLeft = 2625 |TabIndex = 8 |

|ClientTop = 1950 |Top = 1440 |

|ClientWidth = 4260 |Width = 1215 |

|LinkTopic = "Form1" |End |

|LockControls = -1 'True |Begin mandButton cmdPrint |

|MaxButton = 0 'False |Caption = "&Print" |

|ScaleHeight = 2895 |Height = 495 |

|ScaleWidth = 4260 |Left = 2760 |

|Begin VB.TextBox txtHeight |TabIndex = 7 |

|Height = 285 |Top = 840 |

|Left = 1320 |Width = 1215 |

|TabIndex = 5 |End |

|Top = 960 |Begin mandButton cmdCalc |

|Width = 855 |Caption = "&Calculate" |

|End |Height = 495 |

|Begin VB.TextBox txtWidth |Left = 2760 |

|Height = 285 |TabIndex = 6 |

|Left = 1320 |Top = 240 |

|TabIndex = 3 |Width = 1215 |

|Top = 600 |End |

|Width = 855 |Begin VB.TextBox txtLength |

|End |Height = 285 |

|Begin mandButton cmdExit |Left = 1320 |

|Caption = "E&xit" |TabIndex = 1 |

|Height = 495 |Top = 240 |

|Left = 2760 |Width = 855 |

|TabIndex = 9 |End |

|Top = 2040 | |

|Width = 1215 | |

|End | |

|Begin VB.Label lblVolume |Begin VB.Label Label3 |

|Appearance = 0 'Flat |AutoSize = -1 'True |

|BackColor = &H80000005& |Caption = "&Width in feet:" |

|BackStyle = 0 'Transparent |Height = 195 |

|BorderStyle = 1 'Fixed Single |Left = 240 |

|ForeColor = &H80000008& |TabIndex = 2 |

|Height = 255 |Top = 600 |

|Left = 1320 |Width = 945 |

|TabIndex = 11 |End |

|Top = 1320 |Begin VB.Label Label1 |

|Width = 855 |AutoSize = -1 'True |

|End |Caption = "&Length in feet:" |

|Begin VB.Label Label2 |Height = 195 |

|AutoSize = -1 'True |Left = 240 |

|Caption = "Volume:" |TabIndex = 0 |

|Height = 195 |Top = 240 |

|Left = 240 |Width = 1020 |

|TabIndex = 10 |End |

|Top = 1320 |End |

|Width = 570 | |

|End | |

|Begin VB.Label Label4 | |

|AutoSize = -1 'True | |

|Caption = "&Height in feet:" | |

|Height = 195 | |

|Left = 240 | |

|TabIndex = 4 | |

|Top = 960 | |

|Width = 990 | |

|End | |

|Private Sub cmdClear_Click() |Private Sub cmdExit_Click() |

|txtLength.Text = "" |End |

|txtWidth.Text = "" |End Sub |

|txtHeight.Text = "" | |

|lblVolume.Caption = "" |Private Sub cmdPrint_Click() |

|txtLength.SetFocus |cmdCalc.Visible = False |

|End Sub |cmdPrint.Visible = False |

| |cmdClear.Visible = False |

|Private Sub cmdCalc_Click() |cmdExit.Visible = False |

|lblVolume.Caption = Val(txtLength.Text) _ |PrintForm |

|* Val(txtWidth.Text) * Val(txtHeight.Text) |cmdCalc.Visible = True |

|cmdPrint.SetFocus |cmdPrint.Visible = True |

|End Sub |cmdClear.Visible = True |

| |cmdExit.Visible = True |

| |cmdClear.SetFocus |

| |End Sub |

19. (Discovery) lc19Done project – The student should submit a TOE chart (ordered by object), pseudocode, a printout of the form with the test data showing, the Form As Text, and the code. The design of the interface will vary.

|Task |Object |Event |

|Calculate the total amount of interest and the total amount |cmdCalc |Click |

|repaid | | |

|Display the interest and repaid amounts in the lblInterest and| | |

|lblRepaid controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the interest and repaid amounts (from cmdCalc) |lblInterest, lblRepaid |None |

|Get and display the loan amount, the interest rate, and the |txtLoan, txtRate, txtTerm |None |

|term | | |

Pseudocode:

cmdCalc: Calculate the total amount repaid = -(term * 12 * pmt(rate/12, term * 12, loan

amount, 0, 0))

Calculate the total amount of interest = total amount repaid – loan amount

Display the total amount repaid in the lblRepaid control

Display the total amount of interest in the lblInterest control

Send the focus to the Print button

cmdClear: Clear the Text property of the txtLoan, txtRate, and txtTerm controls

Clear the Caption property of the lblInterest and lblRepaid controls

Send the focus to the txtLoan control

cmdExit: End the application

cmdPrint Hide the command buttons

Print the form

Display the command buttons

Send the focus to the Clear Screen button

(The total interest and total repaid may not be formatted.)

[pic]

|VERSION 5.00 |Begin mandButton cmdPrint |

|Begin VB.Form frmQuick |Caption = "&Print" |

|Caption = "Quick Loans" |Height = 495 |

|ClientHeight = 2790 |Left = 2760 |

|ClientLeft = 2625 |TabIndex = 7 |

|ClientTop = 1950 |Top = 840 |

|ClientWidth = 4260 |Width = 1215 |

|LinkTopic = "Form1" |End |

|LockControls = -1 'True |Begin mandButton cmdCalc |

|MaxButton = 0 'False |Caption = "&Calculate" |

|ScaleHeight = 2790 |Height = 495 |

|ScaleWidth = 4260 |Left = 2760 |

|Begin VB.TextBox txtTerm |TabIndex = 6 |

|Height = 285 |Top = 240 |

|Left = 1320 |Width = 1215 |

|TabIndex = 5 |End |

|Top = 960 |Begin VB.TextBox txtLoan |

|Width = 855 |Height = 285 |

|End |Left = 1320 |

|Begin VB.TextBox txtRate |TabIndex = 1 |

|Height = 285 |Top = 240 |

|Left = 1320 |Width = 855 |

|TabIndex = 3 |End |

|Top = 600 |Begin VB.Label Label6 |

|Width = 855 |AutoSize = -1 'True |

|End |Caption = "Total repaid:" |

|Begin mandButton cmdExit |Height = 195 |

|Caption = "E&xit" |Left = 240 |

|Height = 495 |TabIndex = 13 |

|Left = 2760 |Top = 1680 |

|TabIndex = 9 |Width = 885 |

|Top = 2040 |End |

|Width = 1215 |Begin VB.Label lblRepaid |

|End |Appearance = 0 'Flat |

|Begin mandButton cmdClear |BackColor = &H80000005& |

|Caption = "Clear &Screen" |BackStyle = 0 'Transparent |

|Height = 495 |BorderStyle = 1 'Fixed Single |

|Left = 2760 |ForeColor = &H80000008& |

|TabIndex = 8 |Height = 255 |

|Top = 1440 |Left = 1320 |

|Width = 1215 |TabIndex = 12 |

|End |Top = 1680 |

| |Width = 855 |

| |End |

|Begin VB.Label lblInterest |Begin VB.Label Label4 |

|Appearance = 0 'Flat |AutoSize = -1 'True |

|BackColor = &H80000005& |Caption = "&Term (years):" |

|BackStyle = 0 'Transparent |Height = 195 |

|BorderStyle = 1 'Fixed Single |Left = 240 |

|ForeColor = &H80000008& |TabIndex = 4 |

|Height = 255 |Top = 960 |

|Left = 1320 |Width = 915 |

|TabIndex = 11 |End |

|Top = 1320 |Begin VB.Label Label3 |

|Width = 855 |AutoSize = -1 'True |

|End |Caption = "&Interest rate:" |

|Begin VB.Label Label2 |Height = 195 |

|AutoSize = -1 'True |Left = 240 |

|Caption = "Total interest:" |TabIndex = 2 |

|Height = 195 |Top = 600 |

|Left = 240 |Width = 885 |

|TabIndex = 10 |End |

|Top = 1320 |Begin VB.Label Label1 |

|Width = 960 |AutoSize = -1 'True |

|End |Caption = "&Loan amount:" |

| |Height = 195 |

| |Left = 240 |

| |TabIndex = 0 |

| |Top = 240 |

| |Width = 975 |

| |End |

| |End |

|Private Sub cmdClear_Click() |Private Sub cmdExit_Click() |

|txtLoan.Text = "" |End |

|txtRate.Text = "" |End Sub |

|txtTerm.Text = "" | |

|lblInterest.Caption = "" |Private Sub cmdPrint_Click() |

|lblRepaid.Caption = "" |cmdCalc.Visible = False |

|txtLoan.SetFocus |cmdPrint.Visible = False |

|End Sub |cmdClear.Visible = False |

| |cmdExit.Visible = False |

|Private Sub cmdCalc_Click() |PrintForm |

|lblRepaid.Caption = -(Val(txtTerm.Text) * 12 _ |cmdCalc.Visible = True |

|* Pmt(Val(txtRate.Text) / 12, Val(txtTerm.Text) * 12, _ |cmdPrint.Visible = True |

|Val(txtLoan.Text), 0, 0)) |cmdClear.Visible = True |

|lblInterest.Caption = Val(lblRepaid.Caption) – Val(txtLoan.Text) |cmdExit.Visible = True |

|lblInterest.Caption = Format(lblInterest.Caption, "standard") |cmdClear.SetFocus |

|lblRepaid.Caption = Format(lblRepaid.Caption, "standard") |End Sub |

|cmdPrint.SetFocus | |

|End Sub | |

Tutorial 2 – Debugging

Technique

You should use the Val function in equations to tell Visual Basic to treat the Text property and the Caption property as numbers rather than as strings.

Tutorial 3, Lesson A

Questions

d Variables

e All of the above

1. b Integer

2. e Variant

3. c Local

4. a literal constant

5. e variable

6. c symbolic constant

7. d Variant

8. a True

Exercises

1. Dim strName as String

Dim sngPrice as Single (or curPrice as Currency)

2. Dim strName as String

Dim sngHeight as Single

Dim intWeight as Integer

3. Dim strName as String, intBegin as Integer, intPurchase as Integer

Dim intSold as Integer, intEnd as Integer

4. Dim strCity as String, lngPopulation as Long

5. Dim strPart as String, sngCost as Single (or curCost as Currency)

6. Public strName as String

7. Public intAge as Integer

8. strCity = “Miami”

9. strPartno = “AB103”

10. strName = “Desk”

intInStock = 40

intOnorder = 20

11. curTotalsales = curReg1sales + curReg2sales

12. curSalary = curSalary * 1.5

13. Dim strEmpName as String

Enter the Dim statement in the form’s General declarations section. The variable is form-level.

14. Dim curWestsales as Currency

Enter the Dim statement in the cmdWest button’s Click event. The variable is local.

Dim curSouthsales as Currency

Enter the Dim statement in the cmdSouth button’s Click event. The variable is local.

Dim curCompany as Currency

Enter the Dim statement in the form’s General declarations section. The variable is form-level.

15. Public strEmployee as String

Enter the Public statement in a code module’s General declarations section. The variable is global.

16. Dim strState as String

Enter the Dim statement in the frmRate form’s General declarations section. The variable is form-level.

Dim curStateTax as Currency

Enter the Dim statement in the cmdCalc button’s Click event. The variable is local.

Public sngStateRate as Single

Enter the Public statement in a code module’s General declarations section. The variable is global.

17. Const conTaxRate as Single = .05

18. Const conAge as Integer = 21

You can enter the Const statement in the form’s General declarations section, which makes it form-level. If it is possible that the constant for one of the two procedures may differ from the other in the future, then place a Const statement in each of the event procedures, which will make each constant local.

19. Public Const conMessage as String = “Welcome!”

Enter the Public Const statement in a code module’s General declarations section. The constant is global.

20. (Discovery) Response to step k: When you declare a local variable with the Dim statement, the variable retains its value until the event procedure ends, at which time the variable is removed from memory. When you declare a local variable with the Static statement, the variable retains its value until the application ends, at which time it is removed from memory.

Tutorial 3, Lesson B

Questions

1. e all of the above

2. d &

3. a lblRegion.Caption = strReg1 & strReg2

4. d lblAddress.Caption = strCity & “, “ & strState

5. d vbNewLine

6. b Default

7. d Object Browser

8. d sngNum = Val(InputBox(“Enter a number:”, “Number”))

9. c strCity = InputBox(“Enter the city:”, “City”)

Exercises

1. lb1Done project – The student should submit a printout of the interface and the code.

[pic]

|Option Explicit |Private Sub cmdExit_Click() |

| |End |

|Private Sub cmdCalc_Click() |End Sub |

|Dim sngSales As Single, sngComm As Single | |

|sngSales = Val(txtSales.Text) |Private Sub cmdPrint_Click() |

|sngComm = sngSales * 0.1 |PrintForm |

|lblComm.Caption = Format(sngComm, "currency") |txtName.SetFocus |

|cmdPrint.SetFocus |End Sub |

|End Sub | |

2. lb2Done project – The student should submit a printout of the interface and the code.

[pic]

|Option Explicit |Private Sub cmdSqRoot_Click() |

| |Dim intNumber As Integer, sngSqRt As Single |

|Private Sub cmdExit_Click() |intNumber = Val(txtNumber.Text) |

|End |sngSqRt = Sqr(intNumber) |

|End Sub |lblSqRoot.Caption = sngSqRt |

| |End Sub |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|End Sub | |

3. lb3Done project – The student should submit two printouts of the interface and two printouts of the code.

[pic]

|Option Explicit |Private Sub cmdClear_Click() |

| |txtFlorida.Text = "" |

|Private Sub cmdCalc_Click() |txtMaine.Text = "" |

|Dim sngNY As Single, sngMaine As Single, sngFla As Single |txtNewYork.Text = "" |

|Dim sngTotal As Single, sngComm As Single |lblTsales.Caption = "" |

|sngNY = Val(txtNewYork.Text) |lblComm.Caption = "" |

|sngMaine = Val(txtMaine.Text) |txtNewYork.SetFocus |

|sngFla = Val(txtFlorida.Text) |End Sub |

|sngTotal = sngNY + sngMaine + sngFla | |

|sngComm = sngTotal * 0.05 |Private Sub cmdExit_Click() |

|lblTsales.Caption = Format(sngTotal, "standard") |End |

|lblComm.Caption = Format(sngComm, "standard") |End Sub |

|cmdPrint.SetFocus | |

|End Sub |Private Sub cmdPrint_Click() |

| |PrintForm |

| |cmdClear.SetFocus |

| |End Sub |

[pic]

|Option Explicit | |

| | |

|Private Sub cmdCalc_Click() | |

|Dim sngNY As Single, sngMaine As Single, sngFla As Single | |

|Dim sngTotal As Single, sngComm As Single, sngRate As Single | |

|sngRate = Val(InputBox("Enter the commission rate:", "Commission Rate")) | |

|sngNY = Val(txtNewYork.Text) | |

|sngMaine = Val(txtMaine.Text) | |

|sngFla = Val(txtFlorida.Text) | |

|sngTotal = sngNY + sngMaine + sngFla | |

|sngComm = sngTotal * sngRate | |

|lblTsales.Caption = Format(sngTotal, "standard") | |

|lblComm.Caption = Format(sngComm, "standard") | |

|cmdPrint.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdClear_Click() | |

|txtFlorida.Text = "" | |

|txtMaine.Text = "" | |

|txtNewYork.Text = "" | |

|lblTsales.Caption = "" | |

|lblComm.Caption = "" | |

|txtNewYork.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|cmdClear.SetFocus | |

|End Sub | |

4. lb4Done and lb4Done2 projects – The student should submit two printouts of the interface and two printouts of the code.

[pic]

|Option Explicit | |

|Dim sngRaiseRate As Single | |

| | |

|Private Sub cmdCalc_Click() | |

|Const conMsg As String = "Raise percentage: " | |

|Dim sngOldPay1 As Single, sngOldPay2 As Single, sngOldPay3 As Single | |

|Dim sngNewPay1 As Single, sngNewPay2 As Single, sngNewPay3 As Single | |

|sngOldPay1 = Val(txtCurrent1.Text) | |

|sngOldPay2 = Val(txtCurrent2.Text) | |

|sngOldPay3 = Val(txtCurrent3.Text) | |

|sngNewPay1 = sngOldPay1 * sngRaiseRate + sngOldPay1 | |

|sngNewPay2 = sngOldPay2 * sngRaiseRate + sngOldPay2 | |

|sngNewPay3 = sngOldPay3 * sngRaiseRate + sngOldPay3 | |

|lblNew1.Caption = Format(sngNewPay1, "standard") | |

|lblNew2.Caption = Format(sngNewPay2, "standard") | |

|lblNew3.Caption = Format(sngNewPay3, "standard") | |

|lblMsg.Caption = conMsg & Format(sngRaiseRate, "percent") | |

|cmdPrint.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|txtCurrent1.SetFocus | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|sngRaiseRate = Val(InputBox("Enter the raise rate:", "Raise Rate")) | |

|End Sub | |

[pic]

|Option Explicit | |

| | |

|Private Sub cmdCalc_Click() | |

|Const conMsg1 As String = "Job Code 1: " | |

|Const conMsg2 As String = "Job Code 2: " | |

|Const conMsg3 As String = "Job Code 3: " | |

|Dim sngOldPay1 As Single, sngOldPay2 As Single, sngOldPay3 As Single | |

|Dim sngNewPay1 As Single, sngNewPay2 As Single, sngNewPay3 As Single | |

|Dim sngRate1 As Single, sngRate2 As Single, sngRate3 As Single | |

|sngRate1 = Val(InputBox("Enter the first raise rate:", "Raise Rate")) | |

|sngRate2 = Val(InputBox("Enter the second raise rate:", "Raise Rate")) | |

|sngRate3 = Val(InputBox("Enter the third raise rate:", "Raise Rate")) | |

|sngOldPay1 = Val(txtCurrent1.Text) | |

|sngOldPay2 = Val(txtCurrent2.Text) | |

|sngOldPay3 = Val(txtCurrent3.Text) | |

|sngNewPay1 = sngOldPay1 * sngRate1 + sngOldPay1 | |

|sngNewPay2 = sngOldPay2 * sngRate2 + sngOldPay2 | |

|sngNewPay3 = sngOldPay3 * sngRate3 + sngOldPay3 | |

|txtCurrent1.Text = Format(sngOldPay1, "standard") | |

|txtCurrent2.Text = Format(sngOldPay2, "standard") | |

|txtCurrent3.Text = Format(sngOldPay3, "standard") | |

|lblNew1.Caption = Format(sngNewPay1, "standard") | |

|lblNew2.Caption = Format(sngNewPay2, "standard") | |

|lblNew3.Caption = Format(sngNewPay3, "standard") | |

|lblMsg.Caption = conMsg1 & Format(sngRate1, "percent") & vbNewLine _ | |

|& conMsg2 & Format(sngRate2, "percent") & vbNewLine _ | |

|& conMsg3 & Format(sngRate3, "percent") | |

|cmdPrint.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|txtCurrent1.SetFocus | |

|End Sub | |

5. lblAddress.Caption = strCity & “, “ & strState

6. lblAddress.Caption = conMessage & “ “ & strState & “ is “ & strCity & “.”

7. lblAddress.Caption = “My zip code is “ & strZip & “.”

8. (Discovery) In this exercise, the student learns about the Cancel property of a command button. The student is not instructed to submit anything for this exercise.

9. (Discovery) The name of the intrinsic constant that can be used to change the mouse pointer to an hourglass is vbHourglass. The name of the intrinsic constant that can be used to change a form’s BorderStyle property to fixed-single is vbFixedSingle.

Tutorial 3, Lesson C

Questions

1. c Add Form

2. e the startup form

3. c Load statement

4. e Unload statement

5. d Show method

6. d Show method

7. b Hide method

8. b modeless form

9. a modal form

10. c either modal or modeless

11. b global

12. b, d Left, Top

13. c BorderStyle

14. d Timer

15. d MousePointer

Exercises

1. The Open Project dialog box is modal; you can’t move the focus into other areas of the Visual Basic application while this dialog box is displayed. The MSDN Library Visual Studio 6.0 window is modeless; you can move the focus into other areas of the Visual Basic application while the window is displayed.

2. lc2Done project – The student should submit a printout of the interface and the code.

[pic]

|lc2Done.frm |lc2Input.frm |

|Option Explicit |Option Explicit |

| | |

|Private Sub cmdExit_Click() |Private Sub cmdOK_Click() |

|End |strName = txtSperson.Text |

|End Sub |frmAward.Show |

| |Unload frmInput |

|Private Sub cmdPrint_Click() |End Sub |

|PrintForm | |

|End Sub |Private Sub Form_Load() |

| |frmInput.Left = (Screen.Width - |

|Private Sub Form_Load() |frmInput.Width) / 2 |

|frmAward.Left = (Screen.Width - frmAward.Width) / 2 | = (Screen.Height - |

| = (Screen.Height - frmAward.Height) / 2 |frmInput.Height) / 2 |

|Const conMsg As String = "The award goes to " |End Sub |

|lblMsg.Caption = conMsg & strName & "." | |

|End Sub |lc2Mod.bas |

| |Option Explicit |

| |Public strName As String |

lc3Done project – The student should submit a printout of the sales form’s interface with the test data showing, a printout of the rate form’s image, and the code.

[pic] [pic]

|lc3Done.frm | |

|Option Explicit | |

| | |

|Private Sub cmdOK_Click() | |

|sngNrate = Val(txtNrate.Text) | |

|sngSrate = Val(txtSrate.Text) | |

|sngErate = Val(txtErate.Text) | |

|sngWrate = Val(txtWrate.Text) | |

|frmRMsales.Show | |

|Unload frmRate | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmRate.Left = (Screen.Width – frmRate.Width) / 2 | |

| = (Screen.Height – frmRate.Height) / 2 | |

|End Sub | |

| | |

|lc3Sales.frm | |

|Option Explicit | |

| | |

|Private Sub cmdCalc_Click() | |

|Dim sngNcurrent As Single, sngScurrent As Single | |

|Dim sngEcurrent As Single, sngWcurrent As Single | |

|sngNcurrent = Val(txtNorth.Text) | |

|sngScurrent = Val(txtSouth.Text) | |

|sngEcurrent = Val(txtEast.Text) | |

|sngWcurrent = Val(txtWest.Text) | |

|lblNrate.Caption = Format(sngNrate, "percent") | |

|lblSrate.Caption = Format(sngSrate, "percent") | |

|lblErate.Caption = Format(sngErate, "percent") | |

|lblWrate.Caption = Format(sngWrate, "percent") | |

|lblNorth.Caption = Format(sngNcurrent + sngNcurrent * sngNrate, "standard") | |

|lblSouth.Caption = Format(sngScurrent + sngScurrent * sngSrate, "standard") | |

|lblEast.Caption = Format(sngEcurrent + sngEcurrent * sngErate, "standard") | |

|lblWest.Caption = Format(sngWcurrent + sngWcurrent * sngWrate, "standard") | |

|cmdPrint.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|txtNorth.SetFocus | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

| = (Screen.Height - frmRMsales.Height) / 2 | |

|frmRMsales.Left = (Screen.Width - frmRMsales.Width) / 2 | |

|End Sub | |

| | |

|lc3Mod.bas | |

|Option Explicit | |

|Public sngNrate As Single, sngSrate As Single | |

|Public sngErate As Single, sngWrate As Single | |

3. lc4Done project – The student should submit a TOE chart, sketch, pseudocode, two printouts with the test data showing, printouts of both form’s Form Image, and the code.

|Task |Object |Event |

|Show the frmMain form |frmName.cmdOk |Click |

|Unload the frmName form | | |

|Get and display the student’s name on the frmName form |frmName.txtName |None |

| | | |

|Display the student’s name in the lblName control on the frmMain form |frmMain |Load |

|Get a number from the user and display it in the frmMain.lblNumber |frmMain.cmdCalc |Click |

|control | | |

|Calculate the square and square root of the number | | |

|Display the number and the calculated amounts in the lblNumber, | | |

|lblSquare, and lblSqRoot controls on the frmMain form | | |

|End the application |frmMain.cmdExit |Click |

|Print the interface |frmMain.cmdPrint |Click |

|Display the student’s name on the frmMain form (from frmMain form’s Load|frmMain.lblName |None |

|event) | | |

|Display the number on the frmMain form (from cmdCalc) |frmMain.lblNumber |None |

|Display the square and square root (from cmdCalc) |frmMain.lblSquare, |None |

| |frmMain.lblSqRoot | |

Sketch: The student should submit a sketch of both the frmName and frmMain forms. The designs will vary.

Pseudocode for the name form:

OK button’s Click event: Assign student’s name to a global variable

Show the main form

Unload the name form

Pseudocode for the main form:

Square/Square Root button’s Click event:

Declare variables

Get a number from the user

Calculate the square and square root of the number

Display the number, square, and square root in label controls

Load event: Display the student’s name in the lblName control

Exit button’s Click event: End the application

Print button’s Click event: Print the form

Send the focus to the Square/Square Root button

Step e printouts:

[pic] [pic]

Step f printouts:

[pic] [pic]

|lc4Done.frm |lc4Mod.bas |

|Option Explicit |Option Explicit |

| |Public strName As String |

|Private Sub cmdCalc_Click() | |

|Dim sngNumber As Single | |

|sngNumber = Val(InputBox("Enter a number:", "Number")) |lc4Name.frm |

|lblNumber.Caption = sngNumber |Option Explicit |

|lblSquare.Caption = sngNumber ^ 2 | |

|lblSqRoot.Caption = Sqr(sngNumber) |Private Sub cmdOk_Click() |

|End Sub |strName = txtName.Text |

| |frmMain.Show |

|Private Sub cmdExit_Click() |Unload frmName |

|End |End Sub |

|End Sub | |

| |Private Sub Form_Load() |

|Private Sub cmdPrint_Click() |frmName.Left = (Screen.Width - frmName.Width) / |

|PrintForm |2 |

|cmdCalc.SetFocus | = (Screen.Height - frmName.Height) /|

|End Sub |2 |

| |End Sub |

|Private Sub Form_Load() | |

|frmMain.Left = (Screen.Width – frmMain.Width) / 2 | |

| = (Screen.Height – frmMain.Height) / 2 | |

|lblName.Caption = strName | |

|End Sub | |

4. lc5Done project – The student should submit a TOE chart, sketch, pseudocode, two printouts with the test data showing, and the code.

|Task |Object |Event |

|Calculate the number of dollars, quarters, dimes, nickels, and |cmdCalc |Click |

|pennies | | |

|Display the calculated amounts in the lblDollars, lblQuarters, | | |

|lblDimes, lblNickels, and lblPennies controls | | |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the number of dollars, quarters, dimes, nickels, and pennies|lblDollars, lblQuarters, |None |

|(from cmdCalc) |lblDimes, lblNickels, | |

| |lblPennies | |

|Get and display the number of pennies |txtPennies |None |

Sketch: The student should submit a sketch of the form. The design will vary.

Pseudocode:

Calculate button’s Click event: Declare variables

Assign value of txtPennies control to a variable

Calculate the number of dollars, quarters, dimes, nickels, and

pennies

Display the calculated amounts in the appropriate label

controls

Exit button’s Click event: End the application

Print button’s Click event: Print the form

Send the focus to the txtPennies control

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |Private Sub cmdPrint_Click() |

| |PrintForm |

|Private Sub cmdCalc_Click() |txtPennies.SetFocus |

|Dim intDollars As Integer, intQuarters As Integer |End Sub |

|Dim intDimes As Integer, intNickels As Integer | |

|Dim intPennies As Integer |Private Sub Form_Load() |

|'assign value to variable |frmJoe.Left = (Screen.Width – |

|intPennies = Val(txtPennies.Text) |frmJoe.Width) / 2 |

|intDollars = intPennies \ 100 'calculate dollars | = (Screen.Height – |

|intPennies = intPennies - intDollars * 100 |frmJoe.Height) / 2 |

|intQuarters = intPennies \ 25 'calculate quarters |End Sub |

|intPennies = intPennies - intQuarters * 25 | |

|intDimes = intPennies \ 10 'calculate dimes | |

|intPennies = intPennies - intDimes * 10 | |

|intNickels = intPennies \ 5 'calculate nickels | |

|intPennies = intPennies - intNickels * 5 'calculate pennies | |

|lblDollars.Caption = intDollars | |

|lblQuarters.Caption = intQuarters | |

|lblDimes.Caption = intDimes | |

|lblNickels.Caption = intNickels | |

|lblPennies.Caption = intPennies | |

|txtPennies.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

5. lc6Done project – The student should submit a TOE chart, sketch, pseudocode, three printouts with the test data showing, and the code.

|Task |Object |Event |

|Get the amount due and the amount paid |cmdCalc |Click |

|Calculate the change due, as well as the number of dollars, | | |

|quarters, dimes, nickels, and pennies to return to the customer | | |

|Display the amount due, amount paid, and the calculated amounts in | | |

|the lblDue, lblPaid, lblChange, lblDollars, lblQuarters, lblDimes, | | |

|lblNickels, and lblPennies controls | | |

|Clear the screen |cmdClear |Click |

|End the application |cmdExit |Click |

|Print the interface |cmdPrint |Click |

|Display the amount due, amount paid, change, as well as the number |lblDue, lblPaid, lblChange, |None |

|of dollars, quarters, dimes, nickels, and pennies (from cmdCalc) |lblDollars, lblQuarters, | |

| |lblDimes, lblNickels, | |

| |lblPennies | |

Sketch: The student should submit a sketch of the form. The design will vary.

Pseudocode:

Calculate button’s Click event: Declare variables

Get the amount due and the amount paid

Calculate the change due

Calculate the number of dollars, quarters, dimes, nickels, and

pennies to return to the customer

Display the amount due, amount paid, and the calculated

amounts in the appropriate label controls

Clear button’s Click event: Clear the Caption properties of the label controls

Send the focus to the Calculate Change button

Exit button’s Click event: End the application

Print button’s Click event: Print the form

Send the focus to the Clear Screen button

Printout #1: Printout #2:

[pic] [pic]

Printout #3:

[pic]

|Option Explicit | |

| | |

|Private Sub cmdCalc_Click() | |

|Dim sngDue As Single, sngPaid As Single | |

|Dim sngChange As Single, sngTemp As Single | |

|Dim intDollars As Integer, intQuarters As Integer | |

|Dim intDimes As Integer, intNickels As Integer, intPennies As Integer | |

|'get amount due and amount paid | |

|sngDue = Val(InputBox("Enter the amount due:", "Amount Due")) | |

|sngPaid = Val(InputBox("Enter the amount paid:", "Amount Paid")) | |

|sngChange = sngPaid - sngDue 'calculate change | |

|sngTemp = sngChange | |

|intDollars = (sngTemp * 100) \ 100 'calculate dollars | |

|sngTemp = sngTemp - intDollars | |

|intQuarters = sngTemp * 100 \ 25 'calculate quarters | |

|sngTemp = sngTemp - intQuarters * 0.25 | |

|intDimes = sngTemp * 100 \ 10 'calculate dimes | |

|sngTemp = sngTemp - intDimes * 0.1 | |

|intNickels = sngTemp * 100 \ 5 'calculate nickels | |

|sngTemp = sngTemp - intNickels * 0.05 'calculate pennies | |

|intPennies = sngTemp * 100 | |

|'display results | |

|lblPaid.Caption = Format(sngPaid, "currency") | |

|lblDue.Caption = Format(sngDue, "currency") | |

|lblChange.Caption = Format(sngChange, "currency") | |

|lblDollars.Caption = intDollars | |

|lblQuarters.Caption = intQuarters | |

|lblDimes.Caption = intDimes | |

|lblNickels.Caption = intNickels | |

|lblPennies.Caption = intPennies | |

|End Sub | |

| | |

|Private Sub cmdClear_Click() | |

|lblPaid.Caption = "" | |

|lblDue.Caption = "" | |

|lblChange.Caption = "" | |

|lblDollars.Caption = "" | |

|lblQuarters.Caption = "" | |

|lblDimes.Caption = "" | |

|lblNickels.Caption = "" | |

|lblPennies.Caption = "" | |

|cmdCalc.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|cmdClear.SetFocus | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmHinsbrook.Left = (Screen.Width - frmHinsbrook.Width) / 2 | |

| = (Screen.Height - frmHinsbrook.Height) / 2 | |

|End Sub | |

7. (Discovery) Setting a form’s BorderStyle property to 3-FixedDialog is not the same as setting it to 2-Sizable with both the MinButton and MaxButton properties set to False. When you set the form’s BorderStyle property to 3-Fixed Dialog, the user cannot use the form’s borders to size the form. When you set the BorderStyle property to 2-Sizable with both the MinButton and MaxButton properties set to False, the use can still use the form’s borders to size the form.

8. (Discovery) The Val function converts the empty string to 0 (zero); the CCur function results in a “Type mismatch” error. The Val function converts a letter to 0 (zero); the CSng function results in a “Type mismatch” error.

9. (Discovery) In this exercise, the student learns the difference between setting a form’s MousePointer property to 11-Hourglass and 13-Arrow and Hourglass. The student is not instructed to submit anything for this exercise.

Tutorial 3 – Debugging

Technique

• One of the most common errors made in writing code is typing the name of a variable incorrectly. To prevent Visual Basic from creating undeclared variables, always enter the Option Explicit statement in the General declarations of every form and module.

• If your application uses the InputBox function, test your application to see how it handles the various InputBox responses. Remember that the user can enter a valid response, enter an invalid response, click the OK button without entering a response, or click the Cancel button.

• When using the Val function, remember that Visual Basic must be able to interpret the string expression as a numeric value. Therefore, the string expression cannot include a letter or a special character, such as the dollar sign, comma, or the percent sign; it can, however include a period. When an invalid character is encountered, Visual Basic stops converting the string expression to a number at that point.

Exercises

1. T3db1 project – shaded areas show the changes the student would need to make

|Original code: |Debugged code: |

|Private Sub CmdAvg_Click() |Option Explicit |

|Dim intNum1 As Integer | |

|Dim intNum2 As Integer |Private Sub CmdAvg_Click() |

|intNumb1 = Val(InputBox("Enter the first number:", "First |Dim intNum1 As Integer |

|Number")) |Dim intNum2 As Integer |

|intNum2 = Val(InputBox("Enter the second number:", "Second |Dim sngAvg As Single |

|Number")) |intNum1 = Val(InputBox("Enter the first number:", "First |

|sngAvg = intNum1 + intNum2 / 2 |Number")) |

|lblAnswer.Caption = sngAve |intNum2 = Val(InputBox("Enter the second number:", "Second |

|End Sub |Number")) |

| |sngAvg = (intNum1 + intNum2) / 2 |

|Private Sub CmdExit_Click() |lblAnswer.Caption = sngAvg |

|End |End Sub |

|End Sub | |

| |Private Sub CmdExit_Click() |

|Private Sub Form_Load() |End |

| = (Screen.Height – frmAverage.Height) / 2 |End Sub |

|frmAverage.Left = (Screen.Width – frmAverage.Width) / 2 | |

|End Sub |Private Sub Form_Load() |

| | = (Screen.Height - frmAverage.Height) / 2 |

| |frmAverage.Left = (Screen.Width - frmAverage.Width) / 2 |

| |End Sub |

2. T3db2 project – shaded areas show the changes the student would need to make

|Option Explicit | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdSum_Click() | |

|Dim intNum1 As Integer | |

|Dim intNum2 As Integer | |

|Dim intSum As Integer | |

|intNum1 = Val(InputBox("Enter the first number:", "First Number")) | |

|intNum2 = Val(InputBox("Enter the second number:", "Second Number")) | |

|intSum = intNum1 + intNum2 | |

|lblAnswer.Caption = intSum | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

| = (Screen.Height - frmSum.Height) / 2 | |

|frmSum.Left = (Screen.Width - frmSum.Width) / 2 | |

|End Sub | |

3. T3db3 project

The first time the Compute Commission button is clicked in step b, the Click event calculates the commission using 10000 as the sales. The event then formats both the sales and the commission to currency. The second time the Compute Commission is clicked in step b, the Click event calculates the commission using $10,000.00 as the sales. Because the Val function stops converting a string to a number when it encounters the first invalid character—in this case, the $—the commission is calculated using 0 as the sales. Formatting the sales to standard before doing the calculation removes the $.

Tutorial 4, Lesson A

Questions

d curCost > 100 And curCost = 8

22. a, d, e Case “TEXAS”

Case “COLORADO”, “CALIFORNIA”

Case “ALABAMA” To “ARKANAS”

23. c process

24. a input/output

25. d rectangle

26. c parallelogram

27. a diamond

28. Case “NUTS” To “SOUP”

Exercises

1.

2.

3.

4. Select Case intStatus

Case 1

lblMsg.Caption = “Freshman”

Case 2

lblMsg.Caption = “Sophomore”

Case 3

lblMsg.Caption = “Junior”

Case 4

lblMsg.Caption = “Senior”

Case Else

lblMsg.Caption = “Incorrect Data”

End Select

5. Dim intCode as Integer, curCharge as Currency, curTotal as Currency

intCode = Val(txtData.Text)

Select Case intCode

Case Is 1 To 3

curCharge = 25

Case Is 4 To 6

curCharge = 20

Case Is 7 To 10

curCharge = 15

Case Is > 10

curCharge = 10

Case Else

curCharge = 0

End Select

curTotal = curCharge * intCode

lblTotal.Caption = curTotal

6. If UCase(txtCar.Text) = “GRAND AM” Then

lblType.Caption = “Pontiac”

End If

7. If intUnits < 0 Then

lblMsg.Caption = “Entry error”

Else

lblMsg.Caption = “Valid Number”

End If

8. If curPrice < 10 Then

lblMsg.Caption = “Reorder”

Else

lblMsg.Caption = “OK”

End If

9. If curSales 10000

lblComm.Caption = .1 * curSales

Case Is > 5000

lblComm.Caption = .075 * curSales

Case Is >= 1

lblComm.Caption = .05 * curSales

Case Else

lblComm.Caption = “Data Error”

End Select

24. If…Then…Else code

strState = UCase(strState)

If strState = “CALIFORNIA” Or strState = “TEXAS” Then

lblDisc.Caption = .1 * curSales

Else

If strState = “OREGON” Or strState = “NEW MEXICO” Then

lblDisc.Caption = .07 * curSales

Else

lblDisc.Caption = .06 * curSales

End If

End If

lblDisc.Caption =Format(lblDisc.Caption, “standard”)

Select Case code

strState = UCase(strState)

Select Case strState

Case “CALIFORNIA”, “TEXAS”

lblDisc.Caption = .1 * curSales

Case “OREGON”, “NEW MEXICO”

lblDisc.Caption = .07 * curSales

Cae Else

lblDisc.Caption = .06 * curSales

End Select

lblDisc.Caption =Format(lblDisc.Caption, “standard”)

25. txtData.Text = “P” or txtDate.Text = “p”

Tutorial 4, Lesson B

Questions

1. d option button

2. a check box

3. d frame

4. a one

5. b two

6. c three

7. d four

8. d four

9. c Randomize

10. b between 0 and 1, including 0 but not including 1

11. b (30 – 5 + 1) * Rnd + 5

12. e Int((25 – 1 + 1) * Rnd + 1)

13. a Call

14. e optInsured.Value = True

15. First select the cmdExit control, then cut it from the form. Select the frame control, then paste the cmdExit control in the frame.

16. First click the appropriate tool in the toolbox. Move the crosshair mouse pointer on the frame, then drag until the control is the desired size.

17. Assign the value in the first variable (curPrice1) to a temporary variable, then assign the value in the second variable (curPrice2) to the first variable (curPrice1), and then assign the value in the temporary variable to the second variable (curPrice2).

Exercises

1. lb1Done project – The student should submit two printouts of the interface and the code.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |Private Sub optIll_Click() |

|Dim strCapital As String, strChoice As String |strCapital = “Springfield” |

| |lblMsg.Caption = “” |

|Private Sub cmdCheck_Click() |End Sub |

|If strCapital = strChoice Then | |

|lblMsg.Caption = “Correct” |Private Sub optMad_Click() |

|Else |strChoice = “Madison” |

|lblMsg.Caption = “Incorrect” |lblMsg.Caption = “” |

|End If |End Sub |

|End Sub | |

| |Private Sub optOre_Click() |

|Private Sub cmdExit_Click() |strCapital = “Salem” |

|End |lblMsg.Caption = “” |

|End Sub |End Sub |

| | |

|Private Sub cmdPrint_Click() |Private Sub optSac_Click() |

|PrintForm |strChoice = “Sacramento” |

|End Sub |lblMsg.Caption = “” |

| |End Sub |

|Private Sub Form_Load() | |

|frmStates.Left = (Screen.Width – frmStates.Width) / 2 |Private Sub optSal_Click() |

| = (Screen.Height – frmStates.Height) / 2 |strChoice = “Salem” |

|optCal.Value = True |lblMsg.Caption = “” |

|optDen.Value = True |End Sub |

|End Sub | |

| |Private Sub optSpr_Click() |

|Private Sub optCal_Click() |strChoice = “Springfield” |

|strCapital = “Sacramento” |lblMsg.Caption = “” |

|lblMsg.Caption = “” |End Sub |

|End Sub | |

| |Private Sub optWis_Click() |

|Private Sub optCol_Click() |strCapital = “Madison” |

|strCapital = “Denver” |lblMsg.Caption = “” |

|lblMsg.Caption = “” |End Sub |

|End Sub | |

| | |

|Private Sub optDen_Click() | |

|strChoice = “Denver” | |

|lblMsg.Caption = “” | |

|End Sub | |

2. lb2Done project – The student should submit two printouts of the interface and the code.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |Private Sub cmdPrint_Click() |

|Dim intTennis As Integer, intGolf As Integer, intRacquet As Integer |PrintForm |

| |End Sub |

|Private Sub chkGolf_Click() | |

|If chkGolf.Value = 1 Then ‘checked |Private Sub Form_Load() |

|intGolf = 25 |frmWillow.Left = (Screen.Width – |

|Else ‘unchecked |frmWillow.Width) / 2 |

|intGolf = 0 | = (Screen.Height – |

|End If |frmWillow.Height) / 2 |

|lblAdditional.Caption = “” |End Sub |

|lblTotal.Caption = “” | |

|End Sub | |

| | |

|Private Sub chkRacquetball_Click() | |

|If chkRacquetball.Value = 1 Then ‘checked | |

|intRacquet = 20 | |

|Else ‘unchecked | |

|intRacquet = 0 | |

|End If | |

|lblAdditional.Caption = “” | |

|lblTotal.Caption = “” | |

|End Sub | |

| | |

|Private Sub chkTennis_Click() | |

|If chkTennis.Value = 1 Then ‘checked | |

|intTennis = 30 | |

|Else ‘unchecked | |

|intTennis = 0 | |

|End If | |

|lblAdditional.Caption = “” | |

|lblTotal.Caption = “” | |

|End Sub | |

| | |

|Private Sub cmdCalc_Click() | |

|Dim intAdd As Integer, intTotal As Integer | |

|intAdd = intTennis + intGolf + intRacquet | |

|intTotal = Val(lblBasic.Caption) + intAdd | |

|lblAdditional.Caption = intAdd | |

|lblTotal.Caption = intTotal | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

Tutorial 4, Lesson C

Questions

1. e both b and c (1 and vbChecked)

2. c False

3. c static variable

4. e imgCalc.Picture = LoadPicture()

5. d all of the above (a message, one or more command buttons, an optional icon)

6. e all of the above (the number and types of buttons displayed in the dialog box, the style of

the optional icon displayed in the dialog box, the default button, the dialog box’s

modality)

7. a Critical Message

8. b Warning Message

9. c Information Message

10. a application modal

11. c system modal

12. d txtName.SelStart = 0

13. e txtName.SelLength = Len(txtName.Text)

14. b GotFocus

Exercises

1. lc1Done project – The student should submit two printouts of the interface and the code. The numbers shown in the interface will vary.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |Private Sub cmdSelect_Click() |

| |Randomize |

|Private Sub cmdExit_Click() |lblNum1.Caption = Int((54 - 1 + 1) * Rnd + 1) |

|End |lblNum2.Caption = Int((54 - 1 + 1) * Rnd + 1) |

|End Sub |lblNum3.Caption = Int((54 - 1 + 1) * Rnd + 1) |

| |lblNum4.Caption = Int((54 - 1 + 1) * Rnd + 1) |

|Private Sub cmdPrint_Click() |lblNum5.Caption = Int((54 - 1 + 1) * Rnd + 1) |

|cmdSelect.Visible = False |lblNum6.Caption = Int((54 - 1 + 1) * Rnd + 1) |

|cmdPrint.Visible = False |End Sub |

|cmdExit.Visible = False | |

|PrintForm |Private Sub Form_Load() |

|cmdSelect.Visible = True |frmLotto.Left = (Screen.Width - frmLotto.Width) / 2 |

|cmdPrint.Visible = True | = (Screen.Height - frmLotto.Height) / 2 |

|cmdExit.Visible = True |End Sub |

|End Sub | |

2. lc2Done project – Shaded areas indicate changes made by student.

|Option Explicit |

|Dim sngNum1 As Single, sngNum2 As Single |

| |

|Private Sub chkDisplay_Click() |

|If chkDisplay.Value = vbChecked Then |

|fraInfo.Visible = True |

|Else |

|fraInfo.Visible = False |

|End If |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|End |

|End Sub |

| |

|Private Sub cmdVerify_Click() |

|Const conBtns As String = vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim sngUserAnswer As Single, sngCorrectAnswer As Single, intRetVal As Integer |

|Static intNumCorrect As Integer, intNumIncorrect As Integer |

|sngUserAnswer = Val(txtAnswer.Text) |

|Select Case True |

|Case optAdd.Value |

|sngCorrectAnswer = sngNum1 + sngNum2 |

|Case optSub.Value |

|sngCorrectAnswer = sngNum1 – sngNum2 |

|Case optMultiply.Value |

|sngCorrectAnswer = sngNum1 * sngNum2 |

|Case optDivide.Value |

|sngCorrectAnswer = Format(sngNum1 / sngNum2, "standard") |

|End Select |

|Select Case sngUserAnswer |

|Case Is = sngCorrectAnswer |

|imgIcon.Picture = imgHappy.Picture |

|intNumCorrect = intNumCorrect + 1 |

|txtAnswer.Text = "" |

|Call RandomNumbers |

|Case Else |

|imgIcon.Picture = LoadPicture() |

|intNumIncorrect = intNumIncorrect + 1 |

|intRetVal = MsgBox("Try again.", conBtns, "Math Application") |

|txtAnswer.SelStart = 0 |

|txtAnswer.SelLength = Len(txtAnswer.Text) |

|End Select |

|txtAnswer.SetFocus |

|lblCorrect.Caption = intNumCorrect |

|lblIncorrect.Caption = intNumIncorrect |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height – frmMath.Height) / 2 |

|frmMath.Left = (Screen.Width – frmMath.Width) / 2 |

|optLevel1.Value = True |

|optAdd.Value = True |

|End Sub |

|Private Sub RandomNumbers() |

|Dim sngTemp As Single |

|Randomize |

|If optLevel1.Value = True Then 'generate random numbers |

|sngNum1 = Int((10 - 1 + 1) * Rnd + 1) |

|sngNum2 = Int((10 - 1 + 1) * Rnd + 1) |

|Else 'Level 2 option button is selected |

|sngNum1 = Int((100 - 10 + 1) * Rnd + 10) |

|sngNum2 = Int((100 - 10 + 1) * Rnd + 10) |

|End If |

|If (optSub.Value = True Or optDivide.Value = True) _ |

|And sngNum2 > sngNum1 Then 'swap numbers |

|sngTemp = sngNum1 |

|sngNum1 = sngNum2 |

|sngNum2 = sngTemp |

|End If |

|lblNum1.Caption = sngNum1 'display numbers |

|lblNum2.Caption = sngNum2 |

|End Sub |

| |

|Private Sub optAdd_Click() |

|Call RandomNumbers |

|imgOperator.Picture = imgPlus.Picture |

|End Sub |

| |

|Private Sub optDivide_Click() |

|Call RandomNumbers |

|imgOperator.Picture = imgDivide.Picture |

|End Sub |

| |

|Private Sub optLevel1_Click() |

|Call RandomNumbers |

|End Sub |

| |

|Private Sub optLevel2_Click() |

|Call RandomNumbers |

|End Sub |

| |

|Private Sub optMultiply_Click() |

|Call RandomNumbers |

|imgOperator.Picture = imgMultiply.Picture |

|End Sub |

| |

|Private Sub optSub_Click() |

|Call RandomNumbers |

|imgOperator.Picture = imgMinus.Picture |

|End Sub |

| |

|Private Sub txtAnswer_GotFocus() |

|txtAnswer.SelStart = 0 |

|txtAnswer.SelLength = Len(txtAnswer.Text) |

|End Sub |

3. lc3Done project – The student should submit two printouts of the interface and the code.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit | |

|Dim intSem As Integer, sngRate As Single | |

| | |

|Private Sub chkDisc_Click() | |

|If chkDisc.Value = vbChecked Then | |

|sngRate = 0.1 | |

|Else | |

|sngRate = 0 | |

|End If | |

|lblTotal.Caption = "" | |

|End Sub | |

| | |

|Private Sub cmdCalc_Click() | |

|Const conBtns As String = vbOKOnly + vbInformation _ | |

|+ vbDefaultButton1 + vbApplicationModal | |

|Const conMsg As String = "Number of registrants must be greater than 0." | |

|Dim intNumReg As Integer, sngTotal As Single, intRetVal As Integer | |

|intNumReg = Val(txtReg.Text) | |

|If intNumReg < 0 Then | |

|intRetVal = MsgBox(conMsg, conBtns, "Registration Error") | |

|Else | |

|sngTotal = intNumReg * intSem | |

|sngTotal = sngTotal - sngTotal * sngRate | |

|End If | |

|lblTotal.Caption = sngTotal | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|fraButtons.Visible = False | |

|PrintForm | |

|fraButtons.Visible = True | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmReg.Left = (Screen.Width – frmReg.Width) / 2 | |

| = (Screen.Height – frmReg.Height) / 2 | |

|optSem1.Value = True | |

|End Sub | |

|Private Sub optSem1_Click() |

|intSem = 100 |

|lblTotal.Caption = "" |

|End Sub |

| |

|Private Sub optSem2_Click() |

|intSem = 120 |

|lblTotal.Caption = "" |

|End Sub |

| |

|Private Sub txtReg_GotFocus() |

|txtReg.SelStart = 0 |

|txtReg.SelLength = Len(txtReg.Text) |

|End Sub |

4. lc4Done project – The student should submit four printouts of the interface and two printouts of the code. The design of the interface will vary. The total due may not be formatted.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |Private Sub cmdExit_Click() |

| |End |

|Private Sub cmdCalc_Click() |End Sub |

|Const conBtns As String = vbOKOnly + vbInformation _ | |

|+ vbDefaultButton1 + vbApplicationModal |Private Sub cmdPrint_Click() |

|Const conMsg As String = _ |fraButtons.Visible = False |

|"The number of units must be greater than 0." |PrintForm |

|Dim intRetVal As Integer, intUnits As Integer, sngTotal As Single |fraButtons.Visible = True |

|intUnits = Val(txtUnits.Text) |End Sub |

|If intUnits = 5 | = (Screen.Height - |

|sngTotal = intUnits * 9 |frmMarine.Height) / 2 |

|Case Else |optRetail.Value = True |

|intRetVal = MsgBox(conMsg, conBtns, "Entry Error") |End Sub |

|End Select | |

|Else |Private Sub txtUnits_GotFocus() |

|Select Case intUnits |txtUnits.SelStart = 0 |

|Case 1 To 3 |txtUnits.SelLength = |

|sngTotal = intUnits * 15 |Len(txtUnits.Text) |

|Case 4 To 8 |End Sub |

|sngTotal = intUnits * 14 | |

|Case Is >= 9 | |

|sngTotal = intUnits * 12 | |

|Case Else | |

|intRetVal = MsgBox(conMsg, conBtns, "Entry Error") | |

|End Select | |

|End If | |

|lblTotal.Caption = Format(sngTotal, "currency") | |

|txtUnits.SelStart = 0 | |

|txtUnits.SelLength = Len(txtUnits.Text) | |

|txtUnits.SetFocus | |

|End Sub | |

8. (Discovery) The student should submit the code for the project. The instruction they should enter after reading the Help screen on the SetFocus method is shaded.

|Private Sub Check1_Click() |Private Sub Form_Load() |

|Text1.SetFocus |Form1.Show |

|End Sub |Check1.Value = vbChecked |

| |End Sub |

9. (Discovery) lc9Done project – The student should submit five handwritten answers, a printout of the Form Image, and a printout of the code. The design will vary.

Handwritten answers from step d:

Square area: 16

Rectangle area: 15

Parallelogram area: 12

Circle area: 12.56

Triangle area: 6

[pic]

|Option Explicit |Private Sub txtLength_GotFocus() |

| |txtLength.SelStart = 0 |

|Private Sub cmdCalc_Click() |txtLength.SelLength = Len(txtLength.Text) |

|Dim sngSide As Single, sngLength As Single, sngWidth As Single |End Sub |

|Dim sngPbase As Single, sngPheight As Single, sngRadius As Single | |

|Dim sngTbase As Single, sngTheight As Single |Private Sub txtPbase_GotFocus() |

|sngSide = Val(txtSide.Text) |txtPbase.SelStart = 0 |

|sngLength = Val(txtLength.Text) |txtPbase.SelLength = Len(txtPbase.Text) |

|sngWidth = Val(txtWidth.Text) |End Sub |

|sngPbase = Val(txtPbase.Text) | |

|sngPheight = Val(txtPheight.Text) |Private Sub txtPheight_GotFocus() |

|sngRadius = Val(txtRadius.Text) |txtPheight.SelStart = 0 |

|sngTbase = Val(txtTbase.Text) |txtPheight.SelLength = Len(txtPheight.Text) |

|sngTheight = Val(txtTheight.Text) |End Sub |

|lblSqArea.Caption = sngSide ^ 2 | |

|lblRecArea.Caption = sngLength * sngWidth |Private Sub txtRadius_GotFocus() |

|lblParArea.Caption = sngPbase * sngPheight |txtRadius.SelStart = 0 |

|lblCirArea.Caption = 3.14 * sngRadius ^ 2 |txtRadius.SelLength = Len(txtRadius.Text) |

|lblTriArea.Caption = 0.5 * sngTbase * sngTheight |End Sub |

|End Sub | |

| |Private Sub txtSide_GotFocus() |

|Private Sub cmdExit_Click() |txtSide.SelStart = 0 |

|End |txtSide.SelLength = Len(txtSide.Text) |

|End Sub |End Sub |

| | |

|Private Sub Form_Load() |Private Sub txtTbase_GotFocus() |

|frmArea.Left = (Screen.Width – frmArea.Width) / 2 |txtTbase.SelStart = 0 |

| = (Screen.Height – frmArea.Height) / 2 |txtTbase.SelLength = Len(txtTbase.Text) |

|End Sub |End Sub |

| | |

| |Private Sub txtTheight_GotFocus() |

| |txtTheight.SelStart = 0 |

| |txtTheight.SelLength = Len(txtTheight.Text) |

| |End Sub |

| | |

| |Private Sub txtWidth_GotFocus() |

| |txtWidth.SelStart = 0 |

| |txtWidth.SelLength = Len(txtWidth.Text) |

| |End Sub |

10. (Discovery) The Int and Fix functions both remove the fractional part of a numbers and return the resulting integer value. The difference between Int and Fix is in their treatment of negative numbers. Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts the negative number –7.5 to –8; Fix converts –7.5 to –7.

11. (Discovery) lc11Done project – The student should submit a printout of both the original and modified code. Changes to the original code are shaded in the modified code.

Original code:

|Option Explicit |

| |

|Private Sub cmdExit_Click() |

|End |

|End Sub |

| |

|Private Sub cmdVerify_Click() |

|Const conBtns As String = vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim intUserAnswer As Integer, intCorrectAnswer As Integer, intRetVal As Integer |

|Dim intNum1 As Integer, intNum2 As Integer |

|intNum1 = Val(lblNum1.Caption) |

|intNum2 = Val(lblNum2.Caption) |

|intUserAnswer = Val(txtAnswer.Text) |

|intCorrectAnswer = intNum1 + intNum2 |

|Select Case intUserAnswer |

|Case Is = intCorrectAnswer |

|imgIcon.Picture = imgHappy.Picture |

|txtAnswer.Text = "" |

|' |

|Case Else |

|imgIcon.Picture = LoadPicture() |

|intRetVal = MsgBox("Try again.", conBtns, "Math Application") |

|txtAnswer.SelStart = 0 |

|txtAnswer.SelLength = Len(txtAnswer.Text) |

|End Select |

|txtAnswer.SetFocus |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmMath.Height) / 2 |

|frmMath.Left = (Screen.Width - frmMath.Width) / 2 |

|optLevel1.Value = True |

|End Sub |

| |

|Private Sub txtAnswer_GotFocus() |

|txtAnswer.SelStart = 0 |

|txtAnswer.SelLength = Len(txtAnswer.Text) |

|End Sub |

Modified code:

|Option Explicit |

| |

|Private Sub cmdExit_Click() |

|End |

|End Sub |

| |

|Private Sub cmdVerify_Click() |

|Const conBtns As String = vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim intUserAnswer As Integer, intCorrectAnswer As Integer, intRetVal As Integer |

|Dim intNum1 As Integer, intNum2 As Integer |

|intNum1 = Val(lblNum1.Caption) |

|intNum2 = Val(lblNum2.Caption) |

|intUserAnswer = Val(txtAnswer.Text) |

|intCorrectAnswer = intNum1 + intNum2 |

|Select Case intUserAnswer |

|Case Is = intCorrectAnswer |

|imgIcon.Picture = imgHappy.Picture |

|txtAnswer.Text = "" |

|If optLevel1.Value = True Then |

|Call RandomNumbers(1, 10) |

|Else |

|Call RandomNumbers(10, 100) |

|End If |

|Case Else |

|imgIcon.Picture = LoadPicture() |

|intRetVal = MsgBox("Try again.", conBtns, "Math Application") |

|txtAnswer.SelStart = 0 |

|txtAnswer.SelLength = Len(txtAnswer.Text) |

|End Select |

|txtAnswer.SetFocus |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmMath.Height) / 2 |

|frmMath.Left = (Screen.Width - frmMath.Width) / 2 |

|optLevel1.Value = True |

|End Sub |

| |

|Private Sub optLevel1_Click() |

|Call RandomNumbers(1, 10) |

|End Sub |

| |

|Private Sub optLevel2_Click() |

|Call RandomNumbers(10, 100) |

|End Sub |

| |

|Private Sub txtAnswer_GotFocus() |

|txtAnswer.SelStart = 0 |

|txtAnswer.SelLength = Len(txtAnswer.Text) |

|End Sub |

| |

|Private Sub RandomNumbers(intMin As Integer, intMax As Integer) |

|Randomize |

|lblNum1.Caption = Int((intMax - intMin + 1) * Rnd + intMin) |

|lblNum2.Caption = Int((intMax - intMin + 1) * Rnd + intMin) |

|End Sub |

12. (Discovery) lc12Done project – The student should submit a printout of the code.

|lc12Done.frm |Procs.bas |

| | |

|Private Sub Form_Load() |Public Sub CenterForm(FormName As Form) |

|Call CenterForm(Me) |FormName.Left = (Screen.Width - FormName.Width) / 2 |

|End Sub | = (Screen.Height - FormName.Height) / 2 |

| |End Sub |

Tutorial 4 – Debugging

Technique

Use Visual Basic’s Print method to verify the contents of the variables in the application. The syntax of the Print method that prints information on a form is Print [outputlist]. The Print method is covered in more detail in Tutorial 6.

Exercises

1. The student should submit a printout of both the original and modified code. Changes made to the original code are shaded in the modified code.

Original code:

|Option Explicit |Private Sub txtCds_GotFocus() |

| |txtCds.SelStart = 0 |

|Private Sub cmdCalc_Click() |txtCds.SelLength = Len(txtCds.Text) |

|'declare variables |End Sub |

|Dim curTapePrice As Currency, curRecordPrice As Currency | |

|Dim curCdPrice As Currency, curTotTape As Currency |Private Sub txtRecords_GotFocus() |

|Dim curTotRecord As Currency, curTotCd As Currency |txtRecords.SelStart = 0 |

|Dim inTapes As Integer, inRecords As Integer, inCds As Integer |txtRecords.SelLength = Len(txtRecords.Text) |

|'assign values |End Sub |

|curTapePrice = 9.99 | |

|curRecordPrice = 7.99 |Private Sub txtTapes_GotFocus() |

|curCdPrice = 11.89 |txtTapes.SelStart = 0 |

|inTapes = Val(txtTapes.Text) |txtTapes.SelLength = Len(txtTapes.Text) |

|inRecords = Val(txtRecords.Text) |End Sub |

|inCds = Val(txtCds.Text) | |

|'calculate total cost of tapes, records, and CDs | |

|curTotTape = curTapePrice * inTapes | |

|curTotRecord = curRecordPrice * inRecords | |

|curTotCd = curCdPrice * inCds | |

|lblTprice.Caption = Format(curTotTape + curTotRecord + curTotCd, | |

|"currency") | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|End | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmDebug1.Left = (Screen.Width – frmDebug1.Width) / 2 | |

| = (Screen.Height – frmDebug1.Height) / 2 | |

|End Sub | |

Modified code:

|Option Explicit |

| |

|Private Sub cmdCalc_Click() |

|'declare variables |

|Dim curTapePrice As Currency, curRecordPrice As Currency |

|Dim curCdPrice As Currency, curTotTape As Currency |

|Dim curTotRecord As Currency, curTotCd As Currency |

|Dim inTapes As Integer, inRecords As Integer, inCds As Integer |

|'assign values |

|curTapePrice = 9.99 |

|curRecordPrice = 7.99 |

|curCdPrice = 11.89 |

|inTapes = Val(txtTapes.Text) |

|inRecords = Val(txtRecords.Text) |

|inCds = Val(txtCds.Text) |

|'calculate total cost of tapes, records, and CDs |

|curTotTape = curTapePrice * inTapes |

|curTotRecord = curRecordPrice * inRecords |

|curTotCd = curCdPrice * inCds |

|lblTprice.Caption = Format(curTotTape + curTotRecord + curTotCd, "currency") |

|Print curTotTape, curTotRecord, curTotCd |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|End |

|End Sub |

| |

|Private Sub Form_Load() |

|frmDebug1.Left = (Screen.Width - frmDebug1.Width) / 2 |

| = (Screen.Height - frmDebug1.Height) / 2 |

|End Sub |

| |

|Private Sub txtCds_GotFocus() |

|txtCds.SelStart = 0 |

|txtCds.SelLength = Len(txtCds.Text) |

|End Sub |

| |

|Private Sub txtRecords_GotFocus() |

|txtRecords.SelStart = 0 |

|txtRecords.SelLength = Len(txtRecords.Text) |

|End Sub |

| |

|Private Sub txtTapes_GotFocus() |

|txtTapes.SelStart = 0 |

|txtTapes.SelLength = Len(txtTapes.Text) |

|End Sub |

2. The student should submit a printout of both the original and modified code. Changes made to the original code are shaded in the modified code.

Original code:

|Option Explicit |Private Sub optRetail_Click() |

|Dim curPrice As Currency |curPrice = 15 |

| |lblTotal.Caption = "" |

|Private Sub cmdCalc_Click() |End Sub |

|Dim intQuantity As Integer | |

|intQuantity = Val(txtQuantity.Text) |Private Sub optWhole_Click() |

|lblTotal.Caption = intQuantity * curPrice |curPrice = 10 |

|txtQuantity.SetFocus |lblTotal.Caption = "" |

|End Sub |End Sub |

| | |

|Private Sub cmdExit_Click() |Private Sub txtQuantity_Change() |

|End |lblTotal.Caption = "" |

|End Sub |End Sub |

| | |

|Private Sub Form_Load() |Private Sub txtQuantity_GotFocus() |

| = (Screen.Height – frmTotalDue.Height) / 2 |txtQuantity.SelStart = 0 |

|frmTotalDue.Left = (Screen.Width – frmTotalDue.Width) / 2 |txtQuantity.SelLength = Len(txtQuantity.Text) |

|End Sub |End Sub |

Modified code: The student will need to set the optWhole button’s Value property to False in the Properties window, then set it to True in the form’s Load event.

|Option Explicit |Private Sub optRetail_Click() |

|Dim curPrice As Currency |curPrice = 15 |

| |lblTotal.Caption = "" |

|Private Sub cmdCalc_Click() |End Sub |

|Dim intQuantity As Integer | |

|intQuantity = Val(txtQuantity.Text) |Private Sub optWhole_Click() |

|lblTotal.Caption = intQuantity * curPrice |curPrice = 10 |

|txtQuantity.SetFocus |lblTotal.Caption = "" |

|End Sub |End Sub |

| | |

|Private Sub cmdExit_Click() |Private Sub txtQuantity_Change() |

|End |lblTotal.Caption = "" |

|End Sub |End Sub |

| | |

|Private Sub Form_Load() |Private Sub txtQuantity_GotFocus() |

| = (Screen.Height – frmTotalDue.Height) / 2 |txtQuantity.SelStart = 0 |

|frmTotalDue.Left = (Screen.Width – frmTotalDue.Width) / 2 |txtQuantity.SelLength = Len(txtQuantity.Text) |

|optWhole.Value = True |End Sub |

|End Sub | |

When you set an option button’s Value property to True in the Properties window, it does not invoke the button’s Click event. Setting the Value property to True in code, however, does invoke the Click event. The button’s Value property must be set to False in the Properties window, then set to True in the code.

Tutorial 5, Lesson A

Questions

1. b hexagon

2. d 6

3. d 7

4. c 4

5. e 12

6. e less than or equal to

7. c greater than or equal to

8. e For intTemp = 1 to 10

9. 3 Adds the stepvalue to the counter

1 Initializes the counter to the startvalue

2 Checks if the value in the counter is greater (less) than the endvalue

10. b 1

11. b,c,e Do Until, Do while, For Next

12. d a (Do Until) or b (Do While)

13. e a (Do Until), b (Do While), or c (For Next)

14. e b (Do While) and c (For Next)

15. a Do Until

16. b Do While

17. a Do Until

18. a Do Until, Do While

19. d counter

20. a accumulator

21. c, e initialized, updated

22. b counter, accumulator

23. e intNumber = intNumber + 1

24. d curTotal = curTotal + curSales

25. b the Dim statement

Exercises

1. The student should submit a printout of the Help screens for the For Next and Do Loop statements. The student should answer that For Next and Do Loops can be nested.

2. Dim intCount as Integer

intCount = 10

Do While intCount < 100

Print intCount * 2

intCount = intCount + 10

Loop

3.

4. The student should submit a printout of the code. On the printout, the student should indicate that the intTemp variable contains the number 126 when the loop ends.

|Option Explicit | |

| | |

|Private Sub Command1_Click() | |

|Dim intTemp As Integer | |

|For intTemp = 0 To 117 Step 9 | |

|Print intTemp | |

|Next intTemp | |

|Print intTemp | |

|End Sub | |

5. The student should submit a printout of the code. On the printout, the student should indicate that the squares of the even number from 2 through 12 are 4, 16, 36, 64, 100, and 144.

|Option Explicit | |

| | |

|Private Sub Command1_Click() | |

|Dim intTemp As Integer | |

|For intTemp = 2 To 12 Step 2 | |

|Print intTemp ^ 2 | |

|Next intTemp | |

|End Sub | |

6. la6Done project – The student should submit a printout of the code. Changes to the original code are shaded.

|Option Explicit |Private Sub cmdExit_Click() |

| |End |

|Private Sub cmdExam1_Click() |End Sub |

|Dim intCount As Integer | |

|For intCount = 1 To 3 Step 1 |Private Sub Form_Load() |

|Print intCount | = (Screen.Height - frmFor.Height) / 2 |

|Next intCount |frmFor.Left = (Screen.Width - frmFor.Width) / 2 |

|End Sub |End Sub |

| | |

|Private Sub cmdExam2_Click() | |

|Dim intCount As Integer | |

|For intCount = 0 To 6500 Step 50 | |

|imgAirPlane.Left = intCount | |

|Next intCount | |

|For intCount = 6500 To 0 Step -50 | |

|imgAirPlane.Left = intCount | |

|Next intCount | |

|End Sub | |

7. la7Done project – The student should submit a printout of the code. Changes to the original code are shaded.

|Option Explicit |Private Sub cmdExam4_Click() |

| |Dim intCount As Integer |

|Private Sub cmdExam1_Click() |imgAirPlane.Left = 0 |

|Dim intCount As Integer | = 0 |

|For intCount = 1 To 3 Step 1 |For intCount = 0 To 3600 Step 50 |

|Print intCount |imgAirPlane.Left = imgAirPlane.Left + 100 |

|Next intCount | = intCount |

|End Sub |Next intCount |

| |End Sub |

|Private Sub cmdExam2_Click() | |

|Dim intCount As Integer |Private Sub cmdExit_Click() |

|For intCount = 0 To 6500 Step 50 |End |

|imgAirPlane.Left = intCount |End Sub |

|Next intCount | |

|End Sub |Private Sub Form_Load() |

| | = (Screen.Height – frmFor.Height) / 2 |

|Private Sub cmdExam3_Click() |frmFor.Left = (Screen.Width – frmFor.Width) / 2 |

|Dim intCount As Integer |End Sub |

|For intCount = 0 To 3600 Step 50 | |

| = intCount | |

|Next intCount | |

|End Sub | |

8. la8Done project – The student should submit a printout of the code.

|Option Explicit |Private Sub cmdExit_Click() |

|Private Sub cmdDisplay_Click() |End |

|Dim intNum1 As Integer, intNum2 As Integer |End Sub |

|Dim intTemp As Integer, intSum As Integer | |

|intNum1 = 1 | |

|intNum2 = 1 | |

|Print intNum1; intNum2; | |

|For intTemp = 1 To 8 | |

|intSum = intNum1 + intNum2 | |

|Print intSum; | |

|intNum1 = intNum2 | |

|intNum2 = intSum | |

|Next intTemp | |

|End Sub | |

9. The student should submit the code. Changes to the code are shaded.

|Option Explicit | |

| | |

|Private Sub Command1_Click() | |

|Dim intCount As Integer | |

|intCount = 1 | |

|Do While intCount 10 | |

|End Sub | |

11. Do While curSales 0

12. Loop Until curSales = 0

13. Do While UCase(strName) “DONE”

14. Loop Until UCase(strName) = “DONE”

15. 0, 1, 2, 3, 4

16. 0, 1, 2, 3, 4, 5

17. The missing instruction is intNum = intNum + 1. The instruction should be placed immediately below the Print intNum instruction.

18. The missing instruction is intNum = intNum - 1. The instruction should be placed immediately below the Print intNum instruction.

19. The missing instruction is curSales = Val(InputBox(“Enter a sales amount”)). The instruction should be placed immediately below the Print curSales * .1 instruction.

20. To fix the code, you need simply to switch the curSales = Val(InputBox(“Enter a sales amount”))instruction with the Print curSales * .1 instruction.

21. intNumStudents = intNumStudents + 1

22. intQuantity = intQuantity + 5

23. curTotal = curTotal + curSales

24. sngTotal = sngTotal + sngGross

25. intEmployees = 1

26. The intTotal = intTotal + 1 instruction will update a counter, and the sngTotal = sngTotal + sngSales instruction will update an accumulator. You know that the intTotal = intTotal + 1 instruction updates a counter because counters are always updated by a constant amount. You know that the sngTotal = sngTotal + sngSales instruction updates an accumulator because accumulators are always updated by an amount that varies.

27. 0, 2, 4

28. 1

Tutorial 5, Lesson B

Questions

1. a control array

2. d index

3. e txtName(1)

4. a 3

5. a agruments

6. d parallel

7. b GotFocus

8. a Enabled

9. c 2

10. To make the four existing options buttons into a control array, simply enter the same name (optChoice) in each control’s Name property. When you are asked if you want to create a control array, click the Yes button. The values in the Index properties will be 0, 1, 2, and 3.

11. To create a control array that contains three check boxes, add the first check box to the form and set its Name property to chkChoice; set other properties appropriately. Copy the check box to the clipboard, then paste two more check boxes on the form. When you are asked if you want to create a control array, click the Yes button. The values in the Index properties will be 0, 1, and 2.

Exercises

1. lb1Done project – The student should submit a printout of the code.

|Option Explicit |Private Sub Form_Load() |

| |frmImages.Left = (Screen.Width - frmImages.Width) / 2 |

|Private Sub cmdExit_Click() | = (Screen.Height - frmImages.Height) / 2 |

|End |optElement(0).Value = True |

|End Sub |End Sub |

| | |

|Private Sub cmdPrint_Click() |Private Sub optElement_Click(Index As Integer) |

|PrintForm |imgPicture.Picture = imgElement(Index).Picture |

|End Sub |End Sub |

2. lb2Done project – The student should submit a printout of the code.

|Option Explicit |Private Sub cmdYellow_Click() |

| |Dim intX As Integer |

|Private Sub cmdBlue_Click() |Do While intX 3 Then |

|End |intNum = 3 |

|End Sub |tmrFaces1.Enabled = False |

| |tmrFaces2.Enabled = True |

|Private Sub Form_Load() |End If |

| = (Screen.Height – frmFaces.Height) |End Sub |

|/ 2 | |

|frmFaces.Left = (Screen.Width – frmFaces.Width) /|Private Sub tmrFaces2_Timer() |

|2 |imgFace(intNum).Visible = False |

|End Sub |intNum = intNum - 1 |

| |If intNum < 0 Then |

| |intNum = 0 |

| |tmrFaces2.Enabled = False |

| |tmrFaces1.Enabled = True |

| |End If |

| |End Sub |

5. (Discovery) lb5Done project – The student should submit a printout of the Form as Text and the code. The student will need to set the horizontal scroll bar’s Max property to 50 and its LargeChange property to 10. The horizontal scroll bar’s Min, Value, and SmallChange properties should be left at their default values of 0, 0, and 1, respectively. The student should set the label control’s Caption property to 0.

| VERSION 5.00 |Begin VB.Label Label1 |

|Begin VB.Form Form1 |Appearance = 0 'Flat |

|Caption = "Form1" |BackColor = &H80000005& |

|ClientHeight = 1380 |BackStyle = 0 'Transparent |

|ClientLeft = 3705 |BorderStyle = 1 'Fixed Single |

|ClientTop = 2700 |Caption = "0" |

|ClientWidth = 1785 |ForeColor = &H80000008& |

|LinkTopic = "Form1" |Height = 495 |

|ScaleHeight = 1380 |Left = 240 |

|ScaleWidth = 1785 |TabIndex = 0 |

|Begin VB.HScrollBar HScroll1 |Top = 240 |

|Height = 255 |Width = 1215 |

|LargeChange = 10 |End |

|Left = 240 |End |

|Max = 50 | |

|TabIndex = 1 |Code: |

|Top = 840 |Private Sub HScroll1_Change() |

|Width = 1215 |Label1.Caption = HScroll1.Value |

|End |End Sub |

| | |

| |Private Sub HScroll1_Scroll() |

| |Label1.Caption = HScroll1.Value |

| |End Sub |

6. (Discovery) lb6Done project – The student should submit a printout of the Form as Text and the code. The student will need to set the slider control’s Min property to 1, its Max property to 20, and its LargeChange property to 1. Setting the Min property to 1 will automatically set the Value property to 1. The horizontal scroll bar’s SmallChange property should be left at its default value of 1. The student should set the label control’s Caption property to 1.

|VERSION 5.00 |Begin VB.Label Label1 |

|Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; |Appearance = 0 'Flat |

|"MSCOMCTL.OCX" |BackColor = &H80000005& |

|Begin VB.Form Form1 |BackStyle = 0 'Transparent |

|Caption = "Form1" |BorderStyle = 1 'Fixed Single |

|ClientHeight = 1830 |Caption = "1" |

|ClientLeft = 3585 |ForeColor = &H80000008& |

|ClientTop = 2535 |Height = 495 |

|ClientWidth = 2175 |Left = 240 |

|LinkTopic = "Form1" |TabIndex = 0 |

|ScaleHeight = 1830 |Top = 240 |

|ScaleWidth = 2175 |Width = 1500 |

|Begin MSComctlLib.Slider Slider1 |End |

|Height = 630 |End |

|Left = 120 | |

|TabIndex = 1 |Code: |

|Top = 840 |Private Sub Slider1_Change() |

|Width = 1575 |Label1.Caption = Slider1.Value |

|_ExtentX = 2778 |End Sub |

|_ExtentY = 1111 | |

|_Version = 393216 |Private Sub Slider1_Click() |

|LargeChange = 1 |Label1.Caption = Slider1.Value |

|Min = 1 |End Sub |

|Max = 20 | |

|SelStart = 1 | |

|Value = 1 | |

|End | |

Tutorial 5, Lesson C

Questions

1. d MsgBox

2. e Unload

3. a Change

4. b Alignment

5. a For intX = 2 To 0 Step –1

sngTotal = sngTotal + Val(txtSales(intX).Text)

Next intX

6. a -1

Exercises

1. lc1Done project – The student should submit two printouts of the interface with the test data showing and two printouts of the code. The total amount may not be formatted.

Printout #1 (step i) Printout #2 (step l)

[pic] [pic]

Code #1 (step j)

|Option Explicit |

| |

|Private Sub cmdAdd_Click() |

|Dim intX As Integer, sngSales As Single, sngTotal As Single |

|For intX = 0 To 3 |

|sngSales = Val(txtRegion(intX).Text) |

|sngTotal = sngTotal + sngSales |

|Next intX |

|lblTotal.Caption = Format(sngTotal, "currency") |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmColfax |

|End Sub |

| |

|Private Sub cmdPrint_Click() |

|Frame1.Visible = False |

|PrintForm |

|Frame1.Visible = True |

|End Sub |

| |

|Private Sub Form_Load() |

|frmColfax.Left = (Screen.Width - frmColfax.Width) / 2 |

| = (Screen.Height - frmColfax.Height) / 2 |

|End Sub |

| |

|Private Sub Form_Unload(Cancel As Integer) |

|Dim intUser As Integer |

|Const conBtns As Integer = _ |

|vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal |

|intUser = MsgBox("Do you want to exit?", conBtns, "Colfax Industries") |

|If intUser = vbNo Then |

|Cancel = 1 |

|End If |

|End Sub |

| |

|Private Sub txtRegion_Change(Index As Integer) |

|lblTotal.Caption = "" |

|End Sub |

| |

|Private Sub txtRegion_GotFocus(Index As Integer) |

|txtRegion(Index).SelStart = 0 |

|txtRegion(Index).SelLength = Len(txtRegion(Index)) |

|End Sub |

Code #2 (step m)

|Option Explicit |

| |

|Private Sub cmdAdd_Click() |

|Dim intX As Integer, sngSales As Single, sngTotal As Single |

|Do While intX 0 Then | |

|sngAvgPrice = sngTotPrice / intItems | |

|Else | |

|sngAvgPrice = 0 | |

|End If | |

|Printer.Print | |

|Printer.Print "Average price: "; Format(sngAvgPrice, "currency") | |

|Printer.Print "End of report" | |

|Printer.EndDoc | |

|Printer.Font = strFont | |

|Printer.FontSize = sngSize | |

|End Sub | |

|Private Sub cmdWrite_Click() |Private Sub txtNum_GotFocus() |

|Dim intQuantity As Integer, sngPrice As Single |txtNum.SelStart = 0 |

|intQuantity = Val(txtQuantity.Text) |txtNum.SelLength = Len(txtNum.Text) |

|sngPrice = Val(txtPrice.Text) |End Sub |

|Open "a:\tut06\la3.dat" For Append As #1 | |

|Write #1, txtNum.Text, intQuantity, sngPrice |Private Sub txtQuantity_GotFocus() |

|Close #1 |txtQuantity.SelStart = 0 |

|txtNum.SetFocus |txtQuantity.SelLength = Len(txtQuantity.Text) |

|End Sub |End Sub |

| | |

|Private Sub Form_Load() |Private Sub txtPrice_GotFocus() |

| = (Screen.Height – frmBoggs.Height) / 2 |txtPrice.SelStart = 0 |

|frmBoggs.Left = (Screen.Width – frmBoggs.Width) / 2 |txtPrice.SelLength = Len(txtPrice.Text) |

|End Sub |End Sub |

4. la4Done project – The student should submit a printout of the code, as well as the answers to step d.

step d answers: Rectangle area is 72, circle area is 314, triangle area is 37.5

|Option Explicit | |

| | |

|Private Sub cmdExit_Click() | |

|Unload frmArea | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmArea.Left = (Screen.Width - frmArea.Width) / 2 | |

| = (Screen.Height – frmArea.Height) / 2 | |

|lstShape.AddItem "Rectangle" | |

|lstShape.AddItem "Circle" | |

|lstShape.AddItem "Triangle" | |

|End Sub | |

| | |

|Private Sub lstShape_Click() | |

|Dim sngNum1 As Single, sngNum2 As Single, sngArea As Single | |

|Select Case lstShape.Text | |

|Case "Circle" | |

|sngNum1 = Val(InputBox("Enter the radius: ", "Circle")) | |

|sngArea = 3.14 * sngNum1 ^ 2 | |

|Case "Rectangle" | |

|sngNum1 = Val(InputBox("Enter the length: ", "Rectangle")) | |

|sngNum2 = Val(InputBox("Enter the width: ", "Rectangle")) | |

|sngArea = sngNum1 * sngNum2 | |

|Case "Triangle" | |

|sngNum1 = Val(InputBox("Enter the base: ", "Triangle")) | |

|sngNum2 = Val(InputBox("Enter the height: ", "Triangle")) | |

|sngArea = sngNum1 * sngNum2 / 2 | |

|End Select | |

|lblArea.Caption = sngArea | |

|End Sub | |

5. la5Done project – The student should submit a printout of the code. Changes to the original code are shaded. In addition to these change, the student should set the Print Report (cmdPrint) button’s Enabled property to False in the Properties window.

|Option Explicit | |

| | |

|Private Sub cmdDisplay_Click() | |

|Dim strParty As String, intAge As Integer, intCount As Integer | |

|For intCount = 0 To 3 'clear the label controls | |

|lblDem(intCount).Caption = "" | |

|lblRep(intCount).Caption = "" | |

|lblInd(intCount).Caption = "" | |

|Next intCount | |

|Open "a:\tut06\la5.dat" For Input As #1 'open the sequential file | |

|Do While Not EOF(1) | |

|Input #1, strParty, intAge 'read a record | |

|Select Case strParty 'update appropriate label control | |

|Case "Democrat" | |

|lblDem(intAge).Caption = Val(lblDem(intAge).Caption) + 1 | |

|Case "Republican" | |

|lblRep(intAge).Caption = Val(lblRep(intAge).Caption) + 1 | |

|Case "Independent" | |

|lblInd(intAge).Caption = Val(lblInd(intAge).Caption) + 1 | |

|End Select | |

|Loop | |

|Close #1 'close the file | |

|cmdPrint.Enabled = True | |

|End Sub | |

| | |

|Private Sub cmdEnter_Click() | |

|Dim intX As Integer | |

|For intX = 0 To 3 'clear label controls | |

|lblDem(intX).Caption = "" | |

|lblRep(intX).Caption = "" | |

|lblInd(intX).Caption = "" | |

|Next intX | |

|Open "a:\tut06\la5.dat" For Append As #1 'open the sequential file | |

|Write #1, lstParty.Text, lstAge.ListIndex 'write the record | |

|Close #1 'close the file | |

|cmdPrint.Enabled = False | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|Unload frmPao | |

|End Sub | |

| |

|Private Sub cmdPrint_Click() |

|Dim intX As Integer, intDem As Integer, intRep As Integer |

|Dim intInd As Integer, intTotal As Integer |

|Dim strFont As String, sngSize As Single |

|Dim strPS1 As String * 3, strPS2 As String * 3, strPS3 As String * 3 |

|Dim strPS4 As String * 3, strPS5 As String * 4 |

|'accumulate totals |

|For intX = 0 To 3 |

|intDem = intDem + Val(lblDem(intX).Caption) |

|intRep = intRep + Val(lblRep(intX).Caption) |

|intInd = intInd + Val(lblInd(intX).Caption) |

|Next intX |

|intTotal = intDem + intRep + intInd |

|strFont = Printer.Font 'save current printer settings |

|sngSize = Printer.FontSize |

|Printer.Font = "courier new" 'change printer settings |

|Printer.FontSize = 10 'print title and headings |

|Printer.Print Tab(30); "PAO Information - 1999" |

|Printer.Print |

|Printer.Print Tab(5); "Party"; Tab(20); "18-35"; Tab(30); "36-50"; _ |

|Tab(40); "51-65"; Tab(50); "Over 65"; Tab(60); "Total" |

|'align democrat numbers and print |

|RSet strPS1 = Format(lblDem(0).Caption, "general number") |

|RSet strPS2 = Format(lblDem(1).Caption, "general number") |

|RSet strPS3 = Format(lblDem(2).Caption, "general number") |

|RSet strPS4 = Format(lblDem(3).Caption, "general number") |

|RSet strPS5 = Format(intDem, "general number") |

|Printer.Print Tab(5); "Democrat"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|'align republican numbers and print |

|RSet strPS1 = Format(lblRep(0).Caption, "general number") |

|RSet strPS2 = Format(lblRep(1).Caption, "general number") |

|RSet strPS3 = Format(lblRep(2).Caption, "general number") |

|RSet strPS4 = Format(lblRep(3).Caption, "general number") |

|RSet strPS5 = Format(intRep, "general number") |

|Printer.Print Tab(5); "Republican"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|'align independent numbers and print |

|RSet strPS1 = Format(lblInd(0).Caption, "general number") |

|RSet strPS2 = Format(lblInd(1).Caption, "general number") |

|RSet strPS3 = Format(lblInd(2).Caption, "general number") |

|RSet strPS4 = Format(lblInd(3).Caption, "general number") |

|RSet strPS5 = Format(intInd, "general number") |

|Printer.Print Tab(5); "Independent"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|Printer.Print 'print two blank lines |

|Printer.Print |

|'print grand total |

|RSet strPS5 = Format(intTotal, "general number") |

|Printer.Print Tab(41); "Total respondents"; Tab(61); strPS5 |

|Printer.Print 'print a blank line |

|Printer.Print Tab(5); "End of report" 'print message |

|Printer.EndDoc 'send report to printer |

|Printer.Font = strFont |

|Printer.FontSize = sngSize |

|End Sub |

|Private Sub Form_Load() |

| = (Screen.Height - frmPao.Height) / 2 |

|frmPao.Left = (Screen.Width - frmPao.Width) / 2 |

|lstAge.AddItem "18 - 35" |

|lstAge.AddItem "36 - 50" |

|lstAge.AddItem "51 - 65" |

|lstAge.AddItem "Over 65" |

|lstParty.AddItem "Republican" |

|lstParty.AddItem "Independent" |

|lstParty.AddItem "Democrat" |

|lstParty.ListIndex = 0 |

|lstAge.ListIndex = 1 |

|End Sub |

6. la6Done project – The student should submit a printout of the report and a printout of the code. Changes to the original code are shaded.

| PAO Information – 1999 |

| |

|Name Age Group Party |

|---- --------- ----- |

|Jean Rowe 18 – 35 Deomcrat |

|Pat Smith 18 – 35 Democrat |

|Carol Key 36 – 50 Republican |

|Paul Utes Over 65 Independent |

|Sabrina Elm 18 – 35 Republican |

| |

|Total records: 5 |

| |

|End of report |

|Option Explicit |

| |

|Private Sub cmdDisplay_Click() |

|Dim strParty As String, intAge As Integer, intCount As Integer, strName As String |

|For intCount = 0 To 3 'clear the label controls |

|lblDem(intCount).Caption = "" |

|lblRep(intCount).Caption = "" |

|lblInd(intCount).Caption = "" |

|Next intCount |

|Open "a:\tut06\la6.dat" For Input As #1 'open the sequential file |

|Do While Not EOF(1) |

|Input #1, strName, strParty, intAge 'read a record |

|Select Case strParty 'update appropriate label control |

|Case "Democrat" |

|lblDem(intAge).Caption = Val(lblDem(intAge).Caption) + 1 |

|Case "Republican" |

|lblRep(intAge).Caption = Val(lblRep(intAge).Caption) + 1 |

|Case "Independent" |

|lblInd(intAge).Caption = Val(lblInd(intAge).Caption) + 1 |

|End Select |

|Loop |

|Close #1 'close the file |

|End Sub |

| |

|Private Sub cmdEnter_Click() |

|Open "a:\tut06\la6.dat" For Append As #1 'open the sequential file |

|Write #1, txtName.Text, lstParty.Text, lstAge.ListIndex 'write the record |

|Close #1 'close the file |

|txtName.SetFocus |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmPao |

|End Sub |

| |

|Private Sub txtName_GotFocus() |

|txtName.SelStart = 0 |

|txtName.SelLength = Len(txtName.Text) |

|End Sub |

|Private Sub cmdPrint_Click() |

|Dim intTotal As Integer, strName As String, strParty As String, intAge As Integer |

|Dim strAgeGroup As String, strFont As String, sngSize As Single |

|strFont = Printer.Font 'save current printer settings |

|sngSize = Printer.FontSize |

|Printer.Font = "courier new" 'change printer settings |

|Printer.FontSize = 10 'print title and headings |

|Printer.Print Tab(20); "PAO Information - 1999" |

|Printer.Print |

|Printer.Print Tab(5); "Name"; Tab(25); "Age Group"; Tab(40); "Party" |

|Printer.Print Tab(5); "----"; Tab(25); "---------"; Tab(40); "-----" |

|Open "a:\tut06\la6.dat" For Input As #1 'open and read file |

|Do While Not EOF(1) |

|Input #1, strName, strParty, intAge |

|Select Case intAge |

|Case 0 |

|strAgeGroup = "18 - 35" |

|Case 1 |

|strAgeGroup = "36 - 50" |

|Case 2 |

|strAgeGroup = "51 - 65" |

|Case 3 |

|strAgeGroup = "Over 65" |

|End Select |

|Printer.Print Tab(5); strName; Tab(25); strAgeGroup; Tab(40); strParty |

|intTotal = intTotal + 1 |

|Loop |

|Close #1 |

|Printer.Print 'print two blank lines |

|Printer.Print |

|'print grand total |

|Printer.Print Tab(5); "Total records:"; intTotal |

|Printer.Print 'print a blank line |

|Printer.Print Tab(5); "End of report" 'print message |

|Printer.EndDoc 'send report to printer |

|Printer.Font = strFont |

|Printer.FontSize = sngSize |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmPao.Height) / 2 |

|frmPao.Left = (Screen.Width - frmPao.Width) / 2 |

|lstAge.AddItem "18 - 35" |

|lstAge.AddItem "36 - 50" |

|lstAge.AddItem "51 - 65" |

|lstAge.AddItem "Over 65" |

|lstParty.AddItem "Republican" |

|lstParty.AddItem "Independent" |

|lstParty.AddItem "Democrat" |

|lstParty.ListIndex = 0 |

|lstAge.ListIndex = 1 |

|End Sub |

7. la7Done project – The student should submit a printout of the interface with the test data showing and a printout of the code. Changes to the original code are shaded.

[pic]

|Option Explicit |Private Sub lstExt_Click() |

| |Select Case lstExt.Text |

|Private Sub cmdExit_Click() |Case "Smith, Joe" |

|Unload frmExt |lblExt.Caption = 3388 |

|End Sub |Case "Jones, Mary" |

| |lblExt.Caption = 3356 |

|Private Sub cmdPrint_Click() |Case "Adkari, Joel" |

|PrintForm |lblExt.Caption = 2487 |

|End Sub |Case "Lin, Sue" |

| |lblExt.Caption = 1111 |

|Private Sub Form_Load() |Case "Li, Vicky" |

|Dim strName As String |lblExt.Caption = 2222 |

| = (Screen.Height - frmExt.Height) / 2 |End Select |

|frmExt.Left = (Screen.Width - frmExt.Width) / 2 |End Sub |

|Open "a:\tut06\la7.dat" For Input As #1 | |

|Do While Not EOF(1) | |

|Input #1, strName | |

|lstExt.AddItem strName | |

|Loop | |

|lstExt.ListIndex = 0 | |

|End Sub | |

8. (Discovery) la8Done project – The student should submit a printout of the la8Zip.dat file, a printout of the report, and a printout of the code.

|la8Zip.dat file: |Report: |

|"Franklin Park","60131" | |

|"River Grove","60171" |Dr. Jonas Patient List |

|"Elmwood Park","60191" | |

|"Northlake","60145" |Name Birthday |

|"River Forest","60305" |---- -------- |

|"LaGrange","60525" |Sally Bramas 3/9/95 |

|"Oak Park","60405" | |

|"Chicago","60304" |End of report |

|Option Explicit | |

|Dim strFound As String | |

| | |

|Private Sub cmdExit_Click() | |

|Unload frmJonas | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|Dim strName As String, strAddress As String, strCity As String | |

|Dim strZip As String, strBirth As String | |

|Dim strFont As String, sngSize As Single | |

|strFont = Printer.Font 'save current printer settings | |

|sngSize = Printer.FontSize | |

|Printer.Font = "courier new" 'change printer settings | |

|Printer.FontSize = 10 'print title and headings | |

|Printer.Print Tab(5); "Dr. Jonas Patient List" | |

|Printer.Print | |

|Printer.Print Tab(5); "Name"; Tab(25); "Birthday" | |

|Printer.Print Tab(5); "----"; Tab(25); "--------" | |

|Open "a:\tut06\la8.dat" For Input As #1 'open and read file | |

|Do While Not EOF(1) | |

|Input #1, strName, strAddress, strCity, strZip, strBirth | |

|Printer.Print Tab(5); strName; Tab(25); strBirth | |

|Loop | |

|Close #1 | |

|Printer.Print 'print two blank lines | |

|Printer.Print | |

|Printer.Print Tab(5); "End of report" 'print message | |

|Printer.EndDoc 'send report to printer | |

|Printer.Font = strFont | |

|Printer.FontSize = sngSize | |

|End Sub | |

| | |

|Private Sub cmdRecord_Click() | |

|Dim intUser As Integer | |

|Const conBtns As String = _ | |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal | |

|If strFound = "Y" Then | |

|Open "a:\tut06\la8.dat" For Append As #1 | |

|Write #1, txtName.Text, txtAddress.Text, lblCity.Caption, _ | |

|txtZip.TabIndex, txtBirthday.Text | |

|Close #1 | |

|Else | |

|intUser = MsgBox("Record not written.", conBtns, "Zip Code Error") | |

|End If | |

|txtName.SetFocus | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

| = (Screen.Height - frmJonas.Height) / 2 | |

|frmJonas.Left = (Screen.Width - frmJonas.Width) / 2 | |

|strFound = "N" | |

|End Sub | |

|Private Sub Form_Unload(Cancel As Integer) |

|Dim intUser As Integer |

|Const conBtns As Integer = _ |

|vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal |

|intUser = MsgBox("Do you want to exit?", conBtns, "Dr. Jonas") |

|If intUser = vbNo Then |

|Cancel = 1 |

|End If |

|End Sub |

| |

|Private Sub txtAddress_GotFocus() |

|txtAddress.SelStart = 0 |

|txtAddress.SelLength = Len(txtAddress.Text) |

|End Sub |

| |

|Private Sub txtBirthday_GotFocus() |

|txtBirthday.SelStart = 0 |

|txtBirthday.SelLength = Len(txtBirthday.Text) |

|End Sub |

| |

|Private Sub txtName_GotFocus() |

|txtName.SelStart = 0 |

|txtName.SelLength = Len(txtName.Text) |

|End Sub |

| |

|Private Sub txtZip_GotFocus() |

|txtZip.SelStart = 0 |

|txtZip.SelLength = Len(txtZip.Text) |

|End Sub |

| |

|Private Sub txtZip_LostFocus() |

|Dim strCity As String, strZip As String, intUser As Integer |

|Const conBtns As String = _ |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|strFound = "N" |

|If txtZip.Text "" Then |

|Open "a:\tut06\la8Zip.dat" For Input As #1 |

|Do While Not EOF(1) And strFound = "N" |

|Input #1, strCity, strZip |

|If txtZip.Text = strZip Then |

|lblCity.Caption = strCity |

|strFound = "Y" |

|End If |

|Loop |

|Close #1 |

|If strFound = "N" Then |

|intUser = MsgBox("Incorrect zip code", conBtns, "Zip Code Search") |

|lblCity.Caption = "" |

|txtZip.SetFocus |

|End If |

|End If |

|End Sub |

9. (Discovery) la9Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

[pic]

|Option Explicit |Private Sub Form_Load() |

| | = (Screen.Height - frmElements.Height) / 2 |

|Private Sub cmdExit_Click() |frmElements.Left = (Screen.Width - frmElements.Width) / 2 |

|Unload frmElements |lstElements.AddItem "Cloud" |

|End Sub |lstElements.AddItem "Rain" |

| |lstElements.AddItem "Snow" |

|Private Sub cmdPrint_Click() |lstElements.AddItem "Sun" |

|PrintForm |lstElements.AddItem "Lightning" |

|End Sub |lstElements.ListIndex = 0 |

| |End Sub |

| | |

| |Private Sub lstElements_Click() |

| |imgElement.Picture = imgIcons(lstElements.ListIndex).Picture |

| |End Sub |

10. (Discovery) la10Done project – The student should submit a printout of the code for the Display Totals (cmdDisplay) and New File (cmdNew) buttons’ Click event. Changes made to the original code are shaded.

|Private Sub cmdDisplay_Click() | |

|Dim strParty As String, intAge As Integer, intCount As Integer | |

|Dim intUser As Integer | |

|Const conBtns As String = _ | |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal | |

|For intCount = 0 To 3 'clear the label controls | |

|lblDem(intCount).Caption = "" | |

|lblRep(intCount).Caption = "" | |

|lblInd(intCount).Caption = "" | |

|Next intCount | |

|If Dir("a:\tut06\pao.dat") "" Then | |

|Open "a:\tut06\pao.dat" For Input As #1 'open the sequential file | |

|Do While Not EOF(1) | |

|Input #1, strParty, intAge 'read a record | |

|Select Case strParty 'update appropriate label control | |

|Case "Democrat" | |

|lblDem(intAge).Caption = Val(lblDem(intAge).Caption) + 1 | |

|Case "Republican" | |

|lblRep(intAge).Caption = Val(lblRep(intAge).Caption) + 1 | |

|Case "Independent" | |

|lblInd(intAge).Caption = Val(lblInd(intAge).Caption) + 1 | |

|End Select | |

|Loop | |

|Close #1 'close the file | |

|Else | |

|intUser = MsgBox("The file does not exist.", conBtns, "PAO") | |

|End If | |

|End Sub | |

| | |

|Private Sub cmdNew_Click() | |

|Dim intUser As Integer | |

|Const conBtns1 As String = _ | |

|vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal | |

|Const conBtns2 As String = _ | |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal | |

|Const conMsg1 As String = "Are you sure you want to delete the file?" | |

|Const conMsg2 As String = "File was deleted." | |

|Const conMsg3 As String = "File does not exist." | |

|Const conMsg4 As String = "File was not deleted." | |

| | |

|intUser = MsgBox(conMsg1, conBtns1, "Delete File") | |

|If intUser = vbYes Then | |

|If Dir("a:\tut06\pao.dat") "" Then | |

|Kill "a:\tut06\pao.dat" 'delete file | |

|intUser = MsgBox(conMsg2, conBtns2, "Delete File") | |

|Else 'file does not exist | |

|intUser = MsgBox(conMsg3, conBtns2, "Delete File") | |

|End If | |

|Else 'don't delete file | |

|intUser = MsgBox(conMsg4, conBtns2, "Delete File") | |

|End If | |

|End Sub | |

11. (Discovery) la11Done project – The student should submit written explanations to steps b and j, as well as two printouts of the code.

|step b: |

|The three settings of a list box’s MultiSelect property are as follows: |

|(Default) Multiple selection is not allowed |

|Simple multiple selection. A click or the spacebar selects or deselects an item in the list. You also can use Ctrl+click|

|or Shift+click to select or deselect an item. |

|Extended multiple selection. Use Ctrl+click to select or deselect an item. Use Shift+click or Shift+arrow to extend the |

|selection from the previously selected item to the current item. |

| |

|step j: |

|A list box’s Selected property stores the selection status of an item in a list box. This property is an array of |

|Boolean values with the same number of items as the List property array. The Selected property array allows you to |

|quickly check which items in a list are selected. You also can use this property array to select or deselect items in a |

|list from code. |

| |

|A list box’s List property stores the items contained in a list box’s list portion. This property is an array of strings|

|in which each element is a list item. You can use the List property array to access the list box items. |

|step h code: |step p code: |

|Option Explicit |Option Explicit |

| | |

|Private Sub Command1_Click() |Private Sub Command1_Click() |

|Print List1.Text |Dim intX As Integer |

|End Sub |For intX = 0 To List1.ListCount - 1 |

| |If List1.Selected(intX) = True Then |

|Private Sub Form_Load() |Print List1.List(intX) |

|List1.AddItem "Ahmad" |End If |

|List1.AddItem "Jim" |Next intX |

|List1.AddItem "Debbie" |End Sub |

|List1.AddItem "Jeanne" | |

|List1.AddItem "Bill" |Private Sub Form_Load() |

|End Sub |List1.AddItem "Ahmad" |

| |List1.AddItem "Jim" |

| |List1.AddItem "Debbie" |

| |List1.AddItem "Jeanne" |

| |List1.AddItem "Bill" |

| |End Sub |

12. (Discovery) la12Done project – The student should submit four printouts of the la12act.dat and la12inac.dat files and a printout of the code.

|la12act.dat file (step b): |la12inac.dat file (step b): |

|"Smith, Joe" |"Kendry, Paul" |

|"Jones, Mary" |"Yelton, Bob" |

|"Adkari, Joel" |"Patel, Suman" |

|"Lin, Sue" |"Patel, Mamta" |

|"Li, Vicky" |"Lee, Janice" |

|"Patel, Orman" |"Jones, Scotty" |

|"White, Pam" | |

|"Abram, Jill" | |

|"Chen, Sue" | |

|"Dune, Joe" | |

|"Willard, Tom" | |

|"Krisen, Jerry" | |

| | |

|la12act.dat file (step l): |la12inac.dat file (step l): |

|"Abram, Jill" |"Jones, Scotty" |

|"Adkari, Joel" |"Kendry, Paul" |

|"Chen, Sue" |"Krisen, Jerry" |

|"Dune, Joe" |"Lee, Janice" |

|"Jones, Mary" |"Patel, Mamta" |

|"Li, Vicky" |"Patel, Suman" |

|"Lin, Sue" |"Willard, Tom" |

|"Patel, Orman" |"Yelton, Bob" |

|"Smith, Joe" | |

|"White, Pam" | |

| | |

|la12act.dat file (step n): |la12inac.dat file (step n): |

|"Abram, Jill" |"Jones, Scotty" |

|"Adkari, Joel" |"Kendry, Paul" |

|"Chen, Sue" |"Krisen, Jerry" |

|"Dune, Joe" |"Lee, Janice" |

|"Jones, Mary" |"Patel, Mamta" |

|"Li, Vicky" |"Patel, Suman" |

|"Lin, Sue" |"Yelton, Bob" |

|"Patel, Orman" | |

|"Smith, Joe" | |

|"White, Pam" | |

|"Willard, Tom" | |

| | |

|la12act.dat file (step q): |la12inac.dat file (step q): |

|"Abram, Jill" |"Kendry, Paul" |

|"Adkari, Joel" |"Lee, Janice" |

|"Chen, Sue" |"Patel, Mamta" |

|"Dune, Joe" |"Patel, Suman" |

|"Jones, Mary" |"Yelton, Bob" |

|"Li, Vicky" | |

|"Lin, Sue" | |

|"Patel, Orman" | |

|"Smith, Joe" | |

|"White, Pam" | |

|"Willard, Tom" | |

|Option Explicit |Private Sub Form_Load() |

| |Dim strName As String |

|Private Sub cmdExit_Click() | = (Screen.Height – frmAbc.Height) / 2 |

|Unload frmAbc |frmAbc.Left = (Screen.Width - frmAbc.Width) / 2 |

|End Sub |Open "a:\tut06\la12act.dat" For Input As #1 |

| |Do While Not EOF(1) |

|Private Sub cmdInactive_Click() |Input #1, strName |

|Dim intX As Integer |lstActive.AddItem strName |

|Do While intX < lstActive.ListCount |Loop |

|If lstActive.Selected(intX) = True Then |Close #1 |

|lstInactive.AddItem lstActive.List(intX) |Open "a:\tut06\la12inac.dat" For Input As #1 |

|lstActive.RemoveItem intX |Do While Not EOF(1) |

|Else |Input #1, strName |

|intX = intX + 1 |lstInactive.AddItem strName |

|End If |Loop |

|Loop |Close #1 |

|End Sub |End Sub |

| | |

|Private Sub cmdReactivate_Click() |Private Sub Form_Unload(Cancel As Integer) |

|Dim intX As Integer |Dim intX As Integer |

|Do While intX < lstInactive.ListCount |Open "a:\tut06\la12act.dat" For Output As #1 |

|If lstInactive.Selected(intX) = True Then |Open "a:\tut06\la12inac.dat" For Output As #2 |

|lstActive.AddItem lstInactive.List(intX) |For intX = 0 To lstActive.ListCount - 1 |

|lstInactive.RemoveItem intX |Write #1, lstActive.List(intX) |

|Else |Next intX |

|intX = intX + 1 |Close #1 |

|End If |For intX = 0 To lstInactive.ListCount - 1 |

|Loop |Write #2, lstInactive.List(intX) |

|End Sub |Next intX |

| |Close #2 |

|Private Sub cmdRemove_Click() |End Sub |

|Dim intX As Integer | |

|Do While intX < lstInactive.ListCount | |

|If lstInactive.Selected(intX) = True Then | |

|lstInactive.RemoveItem intX | |

|Else | |

|intX = intX + 1 | |

|End If | |

|Loop | |

|End Sub | |

13. (Discovery) la13Done project – The student should submit two printouts of the multiplication table and a printout of the code.

|Multiplication Table |Multiplication Table | |

| | | |

|1 X 5 = 5 |1 X 9 = 9 | |

|2 X 5 = 10 |2 X 9 = 18 | |

|3 X 5 = 15 |3 X 9 = 27 | |

|4 X 5 = 20 |4 X 9 = 36 | |

|5 X 5 = 25 |5 X 9 = 45 | |

|6 X 5 = 30 |6 X 9 = 54 | |

|7 X 5 = 35 |7 X 9 = 63 | |

|8 X 5 = 40 |8 X 9 = 72 | |

|9 X 5 = 45 |9 X 9 = 81 | |

| | | |

|End of report |End of report | |

|Option Explicit | |

| | |

|Private Sub cmdExit_Click() | |

|Unload frmTable | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|Dim intX As Integer, intNum As Integer, strFont As String, sngSize As Single | |

|Dim strPS1 As String * 5 | |

| | |

|intNum = Val(txtNum.Text) 'assign user input to a variable | |

|strFont = Printer.Font 'save current printer settings | |

|sngSize = Printer.FontSize | |

|Printer.Font = "courier new" 'change printer settings | |

|Printer.FontSize = 12 | |

|Printer.Print Tab(10); "Multiplication Table" | |

|Printer.Print | |

|For intX = 1 To 9 | |

|'align product and print | |

|RSet strPS1 = Format(intX * intNum, "general number") | |

|Printer.Print Tab(9); intX; Tab(15); "X"; Tab(18); intNum; _ | |

|Tab(25); "="; strPS1 | |

|Next intX | |

|Printer.Print 'print two blank lines | |

|Printer.Print | |

|Printer.Print Tab(10); "End of report" 'print message | |

|Printer.EndDoc 'send report to printer | |

|Printer.Font = strFont | |

|Printer.FontSize = sngSize | |

|txtNum.SetFocus | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmTable.Left = (Screen.Width - frmTable.Width) / 2 | |

| = (Screen.Height - frmTable.Height) / 2 | |

|End Sub | |

| | |

|Private Sub txtNum_Change() | |

|If txtNum.Text = "" Then | |

|cmdPrint.Enabled = False | |

|Else | |

|cmdPrint.Enabled = True | |

|End If | |

|End Sub | |

| | |

|Private Sub txtNum_GotFocus() | |

|txtNum.SelStart = 0 | |

|txtNum.SelLength = Len(txtNum.Text) | |

|End Sub | |

14. (Discovery) la14Done project – The student should submit a printout of the three columns of numbers and a printout of the code.

| 564 777 909 |Option Explicit |

|4,500 888 9 | |

|4 59 34,556 |Private Sub cmdExit_Click() |

| |Unload frmFormat |

| |End Sub |

| | |

| |Private Sub cmdPrint_Click() |

| |Const conPFormat As String = "##,###" |

| |Dim strPS1 As String * 8, strPS2 As String * 8, strPS3 As String * 8 |

| |Dim strFont As String, sngSize As Single |

| |strFont = Printer.Font 'save current printer settings |

| |sngSize = Printer.FontSize |

| |Printer.Font = "courier new" 'change printer settings |

| |Printer.FontSize = 12 |

| |RSet strPS1 = Format(564, conPFormat) |

| |RSet strPS2 = Format(777, conPFormat) |

| |RSet strPS3 = Format(909, conPFormat) |

| |Printer.Print strPS1; Tab(10); strPS2; Tab(20); strPS3 |

| |RSet strPS1 = Format(4500, conPFormat) |

| |RSet strPS2 = Format(888, conPFormat) |

| |RSet strPS3 = Format(9, conPFormat) |

| |Printer.Print strPS1; Tab(10); strPS2; Tab(20); strPS3 |

| |RSet strPS1 = Format(4, conPFormat) |

| |RSet strPS2 = Format(59, conPFormat) |

| |RSet strPS3 = Format(34556, conPFormat) |

| |Printer.Print strPS1; Tab(10); strPS2; Tab(20); strPS3 |

| |Printer.EndDoc |

| |Printer.Font = strFont |

| |Printer.FontSize = sngSize |

| |End Sub |

Tutorial 6, Lesson B

Questions

1. d Resize

2. c ScaleWidth, Width

3. c form’s Resize

4. a,d Height, Width

5. b,c ScaleHeight,ScaleWidth

6. a,c Caption, Name

7. b Click

8. b menu titles

9. e separator bar

10. c hyphen

11. a access

12. e shortcut

13. a ampersand (&)

14. e If a menu title requires additional information from the user, follow the menu title’s name with an ellipsis (…).

15. a Menu items, which can be from one to three words, should be entered using sentence capitalization.

16. a Clipboard.Clear

17. d Clipboard.SetText “Hello”

18. b lblMsg.Caption = Clipboard.GetText()

19. b SelText

20. a GetText()

21. c Enabled

22. b MultiLine

23. c ScrollBars

24. b MultiLine

Exercises

1. lb1Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

[pic]

|Option Explicit | |

| | |

|Private Sub cmdDisplay_Click() | |

|Dim intP1 As Integer, intP2 As Integer, strGrade As String | |

|Dim intMid As Integer, intFinal As Integer, intSum As Integer | |

|intP1 = Val(txtP1.Text) | |

|intP2 = Val(txtP2.Text) | |

|intMid = Val(txtMid.Text) | |

|intFinal = Val(txtFinal.Text) | |

|intSum = intP1 + intP2 + intMid + intFinal | |

|Select Case intSum | |

|Case Is >= 270 | |

|strGrade = "A" | |

|Case Is >= 240 | |

|strGrade = "B" | |

|Case Is >= 210 | |

|strGrade = "C" | |

|Case Is >= 180 | |

|strGrade = "D" | |

|Case Else | |

|strGrade = "F" | |

|End Select | |

|lblGrade.Caption = strGrade | |

|txtName.SetFocus | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmGrade.Left = (Screen.Width – frmGrade.Width) / 2 | |

| = (Screen.Height – frmGrade.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmGrade | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

| | |

|Private Sub txtFinal_GotFocus() |Private Sub txtP1_GotFocus() |

|txtFinal.SelStart = 0 |txtP1.SelStart = 0 |

|txtFinal.SelLength = Len(txtFinal.Text) |txtP1.SelLength = Len(txtP1.Text) |

|End Sub |End Sub |

| | |

|Private Sub txtMid_GotFocus() |Private Sub txtP2_GotFocus() |

|txtMid.SelStart = 0 |txtP2.SelStart = 0 |

|txtMid.SelLength = Len(txtMid.Text) |txtP2.SelLength = Len(txtP2.Text) |

|End Sub |End Sub |

| | |

|Private Sub txtName_GotFocus() | |

|txtName.SelStart = 0 | |

|txtName.SelLength = Len(txtName.Text) | |

|End Sub | |

2. lb2Done project – The student should submit two printouts of the interface with the test data showing and a printout of the code.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |Private Sub mnuFileClear_Click() |

| |txtName.Text = "" |

|Private Sub Form_Load() |txtTrade.Text = "" |

| = (Screen.Height - frmVenus.Height) / 2 |lblSub.Caption = "" |

|frmVenus.Left = (Screen.Width - frmVenus.Width) / 2 |lblTax.Caption = "" |

|optModel(0).Value = True |lblTotal.Caption = "" |

|optPkg(0).Value = True |End Sub |

|End Sub | |

| |Private Sub mnuFileExit_Click() |

|Private Sub mnuCompute5_Click() |Unload frmVenus |

|Dim sngBase As Single, sngPkg As Single, sngTrade As Single |End Sub |

|Dim sngSub As Single, sngTax As Single, sngTotal As Single | |

|sngBase = Val(lblBase.Caption) |Private Sub mnuFilePrintNologo_Click()|

|sngPkg = Val(lblPkg.Caption) |imgLogo.Visible = False |

|sngTrade = Val(txtTrade.Text) |PrintForm |

|sngSub = sngBase + sngPkg – sngTrade |imgLogo.Visible = True |

|sngTax = sngSub * 0.05 |End Sub |

|sngTotal = sngSub + sngTax | |

|lblSub.Caption = sngSub | |

|lblTax.Caption = sngTax | |

|lblTotal.Caption = sngTotal | |

|End Sub | |

| | |

|Private Sub mnuCompute7_Click() | |

|Dim sngBase As Single, sngPkg As Single, sngTrade As Single | |

|Dim sngSub As Single, sngTax As Single, sngTotal As Single | |

|sngBase = Val(lblBase.Caption) | |

|sngPkg = Val(lblPkg.Caption) | |

|sngTrade = Val(txtTrade.Text) | |

|sngSub = sngBase + sngPkg – sngTrade | |

|sngTax = sngSub * 0.07 | |

|sngTotal = sngSub + sngTax | |

|lblSub.Caption = sngSub | |

|lblTax.Caption = sngTax | |

|lblTotal.Caption = sngTotal | |

|End Sub | |

|Private Sub optModel_Click(Index As Integer) |Private Sub mnuFilePrintWithlogo_Click() |

|Select Case Index |PrintForm |

|Case 0 |End Sub |

|lblBase.Caption = 10500 | |

|Case 1 |Private Sub txtName_GotFocus() |

|lblBase.Caption = 21000 |txtName.SelStart = 0 |

|Case 2 |txtName.SelLength = Len(txtName.Text) |

|lblBase.Caption = 15500 |End Sub |

|End Select | |

|lblSub.Caption = "" |Private Sub txtTrade_Change() |

|lblTax.Caption = "" |lblSub.Caption = "" |

|lblTotal.Caption = "" |lblTax.Caption = "" |

|End Sub |lblTotal.Caption = "" |

| |End Sub |

|Private Sub optPkg_Click(Index As Integer) | |

|If Index = 0 Then |Private Sub txtTrade_GotFocus() |

|lblPkg.Caption = 2000 |txtTrade.SelStart = 0 |

|Else |txtTrade.SelLength = Len(txtTrade.Text) |

|lblPkg.Caption = 3000 |End Sub |

|End If | |

|lblSub.Caption = "" | |

|lblTax.Caption = "" | |

|lblTotal.Caption = "" | |

|End Sub | |

3. (Discovery) lb3Adone and lb3Bdone projects – The student should submit two printouts of the code.

|lb3Adone.frm |lb3Bdone.frm |

|Option Explicit |Option Explicit |

| | |

|Private Sub Form_Load() |Private Sub Form_Load() |

| = (Screen.Height – frmTrans.Height) / 2 | = (Screen.Height – frmTrans.Height) / 2 |

|frmTrans.Left = (Screen.Width – frmTrans.Width) / 2 |frmTrans.Left = (Screen.Width – frmTrans.Width) / 2 |

|End Sub |End Sub |

| | |

|Private Sub mnuDisplayBicycle_Click() |Private Sub mnuDisplayBicycle_Click() |

|lblBike.Visible = True |lblBike.Visible = Not lblBike.Visible |

|imgBike.Visible = True |imgBike.Visible = Not imgBike.Visible |

|lblRocket.Visible = False |mnuDisplayBicycle.Checked = Not mnuDisplayBicycle.Checked |

|imgRocket.Visible = False |End Sub |

|mnuDisplayBicycle.Checked = True | |

|mnuDisplayRocket.Checked = False |Private Sub mnuDisplayRocket_Click() |

|End Sub |lblRocket.Visible = Not lblRocket.Visible |

| |imgRocket.Visible = Not imgRocket.Visible |

|Private Sub mnuDisplayRocket_Click() |mnuDisplayRocket.Checked = Not mnuDisplayRocket.Checked |

|lblRocket.Visible = True |End Sub |

|imgRocket.Visible = True | |

|lblBike.Visible = False | |

|imgBike.Visible = False | |

|mnuDisplayRocket.Checked = True | |

|mnuDisplayBicycle.Checked = False | |

|End Sub | |

4. (Discovery) lb4Done project – The student should submit a printout of the code. Changes to the original code are shaded.

|Option Explicit |Private Sub mnuFilePrintNologo_Click() |

|Private Sub Form_Load() |imgLogo.Visible = False |

| = (Screen.Height – frmVenus.Height) / 2 |PrintForm |

|frmVenus.Left = (Screen.Width – frmVenus.Width) / 2 |imgLogo.Visible = True |

|optModel(0).Value = True |End Sub |

|optPkg(0).Value = True | |

|End Sub |Private Sub mnuFilePrintWithlogo_Click() |

| |PrintForm |

|Private Sub mnuCompute5_Click() |End Sub |

|Dim sngBase As Single, sngPkg As Single, sngTrade As Single | |

|Dim sngSub As Single, sngTax As Single, sngTotal As Single |Private Sub optModel_Click(Index As Integer) |

|sngBase = Val(lblBase.Caption) |Select Case Index |

|sngPkg = Val(lblPkg.Caption) |Case 0 |

|sngTrade = Val(txtTrade.Text) |lblBase.Caption = 10500 |

|sngSub = sngBase + sngPkg - sngTrade |Case 1 |

|sngTax = sngSub * 0.05 |lblBase.Caption = 21000 |

|sngTotal = sngSub + sngTax |Case 2 |

|lblSub.Caption = sngSub |lblBase.Caption = 15500 |

|lblTax.Caption = sngTax |End Select |

|lblTotal.Caption = sngTotal |Call Clear |

|End Sub |End Sub |

| | |

|Private Sub mnuCompute7_Click() |Private Sub optPkg_Click(Index As Integer) |

|Dim sngBase As Single, sngPkg As Single, sngTrade As Single |If Index = 0 Then |

|Dim sngSub As Single, sngTax As Single, sngTotal As Single |lblPkg.Caption = 2000 |

|sngBase = Val(lblBase.Caption) |Else |

|sngPkg = Val(lblPkg.Caption) |lblPkg.Caption = 3000 |

|sngTrade = Val(txtTrade.Text) |End If |

|sngSub = sngBase + sngPkg - sngTrade |Call Clear |

|sngTax = sngSub * 0.07 |End Sub |

|sngTotal = sngSub + sngTax | |

|lblSub.Caption = sngSub |Private Sub txtName_GotFocus() |

|lblTax.Caption = sngTax |txtName.SelStart = 0 |

|lblTotal.Caption = sngTotal |txtName.SelLength = Len(txtName.Text) |

|End Sub |End Sub |

| | |

|Private Sub mnuFileClear_Click() |Private Sub txtTrade_Change() |

|txtName.Text = "" |Call Clear |

|txtTrade.Text = "" |End Sub |

|Call Clear | |

|End Sub |Private Sub txtTrade_GotFocus() |

| |txtTrade.SelStart = 0 |

|Private Sub mnuFileExit_Click() |txtTrade.SelLength = Len(txtTrade.Text) |

|Unload frmVenus |End Sub |

|End Sub | |

| |Private Sub Clear() |

| |lblSub.Caption = "" |

| |lblTax.Caption = "" |

| |lblTotal.Caption = "" |

| |End Sub |

Tutorial 6, Lesson C

Questions

1. b,c Left, Mid

2. c,d Mid Right

3. c Mid

4. d Ha

5. c ay

6. c lcom

7. b Mid(strName, 1, 3)

8. d Mid(strName, 11, 3)

9. a 0

10. c 17

11. c 17

12. a 0

13. d SelStart

14. a 9

Exercises

1. Mary

th

B

ck

2. n

Califo

ornia

lifor

3. lc3Done project – The student should submit two printouts of the interface with the test data showing, as well as a printout of the code. On the first printout, the student should record the error messages from step e. The student may use a File menu with Print and Exit options rather than command buttons. The error messages may vary.

Printout #1: Printout #2:

[pic] [pic]

Error messages from step e: “Incorrect status” and “Incorrect type”

|Option Explicit | |

|Private Sub cmdDisplay_Click() | |

|Dim strStatus As String, strInitials As String, strType As String | |

|Dim intUser As Integer | |

|Const conBtns As Integer = _ | |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal | |

|strStatus = UCase(Left(txtId.Text, 1)) | |

|strInitials = Mid(txtId.Text, 2, 2) | |

|strType = Right(txtId.Text, 1) | |

|Select Case strStatus | |

|Case "F" | |

|lblStatus.Caption = "Full-time" | |

|Case "P" | |

|lblStatus.Caption = "Part-time" | |

|Case Else | |

|lblStatus.Caption = "" | |

|intUser = MsgBox("Incorrect status", conBtns, "BobCat Motors") | |

|End Select | |

|Select Case strType | |

|Case "1" | |

|lblType.Caption = "New" | |

|Case "2" | |

|lblType.Caption = "Used" | |

|Case Else | |

|lblType.Caption = "" | |

|intUser = MsgBox("Incorrect type", conBtns, "BobCat Motors") | |

|End Select | |

|lblInitials.Caption = strInitials | |

|txtId.SetFocus | |

|End Sub | |

|Private Sub cmdExit_Click() |Private Sub txtId_Change() |

|Unload frmBobCat |lblStatus.Caption = "" |

|End Sub |lblInitials.Caption = "" |

| |lblType.Caption = "" |

|Private Sub cmdPrint_Click() |End Sub |

|PrintForm | |

|End Sub |Private Sub txtId_GotFocus() |

| |txtId.SelStart = 0 |

|Private Sub Form_Load() |txtId.SelLength = Len(txtId.Text) |

|frmBobCat.Left = (Screen.Width – frmBobCat.Width) / 2 |End Sub |

| = (Screen.Height – frmBobCat.Height) / 2 | |

|End Sub | |

4. lc4Done project – The student should submit two printouts of the interface with the test data showing, as well as a printout of the code. On the first printout, the student should record the error messages from step e. The student may use a File menu with Print and Exit options rather than command buttons. The error messages may vary.

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit | |

| | |

|Private Sub cmdDisplay_Click() | |

|Dim strStatus As String, intUser As Integer | |

|Const conBtns As Integer = _ | |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal | |

|strStatus = Mid(txtNumber.Text, 2, 1) | |

|Select Case strStatus | |

|Case "1" | |

|lblStatus.Caption = "Salaried" | |

|Case "2" | |

|lblStatus.Caption = "Hourly" | |

|Case Else | |

|lblStatus.Caption = "" | |

|intUser = MsgBox("Incorrect status", conBtns, "BobCat Motors") | |

|End Select | |

|txtNumber.SetFocus | |

|End Sub | |

| | |

|Private Sub cmdExit_Click() | |

|Unload frmAcme | |

|End Sub | |

| | |

|Private Sub cmdPrint_Click() | |

|PrintForm | |

|End Sub | |

|Private Sub Form_Load() |Private Sub txtNumber_GotFocus() |

|frmAcme.Left = (Screen.Width – frmAcme.Width) / 2 |txtNumber.SelStart = 0 |

| = (Screen.Height – frmAcme.Height) / 2 |txtNumber.SelLength = Len(txtNumber.Text) |

|End Sub |End Sub |

| | |

|Private Sub txtNumber_Change() | |

|lblStatus.Caption = "" | |

|End Sub | |

5. lc5Done project – The student should submit a printout of the lc5.dat file, two printouts of the interface with the test data showing, and a printout of the application’s code.

|"BDX22",100 | |

|"ABC11",150 | |

|"BDX22",250 | |

|"CVA33",100 | |

|"ABC11",300 | |

Printout #1: Printout #2:

[pic] [pic]

|Option Explicit |

| |

|Private Sub Form_Load() |

| = (Screen.Height – frmComputer.Height) / 2 |

|frmComputer.Left = (Screen.Width – frmComputer.Width) / 2 |

|lstItem.AddItem "ABC11" |

|lstItem.AddItem "CVA33" |

|lstItem.AddItem "BDX22" |

|lstItem.ListIndex = 0 |

|End Sub |

| |

|Private Sub mnuFileExit_Click() |

|Unload frmComputer |

|End Sub |

| |

|Private Sub mnuFilePrint_Click() |

|PrintForm |

|End Sub |

| |

|Private Sub mnuStatisticsItem_Click() |

|Dim strChoice As String, strItem As String, intSold As Integer, intTotal As Integer |

|strChoice = UCase(lstItem.Text) |

|Open "a:\tut06\lc5.dat" For Input As #1 |

|Do While Not EOF(1) |

|Input #1, strItem, intSold |

|If UCase(strItem) = strChoice Then |

|intTotal = intTotal + intSold |

|End If |

|Loop |

|Close #1 |

|lblTotal.Caption = "The total number sold for item " & _ |

|strChoice & " is " & intTotal & "." |

|End Sub |

| |

|Private Sub mnuStatisticsTotal_Click() |

|Dim strItem As String, intSold As Integer, intTotal As Integer |

|Open "a:\tut06\lc5.dat" For Input As #1 |

|Do While Not EOF(1) |

|Input #1, strItem, intSold |

|intTotal = intTotal + intSold |

|Loop |

|Close #1 |

|lblTotal.Caption = "The total number sold is " & intTotal & "." |

|End Sub |

6. lc6Done project – The student should submit two printouts of the report, as well as a printout of the code.

Printout #1: Printout #2:

Computer Warehouse Computer Warehouse

Item Sold Item Sold

BDX22 100 BDX22 100

ABC11 150 BDX22 250

BDX22 250 BDX22 200

CVA33 100 BDX22 120

ABC11 300

BDX22 200 Total records: 4

ABC11 140

BDX22 120 End of report

CVA33 110

ABC11 500

Total records: 10

End of report

|Option Explicit |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmComputer.Height) / 2 |

|frmComputer.Left = (Screen.Width - frmComputer.Width) / 2 |

|lstItem.AddItem "ABC11" |

|lstItem.AddItem "CVA33" |

|lstItem.AddItem "BDX22" |

|lstItem.ListIndex = 0 |

|End Sub |

| |

|Private Sub mnuFileExit_Click() |

|Unload frmComputer |

|End Sub |

|Private Sub mnuPrintAll_Click() |

|Dim strItem As String, intSold As Integer, intNumRecs As Integer |

|Dim strFont As String, sngSize As Single |

|Dim strPS1 As String * 5 |

|strFont = Printer.Font 'save current printer settings |

|sngSize = Printer.FontSize |

|Printer.Font = "courier new" 'change printer settings |

|Printer.FontSize = 12 |

|Printer.Print Tab(10); "Computer Warehouse" |

|Printer.Print |

|Printer.Print Tab(10); "Item"; Tab(26); "Sold" |

|Printer.Print |

|Open "a:\tut06\lc6.dat" For Input As #1 |

|Do While Not EOF(1) |

|Input #1, strItem, intSold |

|intNumRecs = intNumRecs + 1 |

|RSet strPS1 = Format(intSold, "general number") |

|Printer.Print Tab(10); strItem; Tab(25); strPS1 |

|Loop |

|Close #1 |

|Printer.Print 'print two blank lines |

|Printer.Print |

|'print grand total |

|Printer.Print Tab(10); "Total records: " & intNumRecs |

|Printer.Print |

|Printer.Print Tab(10); "End of report" 'print message |

|Printer.EndDoc 'send report to printer |

|Printer.Font = strFont |

|Printer.FontSize = sngSize |

|End Sub |

|Private Sub mnuPrintItem_Click() |

|Dim strItem As String, intSold As Integer, intNumRecs As Integer |

|Dim strChoice As String, strFont As String, sngSize As Single |

|Dim strPS1 As String * 5 |

|strChoice = UCase(lstItem.Text) |

|strFont = Printer.Font 'save current printer settings |

|sngSize = Printer.FontSize |

|Printer.Font = "courier new" 'change printer settings |

|Printer.FontSize = 12 |

|Printer.Print Tab(10); "Computer Warehouse" |

|Printer.Print |

|Printer.Print Tab(10); "Item"; Tab(26); "Sold" |

|Printer.Print |

|Open "a:\tut06\lc6.dat" For Input As #1 |

|Do While Not EOF(1) |

|Input #1, strItem, intSold |

|If UCase(strItem) = strChoice Then |

|intNumRecs = intNumRecs + 1 |

|RSet strPS1 = Format(intSold, "general number") |

|Printer.Print Tab(10); strItem; Tab(25); strPS1 |

|End If |

|Loop |

|Close #1 |

|Printer.Print 'print two blank lines |

|Printer.Print |

|'print grand total |

|Printer.Print Tab(10); "Total records: " & intNumRecs |

|Printer.Print |

|Printer.Print Tab(10); "End of report" 'print message |

|Printer.EndDoc 'send report to printer |

|Printer.Font = strFont |

|Printer.FontSize = sngSize |

|End Sub |

7. (Discovery) lc7Done project – The student should submit the application’s code. The student will need to set the txtEdit control’s HideSelection property to False. Changes to the original code are shaded.

|lc7Done.frm |

|Option Explicit |

|Dim strSearchFor As String |

| |

|Private Sub Form_Resize() |

|txtEdit.Height = frmEdit.ScaleHeight |

|txtEdit.Width = frmEdit.ScaleWidth |

|End Sub |

| |

|Private Sub mnuEdit_Click() |

|If txtEdit.SelText = "" Then 'if no text is selected |

|mnuEditCut.Enabled = False |

|mnuEditCopy.Enabled = False |

|Else 'if some text is selected |

|mnuEditCut.Enabled = True |

|mnuEditCopy.Enabled = True |

|End If |

|If Clipboard.GetText() = "" Then 'if no text is on the clipboard |

|mnuEditPaste.Enabled = False |

|Else 'if some text is on the clipboard |

|mnuEditPaste.Enabled = True |

|End If |

|End Sub |

| |

|Private Sub mnuEditCopy_Click() |

|Clipboard.Clear 'clear clipboard |

|Clipboard.SetText txtEdit.SelText 'send text to clipboard |

|End Sub |

| |

|Private Sub mnuEditCut_Click() |

|Clipboard.Clear 'clear clipboard |

|Clipboard.SetText txtEdit.SelText 'send text to clipboard |

|txtEdit.SelText = "" 'remove selected text from text box |

|End Sub |

| |

|Private Sub mnuEditFind_Click() |

|strNewSearch = "Y" |

|frmFind.txtFind.Text = "" |

|frmFind.Show |

|frmFind.txtFind.SetFocus |

|End Sub |

| |

|Private Sub mnuEditPaste_Click() |

|'retrieve text from clipboard and paste into text box |

|txtEdit.SelText = Clipboard.GetText() |

|End Sub |

| |

|Private Sub mnuFileExit_Click() |

|Unload frmEdit |

|End Sub |

|lc7Find.frm |

|Option Explicit |

| |

|Private Sub cmdFindNext_Click() |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Const conMsg As String = "The search has been completed." |

|Dim intRetVal As Integer, strSearchFor As String |

|Dim intFoundPos As Integer, intBegSearch As Integer |

|strSearchFor = txtFind.Text |

|If strNewSearch = "Y" Then |

|intBegSearch = 1 |

|strNewSearch = "N" |

|Else |

|intBegSearch = frmEdit.txtEdit.SelStart + 2 |

|End If |

|intFoundPos = InStr(intBegSearch, frmEdit.txtEdit.Text, strSearchFor, 1) |

|If intFoundPos = 0 Then 'if text was not found |

|intRetVal = MsgBox(conMsg, conBtns, "Find Next") |

|Unload frmFind |

|Else 'if text was found |

|frmEdit.txtEdit.SelStart = intFoundPos - 1 'highlight text |

|frmEdit.txtEdit.SelLength = Len(strSearchFor) |

|End If |

|End Sub |

| |

|Private Sub cmdCancel_Click() |

|Unload frmFind |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmFind.Height) / 2 |

|frmFind.Left = (Screen.Width - frmFind.Width) / 2 |

|End Sub |

| |

|Private Sub txtFind_Change() |

|strNewSearch = "Y" |

|End Sub |

| |

|Private Sub txtFind_GotFocus() |

|txtFind.SelStart = 0 |

|txtFind.SelLength = Len(txtFind.Text) |

|End Sub |

|lc7Done.bas | |

|Option Explicit | |

|Public strNewSearch As String | |

8. (Discovery) lc8Done project – The student should submit a printout of the code.

Answers to step a: (Note: The student is not instructed to submit these values.)

Number Number with Check Digit

1357 13576

4273 42731

3907 39075

4621. 46210

|Option Explicit |

| |

|Private Sub cmdVerify_Click() |

|Dim strNum1 As String, strNum2 As String, strNum3 As String |

|Dim strNum4 As String, strAccount As String, intTotal As Integer |

|strNum1 = Left(txtNumber.Text, 1) |

|strNum2 = Mid(txtNumber.Text, 2, 1) |

|strNum3 = Mid(txtNumber.Text, 3, 1) |

|strNum4 = Mid(txtNumber.Text, 4, 1) |

|intTotal = Val(strNum1) + Val(strNum2) * 2 + Val(strNum3) + Val(strNum4) * 2 |

|If Right(txtNumber.Text, 1) = Right(Str(intTotal), 1) Then |

|lblMsg.Caption = "Correct" |

|Else |

|lblMsg.Caption = "Incorrect" |

|End If |

|txtNumber.SelStart = 0 |

|txtNumber.SelLength = Len(txtNumber.Text) |

|txtNumber.SetFocus |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmNumber.Height) / 2 |

|frmNumber.Left = (Screen.Width - frmNumber.Width) / 2 |

|End Sub |

| |

|Private Sub txtNumber_Change() |

|lblMsg.Caption = "" |

|End Sub |

| |

|Private Sub txtNumber_GotFocus() |

|txtNumber.SelStart = 0 |

|txtNumber.SelLength = Len(txtNumber.Text) |

|End Sub |

9. (Discovery) lc9Done project – The student should submit a printout of the lc9.dat file, a printout of the interface with the test data showing, and a printout of the code.

|lc9.dat | |

|"F1","James, John" | |

|"P2","Daly, Mary" | |

|"F2","Raines, Martha" | |

|"P1","Bride, Jeff" | |

|"F2","May, Tammy" | |

|"P2","Jacob, Kristy" | |

|"F1","Joana, June" | |

|"F1","Sueba, Paul" | |

|"F2","Janes, Carol" | |

|"F1","Smith, Charles" | |

|"P1","Hines, Bridget" | |

|"P2","Kramer, Jerry" | |

|"P1","Adams, John" | |

|"P2","Smith, William" | |

|"P1","Adair, Jenny" | |

|"F1","Gray, Paul" | |

|"F1","Thomas, Chris" | |

|"F1","Angles, Carl" | |

|"F2","Jonah, Jenny" | |

|"F1","Verace, Carol" | |

|"P1","Jerame, Ann" | |

|"P2","Krumpet, Kate" | |

|"F2","Pate, Jenny" | |

|"P2","Cary, Suman" | |

|"P1","Patel, Ann" | |

[pic]

|Option Explicit |

| |

|Private Sub cmdExit_Click() |

|Unload frmBobCat |

|End Sub |

| |

|Private Sub cmdPrint_Click() |

|PrintForm |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height – frmBobCat.Height) / 2 |

|frmBobCat.Left = (Screen.Width – frmBobCat.Width) / 2 |

|lstChoices.AddItem "Full-time" |

|lstChoices.AddItem "Part-time" |

|lstChoices.AddItem "New Cars" |

|lstChoices.AddItem "Used Cars" |

|lstChoices.AddItem "Full-time/New Cars" |

|lstChoices.AddItem "Full-time/Used Cars" |

|lstChoices.AddItem "Part-time/New Cars" |

|lstChoices.AddItem "Part-time/Used Cars" |

|lstChoices.ListIndex = 0 |

|End Sub |

| |

|Private Sub lstChoices_Click() |

|Dim strInputCode As String, strInputName As String, strCode As String |

|Select Case lstChoices.Text |

|Case "Full-time" |

|strCode = "F" |

|Case "Part-time" |

|strCode = "P" |

|Case "New Cars" |

|strCode = "1" |

|Case "Used Cars" |

|strCode = "2" |

|Case "Full-time/New Cars" |

|strCode = "F1" |

|Case "Full-time/Used Cars" |

|strCode = "F2" |

|Case "Part-time/New Cars" |

|strCode = "P1" |

|Case "Part-time/Used Cars" |

|strCode = "P2" |

|End Select |

|lstNames.Clear |

|Open "a:\tut06\lc9.dat" For Input As #1 |

|Do While Not EOF(1) |

|Input #1, strInputCode, strInputName |

|If InStr(1, strInputCode, strCode, 1) Then |

|lstNames.AddItem strInputName |

|End If |

|Loop |

|Close #1 |

|End Sub |

Tutorial 6 – Debugging

Technique

Visual Basic’s Edit menu provides two commands that you can use to edit the code in an application quickly. These commands are Find and Replace.

Exercises

The student is instructed to submit the code for the second debugging application. Changes to the original code are shaded.

|Option Explicit |

| |

|Private Sub cmd5_Click() |

|Dim sngSales As Single, sngComm As Single |

|sngSales = Val(txtSales.Text) |

|sngComm = sngSales * 0.05 |

|lblComm.Caption = Format(sngComm, "standard") |

|End Sub |

| |

|Private Sub cmd8_Click() |

|Dim sngSales As Single, sngComm As Single |

|sngSales = Val(txtSales.Text) |

|sngComm = sngSales * 0.08 |

|lblComm.Caption = Format(sngComm, "standard") |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmDebug2 |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height – frmDebug2.Height) / 2 |

|frmDebug2.Left = (Screen.Width – frmDebug2.Width) / 2 |

|End Sub |

Tutorial 7, Lesson A

Questions

c Common Dialog

1. e ShowOpen

2. e ShowPrinter

3. c Save As

4. d ShowColor

5. d ShowFont

6. c Filter

7. a “Picture Files(*.pic)|*.pic”

8. b “Project Files(*.vbp;*.mak;*.vbg)|*.vbp;*.mak;*.vbg”

9. c FileName

10. c Flags

11. c Flags

Exercises

1. The student should submit a printout of the code.

|Private Sub cmdFull_Click() |Private Sub cmdPartial_Click() |

|dlgColor.Flags = cdlCCFullOpen |dlgColor.Flags = cdlCCPreventFullOpen |

|dlgColor.ShowColor |dlgColor.ShowColor |

|End Sub |End Sub |

2. The student should submit a printout of the code.

|Private Sub cmdOpen_Click() |Private Sub cmdSave_Click() |

|dlg1.Filter = "All Files(*.*)|*.*" |dlg1.Filter = "All Files(*.*)|*.*" |

|dlg1.Flags = cdlOFNCreatePrompt |dlg1.Flags = cdlOFNOverwritePrompt |

|dlg1.ShowOpen |dlg1.ShowSave |

|End Sub |End Sub |

X This file does not exist. Do you want to create it?

[filename including path will vary] This file already exists. Replace existing file?

3. The student should submit a printout of the code.

|Private Sub cmdEffects_Click() |Private Sub cmdWysiwyg_Click() |

|dlgFont.Flags = cdlCFBoth + cdlCFEffects |dlgFont.Flags = cdlCFBoth + cdlCFWYSIWYG |

|dlgFont.ShowFont |dlgFont.ShowFont |

|End Sub |End Sub |

| | |

|Private Sub cmdTT_Click() | |

|dlgFont.Flags = cdlCFBoth + cdlCFTTOnly | |

|dlgFont.ShowFont | |

|End Sub | |

4. The student should submit a printout of the code.

|Private Sub cmdPrint_Click() |

|dlgPrint.Flags = cdlPDDisablePrintToFile + cdlPDNoSelection + cdlPDNoPageNums |

|dlgPrint.ShowPrinter |

|End Sub |

Tutorial 7, Lesson B

Questions

1. c both a and b (save a new file and save an existing file under a new name)

2. d both a and b (the document’s name and the application’s name)

3. e both b and c (the application’s name and the type of document the application creates)

4. a cdlOFNOverwritePrompt

5. b cdlOFNPathMustExist

6. c dlgEdit.Filter = “Document Files(*.doc)|*.doc”

7. e FileName

8. d Write #

9. b Print #

10. d CancelError

11. c error trapping

12. c error-handling routine or error handler

13. b On Error GoTo

14. d Exit Sub

15. a colon (:)

16. d Call mnuFileSaveAs_Click

17. a True and False

Exercises

1. lb1Done project – The student should submit a printout of the code.

|Option Explicit |

|Dim intTerm As Integer |

| |

|Private Sub cmdCalc_Click() |

|Dim sngPrincipal As Single, sngRate As Single |

|Dim sngPayment As Single |

|sngPrincipal = Val(txtPrincipal.Text) |

|sngRate = Val(Format(lstInterest.Text, "general number")) |

|sngPayment = -Pmt(sngRate / 12, intTerm * 12, sngPrincipal) |

|lblPayment.Caption = Format(sngPayment, "currency") |

|txtPrincipal.SetFocus |

|End Sub |

| |

|Private Sub Form_Load() |

|frmMthlyPay.Left = (Screen.Width - frmMthlyPay.Width) / 2 |

| = (Screen.Height - frmMthlyPay.Height) / 2 |

|Dim sngX As Single |

|For sngX = 0.07 To 0.12 Step 0.0025 |

|lstInterest.AddItem Format(sngX, "percent") |

|Next sngX |

|lstInterest.ListIndex = 8 |

|optTerm(3).Value = True |

|End Sub |

| |

|Private Sub lstInterest_Click() |

|lblPayment.Caption = "" |

|End Sub |

| |

|Private Sub mnuFileExit_Click() |

|Unload frmMthlyPay |

|End Sub |

| |

|Private Sub mnuFilePrint_Click() |

|PrintForm |

|End Sub |

|Private Sub mnuFormatBackground_Click() |Private Sub optTerm_Click(Index As Integer) |

|dlgCommon.Flags = cdlCCRGBInit |Select Case Index |

|dlgCommon.Color = frmMthlyPay.BackColor |Case 0 |

|dlgCommon.ShowColor |intTerm = 2 |

|frmMthlyPay.BackColor = dlgCommon.Color |Case 1 |

|End Sub |intTerm = 3 |

| |Case 2 |

|Private Sub mnuFormatFont_Click() |intTerm = 4 |

|dlgCommon.Flags = cdlCFScreenFonts |Case Else |

|dlgCommon.FontName = lblPayment.FontName |intTerm = 5 |

|dlgCommon.FontBold = lblPayment.FontBold |End Select |

|dlgCommon.FontItalic = lblPayment.FontItalic |lblPayment.Caption = "" |

|dlgCommon.FontSize = lblPayment.FontSize |End Sub |

|dlgCommon.ShowFont | |

|lblPayment.FontName = dlgCommon.FontName |Private Sub txtPrincipal_Change() |

|lblPayment.FontBold = dlgCommon.FontBold |lblPayment.Caption = "" |

|lblPayment.FontItalic = dlgCommon.FontItalic |End Sub |

|lblPayment.FontSize = dlgCommon.FontSize | |

|End Sub |Private Sub txtPrincipal_GotFocus() |

| |txtPrincipal.SelStart = 0 |

|Private Sub mnuFormatInfo_Click() |txtPrincipal.SelLength = Len(txtPrincipal.Text) |

|Dim intX As Integer |End Sub |

|dlgCommon.Flags = cdlCCRGBInit | |

|dlgCommon.Color = fraInfo.BackColor | |

|dlgCommon.ShowColor | |

|For intX = 0 To 3 | |

|optTerm(intX).BackColor = dlgCommon.Color | |

|Next intX | |

|fraInfo.BackColor = dlgCommon.Color | |

|End Sub | |

2. lb2Done project – The student should submit a printout of the code for the Format menu’s commands.

|Private Sub mnuFormatColor_Click() |

|dlgEdit.Flags = cdlCCRGBInit |

|dlgEdit.Color = txtEdit.BackColor |

|dlgEdit.ShowColor |

|txtEdit.BackColor = dlgEdit.Color |

|End Sub |

| |

|Private Sub mnuFormatFont_Click() |

|dlgEdit.Flags = cdlCFScreenFonts |

|dlgEdit.FontName = txtEdit.FontName |

|dlgEdit.FontBold = txtEdit.FontBold |

|dlgEdit.FontItalic = txtEdit.FontItalic |

|dlgEdit.FontSize = txtEdit.FontSize |

|dlgEdit.ShowFont |

|txtEdit.FontName = dlgEdit.FontName |

|txtEdit.FontBold = dlgEdit.FontBold |

|txtEdit.FontItalic = dlgEdit.FontItalic |

|txtEdit.FontSize = dlgEdit.FontSize |

|End Sub |

Tutorial 7, Lesson C

Questions

1. d both a and c (automatically save the current document using its current name and give the file a name if it

has not been previously saved)

2. d Input function

3. d Input function

4. d LOF

5. a FileLen

Exercises

1. lc1Done project – The student should submit a printout of the lcdata1.dat, lcdata2.dat, lcdata3.dat, and lcdata4.dat files, as well as a printout of the code.

|lcdata1.dat |lcdata3.dat |

|"Smith, Joe" |"Smith, Joe" |

|"Jones, Mary" |"Jones, Mary" |

|"Adkari, Joel" |"Adkari, Joel" |

|"Lin, Sue" |"Lin, Sue" |

|"Li, Vicky" |"Li, Vicky" |

|"Patel, Orman" |"Patel, Orman" |

|"White, Pam" |"White, Pam" |

|"Abram, Jill" |"Abram, Jill" |

|"Chen, Sue" |"Chen, Sue" |

|"Dune, Joe" |"Dune, Joe" |

|"Willard, Tom" | |

|"Krisen, Jerry" | |

|lcdata2.dat |lcdata4.dat |

|"Kendry, Paul" |"Franklin Park","60131" |

|"Yelton, Bob" |"River Grove","60171" |

|"Patel, Suman" |"Elmwood Park","60191" |

|"Patel, Mamta" |"Northlake","60145" |

|"Lee, Janice" |"River Forest","60305" |

|"Jones, Scotty" |"LaGrange","60525" |

| |"Oak Park","60405" |

| |"North Park","60304" |

|Option Explicit |

| |

|Private Sub Form_Resize() |

|txtEdit.Height = frmEdit.ScaleHeight |

|txtEdit.Width = frmEdit.ScaleWidth |

|End Sub |

| |

|Private Sub mnuFileExit_Click() |

|Unload frmEdit |

|End Sub |

| |

|Private Sub mnuFileOpen_Click() |

|On Error GoTo OpenErrHandler |

|dlgEdit.CancelError = True |

|dlgEdit.Filter = "Data Files(*.dat)|*.dat|All Files(*.*)|*.*" |

|dlgEdit.FileName = "" |

|dlgEdit.ShowOpen |

|Open dlgEdit.FileName For Input As #1 |

|txtEdit.Text = Input(LOF(1), 1) |

|Close #1 |

|frmEdit.Caption = dlgEdit.FileName & " - Text Editor" |

|Exit Sub |

| |

|OpenErrHandler: |

|End Sub |

| |

|Private Sub mnuFilePrint_Click() |

|On Error GoTo PrintErrHandler |

|dlgEdit.Flags = cdlPDNoSelection + cdlPDHidePrintToFile + cdlPDNoPageNums |

|dlgEdit.CancelError = True |

|dlgEdit.ShowPrinter |

|PrintForm |

|Exit Sub |

| |

|PrintErrHandler: |

|End Sub |

2. lc2Done project – The student should submit a printout of the lc2.dat file, a printout of the interface with the test data showing, and a printout of the code.

lc2.dat

"Mary","Female",21

"Terri","Female",18

"Jim","Male",33

"George","Male",45

"Paula","Female",53

"Fred","Male",25

[pic]

|Private Sub Form_Load() | |

|frmData.Left = (Screen.Width - frmData.Width) / 2 | |

| = (Screen.Height - frmData.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmData | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

|Option Explicit |

| |

|Private Sub cmdDisplay_Click() |

|Dim strName As String, strGender As String, intAge As Integer |

|Dim intTotFem As Integer, intTotMal As Integer |

|Dim intTotAgeFem As Integer, intTotAgeMal As Integer |

|Dim sngAvgAgeFem As Single, sngAvgAgeMal As Single |

|Open "a:\tut07\lc2.dat" For Input As #1 |

|Do While Not EOF(1) |

|Input #1, strName, strGender, intAge |

|If UCase(strGender) = "FEMALE" Then |

|intTotFem = intTotFem + 1 |

|intTotAgeFem = intTotAgeFem + intAge |

|Else |

|intTotMal = intTotMal + 1 |

|intTotAgeMal = intTotAgeMal + intAge |

|End If |

|Loop |

|Close #1 |

|If intTotFem > 0 Then |

|sngAvgAgeFem = intTotAgeFem / intTotFem |

|Else |

|sngAvgAgeFem = 0 |

|End If |

|If intTotMal > 0 Then |

|sngAvgAgeMal = intTotAgeMal / intTotMal |

|Else |

|sngAvgAgeMal = 0 |

|End If |

|lblTotFem.Caption = intTotFem |

|lblTotMale.Caption = intTotMal |

|lblAvgAgeFem.Caption = Format(sngAvgAgeFem, "standard") |

|lblAvgAgeMal.Caption = Format(sngAvgAgeMal, "standard") |

|End Sub |

3. (Discovery) lc3Done project – The student should submit a printout of the code. The student is instructed to circle the sections of the code he or she had to modify in order to include the FreeFile function. The modified sections are shaded.

|Option Explicit |

|Dim strSearchFor As String |

|Dim blnChange As Boolean, blnCancelSave As Boolean |

| |

|Private Sub Form_Load() |

|blnChange = False |

|blnCancelSave = False |

|End Sub |

| |

|Private Sub Form_Resize() |

|txtEdit.Height = frmEdit.ScaleHeight |

|txtEdit.Width = frmEdit.ScaleWidth |

|End Sub |

| |

|Private Sub Form_Unload(Cancel As Integer) |

|Const conBtns As Integer = vbYesNoCancel + vbExclamation _ |

|+ vbDefaultButton3 + vbApplicationModal |

|Const conMsg As String = "Do you want to save the current document?" |

|Dim intUserResponse As Integer |

|If blnChange = True Then 'document was changed since last save |

|intUserResponse = MsgBox(conMsg, conBtns, "Editor") |

|Select Case intUserResponse |

|Case vbYes 'user wants to save current document |

|Call mnuFileSave_Click |

|If blnCancelSave = True Then 'user canceled save |

|Cancel = 1 'return to document-don't unload form |

|End If |

|Case vbNo 'user does not want to save current document |

|'unload form and exit |

|Case vbCancel |

|Cancel = 1 'return to document-don't unload form |

|End Select |

|End If |

|End Sub |

|Private Sub mnuEdit_Click() |

|If txtEdit.SelText = "" Then 'if no text is selected |

|mnuEditCut.Enabled = False |

|mnuEditCopy.Enabled = False |

|Else 'if some text is selected |

|mnuEditCut.Enabled = True |

|mnuEditCopy.Enabled = True |

|End If |

|If Clipboard.GetText() = "" Then 'if no text is on the clipboard |

|mnuEditPaste.Enabled = False |

|Else 'if some text is on the clipboard |

|mnuEditPaste.Enabled = True |

|End If |

|End Sub |

| |

|Private Sub mnuEditCopy_Click() |

|Clipboard.Clear 'clear clipboard |

|Clipboard.SetText txtEdit.SelText 'send text to clipboard |

|End Sub |

| |

|Private Sub mnuEditCut_Click() |

|Clipboard.Clear 'clear clipboard |

|Clipboard.SetText txtEdit.SelText 'send text to clipboard |

|txtEdit.SelText = "" 'remove selected text from text box |

|End Sub |

| |

|Private Sub mnuEditFind_Click() |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Const conMsg As String = "The search string was not found." |

|Dim intRetVal As Integer |

|Dim intFoundPos As Integer |

|strSearchFor = InputBox("Find what?", "Find") 'prompt user for text |

|intFoundPos = InStr(1, txtEdit.Text, strSearchFor, 1) 'search for text |

|If intFoundPos = 0 Then 'if text was not found |

|intRetVal = MsgBox(conMsg, conBtns, "Find") |

|Else 'if text was found |

|txtEdit.SelStart = intFoundPos - 1 'highlight text |

|txtEdit.SelLength = Len(strSearchFor) |

|End If |

|End Sub |

| |

|Private Sub mnuEditFindNext_Click() |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Const conMsg As String = "The search has been completed." |

|Dim inRetVal As Integer |

|Dim intFoundPos As Integer, intBegSearch As Integer |

|intBegSearch = txtEdit.SelStart + 2 |

|intFoundPos = InStr(intBegSearch, txtEdit.Text, strSearchFor, 1) |

|If intFoundPos = 0 Then 'if text was not found |

|inRetVal = MsgBox(conMsg, conBtns, "Find Next") |

|Else 'if text was found |

|txtEdit.SelStart = intFoundPos - 1 'highlight text |

|txtEdit.SelLength = Len(strSearchFor) |

|End If |

|End Sub |

|Private Sub mnuEditPaste_Click() |

|'retrieve text from clipboard and paste into text box |

|txtEdit.SelText = Clipboard.GetText() |

|End Sub |

| |

|Private Sub mnuFileExit_Click() |

|Unload frmEdit |

|End Sub |

| |

|Private Sub mnuFileNew_Click() |

|Const conBtns As Integer = vbYesNoCancel + vbExclamation _ |

|+ vbDefaultButton3 + vbApplicationModal |

|Const conMsg As String = "Do you want to save the current document?" |

|Dim intUserResponse As Integer |

|If blnChange = True Then 'text box was changed since last save |

|intUserResponse = MsgBox(conMsg, conBtns, "Editor") |

|Select Case intUserResponse |

|Case vbYes 'user wants to save current file |

|Call mnuFileSave_Click |

|If blnCancelSave = True Then 'save was canceled |

|Exit Sub |

|End If |

|Case vbNo 'user does not want to save current file |

|'process instructions below End If |

|Case vbCancel 'user wants to cancel New command |

|Exit Sub |

|End Select |

|End If |

|txtEdit.Text = "" 'clear text box |

|blnChange = False 'reset variable |

|frmEdit.Caption = "Document - Text Editor" |

|dlgEdit.FileName = "" |

|End Sub |

|Private Sub mnuFileOpen_Click() |

|Const conBtns As Integer = vbYesNoCancel + vbExclamation _ |

|+ vbDefaultButton3 + vbApplicationModal |

|Const conMsg As String = "Do you want to save the current document?" |

|Dim intUserResponse As Integer, intFileNum As Integer |

|On Error GoTo OpenErrHandler |

|dlgEdit.CancelError = True |

|If blnChange = True Then 'document was changed since last save |

|intUserResponse = MsgBox(conMsg, conBtns, "Editor") |

|Select Case intUserResponse |

|Case vbYes 'user wants to save current document |

|Call mnuFileSave_Click |

|If blnCancelSave = True Then 'user canceled save |

|Exit Sub |

|End If |

|Case vbNo 'user doesn't want to save current document |

|'process instructions below End If |

|Case vbCancel 'user wants to cancel Open command |

|Exit Sub |

|End Select |

|End If |

|dlgEdit.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*" |

|dlgEdit.FileName = "" |

|dlgEdit.ShowOpen |

|intFileNum = FreeFile() |

|Open dlgEdit.FileName For Input As #intFileNum |

|txtEdit.Text = Input(LOF(intFileNum), intFileNum) |

|Close #intFileNum |

|blnChange = False |

|frmEdit.Caption = dlgEdit.FileName & " - Text Editor" |

|Exit Sub |

| |

|OpenErrHandler: |

|End Sub |

| |

|Private Sub mnuFilePrint_Click() |

|On Error GoTo PrintErrHandler |

|dlgEdit.Flags = cdlPDNoSelection + cdlPDHidePrintToFile + cdlPDNoPageNums |

|dlgEdit.CancelError = True |

|dlgEdit.ShowPrinter |

|PrintForm |

|Exit Sub |

|PrintErrHandler: |

|End Sub |

| |

|Private Sub mnuFileSave_Click() |

|Dim intFileNum As Integer |

|If frmEdit.Caption = "Document - Text Editor" Then |

|Call mnuFileSaveAs_Click 'new document |

|Else 'existing document |

|intFileNum = FreeFile() |

|Open dlgEdit.FileName For Output As #intFileNum |

|Print #intFileNum, txtEdit.Text |

|Close #intFileNum |

|blnChange = False |

|End If |

|End Sub |

|Private Sub mnuFileSaveAs_Click() |

|Dim intFileNum As Integer |

|On Error GoTo SaveErrHandler 'turn error trapping on |

|dlgEdit.CancelError = True 'treat the Cancel button as an error |

|dlgEdit.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist |

|dlgEdit.Filter = "Text Files(*.txt)|*.txt" |

|dlgEdit.ShowSave |

|intFileNum = FreeFile() |

|Open dlgEdit.FileName For Output As #intFileNum |

|Print #intFileNum, txtEdit.Text |

|Close #intFileNum |

|frmEdit.Caption = dlgEdit.FileName & " - Text Editor" |

|blnChange = False |

|blnCancelSave = False |

|Exit Sub |

| |

|SaveErrHandler: |

|blnCancelSave = True 'save was canceled |

|End Sub |

| |

|Private Sub txtEdit_Change() |

|blnChange = True |

|End Sub |

4. (Discovery) lc4Done project – The student should submit the command button’s code.

|Private Sub Command1_Click() |

|dlgOpen.Filter = "Text Files (*.txt)|*.txt|Picture Files (*.pic)|*.pic|All Files (*.*)|*.*" |

|dlgOpen.FilterIndex = 3 |

|dlgOpen.ShowOpen |

|End Sub |

5. lc5Done project – The student should submit four printouts of the code.

|step g: |

|Option Explicit |

| |

|Private Sub cmdCalc_Click() |

|Const conMsg As String = "The sales amount cannot exceed 32767" |

| |

|Const conBtns As Integer = _ |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim intSales As Integer, sngBonus As Single, intTemp As Integer |

|On Error GoTo CalcErrHandler |

|intSales = Val(InputBox("Enter the sales:", "Entry")) |

|sngBonus = intSales * 0.1 |

|lblBonus.Caption = Format(sngBonus, "currency") |

|Exit Sub |

| |

|CalcErrHandler: |

|intTemp = MsgBox(conMsg, conBtns, "Error") |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmBonus |

|End Sub |

| |

|Private Sub Form_Load() |

|frmBonus.Left = (Screen.Width – frmBonus.Width) / 2 |

| = (Screen.Height – frmBonus.Height) / 2 |

|End Sub |

| |

|step h: |

|Option Explicit |

| |

|Private Sub cmdCalc_Click() |

|Const conMsg As String = "The sales amount cannot exceed 32767" |

|Const conBtns As Integer = _ |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim intSales As Integer, sngBonus As Single, intTemp As Integer |

|On Error GoTo CalcErrHandler |

|intSales = Val(InputBox("Enter the sales:", "Entry")) |

|sngBonus = intSales * 0.1 |

|lblBonus.Caption = Format(sngBonus, "currency") |

|Exit Sub |

| |

|CalcErrHandler: |

|intTemp = MsgBox(conMsg, conBtns, "Error") |

|Resume |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmBonus |

|End Sub |

| |

|Private Sub Form_Load() |

|frmBonus.Left = (Screen.Width - frmBonus.Width) / 2 |

| = (Screen.Height - frmBonus.Height) / 2 |

|End Sub |

|step j: |

|Option Explicit |

| |

|Private Sub cmdCalc_Click() |

|Const conMsg As String = "The sales amount cannot exceed 32767" |

|Const conBtns As Integer = _ |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim intSales As Integer, sngBonus As Single, intTemp As Integer |

|On Error GoTo CalcErrHandler |

|intSales = Val(InputBox("Enter the sales:", "Entry")) |

|sngBonus = intSales * 0.1 |

|lblBonus.Caption = Format(sngBonus, "currency") |

|Exit Sub |

| |

|CalcErrHandler: |

|intTemp = MsgBox(conMsg, conBtns, "Error") |

|intSales = 0 |

|Resume Next |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmBonus |

|End Sub |

| |

|Private Sub Form_Load() |

|frmBonus.Left = (Screen.Width - frmBonus.Width) / 2 |

| = (Screen.Height - frmBonus.Height) / 2 |

|End Sub |

| |

|step m: |

|Option Explicit |

| |

|Private Sub cmdCalc_Click() |

|Const conMsg As String = "The sales amount cannot exceed 32767" |

|Const conBtns As Integer = _ |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|Dim intSales As Integer, sngBonus As Single, intTemp As Integer |

|On Error GoTo CalcErrHandler |

|intSales = Val(InputBox("Enter the sales:", "Entry")) |

|sngBonus = intSales * 0.1 |

|Here: |

|lblBonus.Caption = Format(sngBonus, "currency") |

|Exit Sub |

| |

|CalcErrHandler: |

|intTemp = MsgBox(conMsg, conBtns, "Error") |

|sngBonus = 0 |

|Resume Here |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmBonus |

|End Sub |

| |

|Private Sub Form_Load() |

|frmBonus.Left = (Screen.Width - frmBonus.Width) / 2 |

| = (Screen.Height - frmBonus.Height) / 2 |

|End Sub |

6. (Discovery) lc6Done project – The student should submit a printout of the code and a printout of the pao.rpt report. Changes to the original code are shaded.

|Option Explicit |

| |

|Private Sub cmdDisplay_Click() |

|Dim strParty As String, intAge As Integer, intCount As Integer |

|For intCount = 0 To 3 'clear the label controls |

|lblDem(intCount).Caption = "" |

|lblRep(intCount).Caption = "" |

|lblInd(intCount).Caption = "" |

|Next intCount |

|Open "a:\tut07\pao.dat" For Input As #1 'open the sequential file |

|Do While Not EOF(1) |

|Input #1, strParty, intAge 'read a record |

|Select Case strParty 'update appropriate label control |

|Case "Democrat" |

|lblDem(intAge).Caption = Val(lblDem(intAge).Caption) + 1 |

|Case "Republican" |

|lblRep(intAge).Caption = Val(lblRep(intAge).Caption) + 1 |

|Case "Independent" |

|lblInd(intAge).Caption = Val(lblInd(intAge).Caption) + 1 |

|End Select |

|Loop |

|Close #1 'close the file |

| |

|End Sub |

| |

|Private Sub cmdEnter_Click() |

|Open "a:\tut07\pao.dat" For Append As #1 'open the sequential file |

|Write #1, lstParty.Text, lstAge.ListIndex 'write the record |

|Close #1 'close the file |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmPao |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height – frmPao.Height) / 2 |

|frmPao.Left = (Screen.Width – frmPao.Width) / 2 |

|lstAge.AddItem "18 - 35" |

|lstAge.AddItem "36 - 50" |

|lstAge.AddItem "51 - 65" |

|lstAge.AddItem "Over 65" |

|lstParty.AddItem "Republican" |

|lstParty.AddItem "Independent" |

|lstParty.AddItem "Democrat" |

|lstParty.ListIndex = 0 |

|lstAge.ListIndex = 1 |

|End Sub |

|Private Sub cmdPrint_Click() |

|Dim intX As Integer, intDem As Integer, intRep As Integer |

|Dim intInd As Integer, intTotal As Integer |

|Dim strPS1 As String * 3, strPS2 As String * 3, strPS3 As String * 3 |

|Dim strPS4 As String * 3, strPS5 As String * 4 |

| |

|'accumulate totals |

|For intX = 0 To 3 |

|intDem = intDem + Val(lblDem(intX).Caption) |

|intRep = intRep + Val(lblRep(intX).Caption) |

|intInd = intInd + Val(lblInd(intX).Caption) |

|Next intX |

|intTotal = intDem + intRep + intInd |

|Open "a:\tut07\pao.rpt" For Output As #1 |

| |

|Print #1, Tab(30); "PAO Information – 1999" |

|Print #1, |

|Print #1, Tab(5); "Party"; Tab(20); "18-35"; Tab(30); "36-50"; _ |

|Tab(40); "51-65"; Tab(50); "Over 65"; Tab(60); "Total" |

|'align democrat numbers and print |

|RSet strPS1 = Format(lblDem(0).Caption, "general number") |

|RSet strPS2 = Format(lblDem(1).Caption, "general number") |

|RSet strPS3 = Format(lblDem(2).Caption, "general number") |

|RSet strPS4 = Format(lblDem(3).Caption, "general number") |

|RSet strPS5 = Format(intDem, "general number") |

|Print #1, Tab(5); "Democrat"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|'align republican numbers and print |

|RSet strPS1 = Format(lblRep(0).Caption, "general number") |

|RSet strPS2 = Format(lblRep(1).Caption, "general number") |

|RSet strPS3 = Format(lblRep(2).Caption, "general number") |

|RSet strPS4 = Format(lblRep(3).Caption, "general number") |

|RSet strPS5 = Format(intRep, "general number") |

|Print #1, Tab(5); "Republican"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|'align independent numbers and print |

|RSet strPS1 = Format(lblInd(0).Caption, "general number") |

|RSet strPS2 = Format(lblInd(1).Caption, "general number") |

|RSet strPS3 = Format(lblInd(2).Caption, "general number") |

|RSet strPS4 = Format(lblInd(3).Caption, "general number") |

|RSet strPS5 = Format(intInd, "general number") |

|Print #1, Tab(5); "Independent"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|Print #1, 'print two blank lines |

|Print #1, |

|'print grand total |

|RSet strPS5 = Format(intTotal, "general number") |

|Print #1, Tab(41); "Total respondents"; Tab(61); strPS5 |

|Print #1, 'print a blank line |

|Print #1, Tab(5); "End of report" 'print message |

|Close #1 |

|End Sub |

| PAO Information - 1999 |

| |

|Party 18-35 36-50 51-65 Over 65 Total |

|Democrat 1 1 2 |

|Republican 1 1 |

|Independent 1 1 2 |

| |

| |

|Total respondents 5 |

| |

|End of report |

Tutorial 7 – Debugging

Technique

It is important to test an application with both valid and invalid data. The application should be able to handle the invalid data appropriately; in other words, the application should not “crash” because the user entered invalid data. Once you have determined which types of errors may occur in the application, you can use error trapping, along with the Err object, to instruct the application to take the appropriate action that will prevent the application from “crashing.” The Err object is yet another object available in Visual Basic, similar to the Print, Form, and Screen objects that you learned about in previous tutorials.

Exercises

1. DebDone2 project – The student should submit a printout of the code. Changes to the original code are shaded.

|Option Explicit |

| |

|Private Sub cmdDivide_Click() |

|Const conMsg As String = "Both text boxes must be completed and must contain numbers." |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Dim intUserResponse As Integer |

|Dim sngNum1 As Single, sngNum2 As Single |

|On Error GoTo DebugErrHandler |

|sngNum1 = Val(txtNum1.Text) |

|sngNum2 = Val(txtNum2.Text) |

|lblQuotient.Caption = sngNum1 / sngNum2 |

|Exit Sub |

| |

|DebugErrHandler: |

|Select Case Err.Number |

|Case 6, 11 |

|intUserResponse = MsgBox(conMsg, conBtns, "Debug") |

|End Select |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmDivide |

|End Sub |

| |

|Private Sub Form_Load() |

|frmDivide.Left = (Screen.Width - frmDivide.Width) / 2 |

| = (Screen.Height - frmDivide.Height) / 2 |

|End Sub |

2. DebDone3 project – The student should submit a printout of the code. Changes to the original code are shaded.

|Option Explicit |

| |

|Private Sub cmdDivide_Click() |

|Const conMsg As String = "Both text boxes must be completed and must contain numbers." |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Dim intUserResponse As Integer |

|Dim sngNum1 As Single, sngNum2 As Single |

|On Error GoTo DebugErrHandler |

|Err.Raise 51 |

|sngNum1 = Val(txtNum1.Text) |

|sngNum2 = Val(txtNum2.Text) |

|lblQuotient.Caption = sngNum1 / sngNum2 |

|Exit Sub |

| |

|DebugErrHandler: |

|Select Case Err.Description |

|Case "Overflow", "Division by zero" |

|intUserResponse = MsgBox(conMsg, conBtns, "Debug") |

|Case "Internal error" |

|intUserResponse = MsgBox("Internal error", conBtns, "Debug") |

|End Select |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmDivide |

|End Sub |

| |

|Private Sub Form_Load() |

|frmDivide.Left = (Screen.Width - frmDivide.Width) / 2 |

| = (Screen.Height - frmDivide.Height) / 2 |

|End Sub |

Tutorial 8, Lesson A

Questions

e Type

1. c either randomly or sequentially

2. b General Declarations section of a code module

3. e strCity As String * 15

4. d The string “Chicago” followed by eight blank spaces

5. b byte

6. d 8

7. d Open

8. d Open

9. c Put

10. b Get

11. c,e Open “a:\data.dat” for random as #1 Len = Len(udtEmpRec)

Open “a:\data.dat” for random as #1 Len = 100

12. d Put #1, intRecNum, udtEmpRec

13. d Close #3

14. a Len(udtStudRec)

15. c either read from or written to

16. d strFirst = Space(10)

17. e CustStruc

18. c udtCustRec

19. a,b,d strName, strPhone, curSalary

20. c 25

21. a 8

22. d 45

23. d udtCustRec.strPhone

24. c udtCustRec

25. a,c Get #1, 2, udtCustRec

Get #1, intNum, udtcustRec

Exercises

1. Type BookStruc

strTitle as String * 20

strAuthor as String * 20

curCost as Currency

End Type

2. Type TapeStruc

strName as String * 25

strArtist as String * 20

intSong as Integer

strLength as String * 6

End Type

3. Dim udtBookRec as BookStruc

4. Dim udtTapeRec as TapeStruc

5. Open “a:\tut08\books.dat” for Random as #1 Len = Len(udtBookRec)

6. Open “a:\tut08\tapes.dat” for Random as #1 Len = Len(udtTapeRec)

7. Put #1, intRecNum, udtBookRec

8. Put #1, intRecNum, udtTapeRec

9. Get #1, intRecNum, udtBookRec

10. Get #1, intRecNum, udtTapeRec

11. Close #1

12. a. Dim udtCompRec as ComputerStruc

b. Open “a:\tut08\Computer.dat” for Random as #1 Len = Len(udtCompRec)

c. Dim intX as Integer

udtCompRec.strName = Space(5)

udtCompRec.curCost = 0

For intX = 1 To 10

Put #1, intX, udtCompRec

Next intX

d. udtCompRec.strName = “IB-50”

e. udtCompRec.curCost = 2400

f. Put #1, intRecNum, udtCompRec

g. Get #1, intRecNum, udtCompRec

h. lblName.Caption = udtCompRec.strName

lblCost.Caption = udtCompRec.curCost

i. Close #1

13. a. Dim udtFriendRec as FriendStruc

b. Open “a:\tut08\Friends.dat” for Random as #1 Len = Len(udtFriendRec)

c. Dim intX as Integer

udtFriendRec.strLast = Space(10)

udtFriendRec.strFirst = Space(10)

For intX = 1 To 5

Put #1, intX, udtFriendRec

Next intX

d. udtFriendRec.strFirst = txtFirst.Text

e. udtFriendRec.strLast = txtLast.Text

f. Put #1, intRecNum, udtFriendRec

g. Get #1, intRecNum, udtFriendRec

h. lblName.Caption = udtFriendRec.strFirst & “ “ & udtFriendRec.strLast

j. Close #1

14. a. Type CustStruc

strName as String * 25

strPhone as String * 8

curSales as Currency

End Type

b. Dim udtCustRec as CustStruc

c. Open “a:\tut08\Customer.dat” for Random as #1 Len = Len(udtCustRec)

d. Dim intX as Integer

udtCustRec.strName = Space(25)

udtCustRec.strPhone = Space(8)

udtCustRec.curSales = 0

For intX = 1 To 5

Put #1, intX, udtCustRec

Next intX

e. udtCustRec.strName = txtName.Text

f. udtCustRec.strPhone = txtPhone.Text

g. udtCustRec.curSales = Val(txtSales.Text)

h. Put #1, intRecNum, udtCustRec

i. Get #1, intRecNum, udtCustRec

k. txtName.Text = udtCustRec.strName

l. txtPhone.Text = udtCustRec.strPhone

m. txtSales.Text = udtCustRec.curSales

n. Close #1

15. la15Done project – The student should submit a printout of the interface, a printout of the code, and a printout of the cds.dat file.

[pic]

|la15Done.bas |

|Option Explicit |

|Type CDStruc |

|strName As String * 20 |

|strArtist As String * 20 |

|End Type |

| |

|la15Done.frm |

|Option Explicit |

| |

|Private Sub cmdDisplay_Click() |

|Const conMsg As String = "Incorrect item number." |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Dim intUser As Integer, intX As Integer, udtCDRec As CDStruc |

|intX = Val(txtNumber.Text) |

|If intX > 0 Then |

|Get #1, intX, udtCDRec |

|txtName.Text = udtCDRec.strName |

|txtArtist.Text = udtCDRec.strArtist |

|Else |

|intUser = MsgBox(conMsg, conBtns, "Enter") |

|End If |

|txtNumber.SetFocus |

|End Sub |

| |

|Private Sub cmdEnter_Click() |

|Const conMsg As String = "Incorrect item number." |

|Const conBtns As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Dim intUser As Integer, intX As Integer, udtCDRec As CDStruc |

|intX = Val(txtNumber.Text) |

|If intX > 0 Then |

|udtCDRec.strName = txtName.Text |

|udtCDRec.strArtist = txtArtist.Text |

|Put #1, intX, udtCDRec |

|Else |

|intUser = MsgBox(conMsg, conBtns, "Enter") |

|End If |

|txtName.Text = "" |

|txtArtist.Text = "" |

|txtNumber.SetFocus |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmCd |

|End Sub |

|Private Sub cmdInit_Click() |

|Const conMsg As String = "Do you want to initialize the file?" |

|Const conBtns1 As Integer = vbYesNo + vbExclamation _ |

|+ vbDefaultButton2 + vbApplicationModal |

|Const conBtns2 As Integer = vbOKOnly + vbInformation _ |

|+ vbDefaultButton1 + vbApplicationModal |

|Dim intUser As Integer, intX As Integer, udtCDRec As CDStruc |

|udtCDRec.strName = Space(20) |

|udtCDRec.strArtist = Space(20) |

|intUser = MsgBox(conMsg, conBtns1, "Initialize") |

|If intUser = vbYes Then |

|For intX = 1 To 5 |

|Put #1, intX, udtCDRec |

|Next intX |

|intUser = MsgBox("File was initialized.", conBtns2, "Initialized") |

|Else |

|intUser = MsgBox("File was not initialized.", conBtns2, "Not Initialized") |

|End If |

|txtNumber.SetFocus |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height – frmCd.Height) / 2 |

|frmCd.Left = (Screen.Width - frmCd.Width) / 2 |

|Dim udtCDRec As CDStruc |

|Open "a:\tut08\CDs.dat" For Random As #1 Len = Len(udtCDRec) |

|End Sub |

| |

|Private Sub Form_Unload(Cancel As Integer) |

|Close #1 |

|End Sub |

| |

|Private Sub txtArtist_GotFocus() |

|txtArtist.SelStart = 0 |

|txtArtist.SelLength = Len(txtArtist.Text) |

|End Sub |

| |

|Private Sub txtName_GotFocus() |

|txtName.SelStart = 0 |

|txtName.SelLength = Len(txtName.Text) |

|End Sub |

| |

|Private Sub txtNumber_GotFocus() |

|txtNumber.SelStart = 0 |

|txtNumber.SelLength = Len(txtNumber.Text) |

|End Sub |

| |

|CDs.dat |

| |

|Line Dancing Helen Starks Country For All Barbara Mender |

|Western Way Mingo Colfax |

Tutorial 8, Lesson B

Questions

1. e startup

2. c Project

3. b Call DoubleNumber(intNumber)

4. c passing

5. b receiving

6. a Call PrintHeading

7. e Private Sub DisplayName(strFriendName as String)

8. e Private Sub UpdateAge(strFriendName as String, intAge as Integer)

9. c Object Browser

10. a The names of the receiving procedure’s variables must be identical to the names of the variables listed in

the Call statement.

11. d by value

12. c by reference

13. d by value

14. c by reference

15. c by reference

Exercises

1. The student should submit a printout of the code. On the printout, the student should record the contents of the intNum and intNumber variables, as well as why the Display button printed those numbers.

|Private Sub cmdDisplay_Click() |

|Dim intNumber As Integer |

|intNumber = 10 |

|Call DoubleNumber(intNumber) |

|lblNumber.Caption = intNumber |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmLb1 |

|End Sub |

| |

|Private Sub DoubleNumber(intNum As Integer) |

|intNum = intNum * 2 |

|lblNum.Caption = intNum |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmLb1.Height) / 2 |

|frmLb1.Left = (Screen.Width - frmLb1.Width) / 2 |

|End Sub |

step f: intNum contains 20, and intNumber contains 10. Because the DoubleNumber procedure did not have access to the intNumber variable, the contents of the intNumber variable was not multiplied by 2. The intNumber variable, therefore, contains its original value of 10. The intNum variable received the 10 from the Display button’s Click event. The 10 was stored in a separate memory location, which was subsequently multiplied by 2.

2. lb2Done project – The student should submit three printouts of the interface, a printout of the student list, and a printout of the code. Changes to the original code are shaded.

Printout #1: Printout #2

[pic] [pic]

Printout #3:

[pic]

| Student List |

| |

|Name Grade |

|Paul Penny C |

|Mark Place B |

|Janice Jones F |

| |

|End of report |

|lb2Done.bas |

|Option Explicit |

|Type StudStruc |

|strName As String * 20 |

|strGrade As String * 1 |

|End Type |

| |

|lb2Done.frm |

|Option Explicit |

| |

|Private Sub chkDone_Click(Index As Integer) |

|Dim intCount As Integer, strChecked As String |

|If chkDone(Index).Value = vbChecked Then 'if check box is selected |

|cmdDisplay.Enabled = True |

|txtScore(Index).Enabled = True |

|txtScore(Index).SetFocus |

|Else 'if check box is deselected |

|txtScore(Index).Text = 0 |

|txtScore(Index).Enabled = False |

|strChecked = "N" 'assume that no check boxes are selected |

|Do While intCount = 20000 Then |

|sngRate = 0.06 |

|Else |

|sngRate = 0.05 |

|End If |

|sngNew = sngOld + sngOld * sngRate |

|txtOldSalary.Text = Format(sngOld, "currency") |

|lblRate.Caption = Format(sngRate, "percent") |

|lblNewSalary.Caption = Format(sngNew, "currency") |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmSalary |

|End Sub |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmSalary.Height) / 2 |

|frmSalary.Left = (Screen.Width - frmSalary.Width) / 2 |

|End Sub |

| |

|Private Sub txtOldSalary_GotFocus() |

|txtOldSalary.SelStart = 0 |

|txtOldSalary.SelLength = Len(txtOldSalary.Text) |

|End Sub |

Tutorial 10, Lesson A

Questions

1. a,c,e are related in some way, have the same data type, have the same name

2. e subscript

3. d intStock sub 2

4. c Variable arrays use many more variable names.

5. e Dim strItem(1 To 5) as String

6. a You use the Dim statement to fill an array with data.

7. b Mary

8. b replace the name “Patrick” with the name “Jan”

9. b replace the name “Tom” with the name “Sue”

10. c replace the 500 amount with 510

11. a replace the 500 amount with 12000

12. a 22000

13. e If intX >= 1 and intX = 0 Then |

|strFound = "N" |

|intX = 5 |

|Do While intX > 0 And strFound = "N" |

|If intPoints(intX) = 0 Then |

|strFound = "N" |

|intX = 1 |

|Do While intX = intNum Then |

|lblGrade.Caption = strGrades(intX) |

|strFound = "Y" |

|Else |

|intX = intX + 1 |

|End If |

|Loop |

|Else |

|intUser = MsgBox("Incorrect number of points.", conBtns, "Entry Error") |

|End If |

|txtPoints.SetFocus |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmGrade |

|End Sub |

| |

|Private Sub cmdPrint_Click() |

|PrintForm |

|End Sub |

|Private Sub Form_Load() |Private Sub txtPoints_Change() |

| = (Screen.Height - frmGrade.Height) / 2 |lblGrade.Caption = "" |

|frmGrade.Left = (Screen.Width - frmGrade.Width) / 2 |End Sub |

|intpoints(1) = 299 | |

|intpoints(2) = 349 |Private Sub txtPoints_GotFocus() |

|intpoints(3) = 399 |txtPoints.SelStart = 0 |

|intpoints(4) = 449 |txtPoints.SelLength = Len(txtPoints.Text) |

|intpoints(5) = 500 |End Sub |

|strGrades(1) = "F" | |

|strGrades(2) = "D" | |

|strGrades(3) = "C" | |

|strGrades(4) = "B" | |

|strGrades(5) = "A" | |

|End Sub | |

9. la9Done project – The student should submit two printouts of the interface with the test data showing and a printout of the application’s code.

[pic] [pic]

|Option Explicit |

|Dim intPoints(1 To 5) As Integer, strGrades(1 To 5) As String |

| |

|Private Sub cmdDisplay_Click() |

|Dim intX As Integer, intNum As Integer, strFound As String, intUser As Integer |

|Const conBtns As String = _ |

|vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal |

|intNum = Val(txtPoints.Text) |

|If intNum >= 0 Then |

|strFound = "N" |

|intX = 5 |

|Do While intX > 0 And strFound = "N" |

|If intPoints(intX) = 0 Then |

|strFound = "N" |

|intX = 5 |

|Do While intX > 0 And strFound = "N" |

|If udtGrades(intX).intPoints 20 Then 'invalid entry |

|intUser = MsgBox("Error in student number", conBtns, "Entry Error") |

|Else |

|'get increase amount |

|intIncrease = Val(InputBox("Enter the number of additional points:", "Points")) |

|If strStudNum = "A" Then 'add additional points to each score in the array |

|For intX = 1 To 20 |

|intScoreArray(intX) = intScoreArray(intX) + intIncrease |

|Next intX |

|Else 'update individual student's score |

|intScoreArray(intStudNum) = intScoreArray(intStudNum) + intIncrease |

|End If |

|lblMsg.Caption = "Score(s) updated by" 'display message |

|lblAnswer.Caption = intIncrease |

|Open "a:\Tut10\Test14.dat" For Output As #1 'open file |

|For intX = 1 To 20 'write array contents to file |

|Write #1, intScoreArray(intX) |

|Next intX |

|Close #1 'close file |

|End If |

|End Sub |

15. la15Done project – The student should submit a printout of the application’s code.

|Option Explicit |

|Dim intCounter(1 To 3, 1 To 4) As Integer |

| |

|Private Sub Form_Load() |

| = (Screen.Height - frmPao.Height) / 2 |

|frmPao.Left = (Screen.Width - frmPao.Width) / 2 |

|lstAge.AddItem "18 - 35" |

|lstAge.AddItem "36 - 50" |

|lstAge.AddItem "51 - 65" |

|lstAge.AddItem "Over 65" |

|lstParty.AddItem "Republican" |

|lstParty.AddItem "Independent" |

|lstParty.AddItem "Democrat" |

|lstParty.ListIndex = 0 |

|lstAge.ListIndex = 1 |

|End Sub |

|Private Sub cmdDisplay_Click() |

|Dim strParty As String, intAge As Integer |

|Dim intRow As Integer, intCol As Integer |

|For intRow = 1 To 3 'initialize array |

|For intCol = 1 To 4 |

|intCounter(intRow, intCol) = 0 |

|Next intCol |

|Next intRow |

| |

|Open "a:\tut10\pao.dat" For Input As #1 'open the sequential file |

|Do While Not EOF(1) |

|Input #1, strParty, intAge 'read a record |

|Select Case strParty 'update intCounter array |

|Case "Democrat" |

|intCounter(1, intAge + 1) = intCounter(1, intAge + 1) + 1 |

|Case "Republican" |

|intCounter(2, intAge + 1) = intCounter(2, intAge + 1) + 1 |

|Case "Independent" |

|intCounter(3, intAge + 1) = intCounter(3, intAge + 1) + 1 |

|End Select |

|Loop |

|Close #1 'close the file |

| |

|For intCol = 0 To 3 'display in label controls |

|lblDem(intCol).Caption = intCounter(1, intCol + 1) |

|lblRep(intCol).Caption = intCounter(2, intCol + 1) |

|lblInd(intCol).Caption = intCounter(3, intCol + 1) |

|Next intCol |

|End Sub |

| |

|Private Sub cmdEnter_Click() |

|Open "a:\tut10\pao.dat" For Append As #1 'open the sequential file |

|Write #1, lstParty.Text, lstAge.ListIndex 'write the record |

|Close #1 'close the file |

|End Sub |

| |

|Private Sub cmdExit_Click() |

|Unload frmPao |

|End Sub |

|Private Sub cmdPrint_Click() |

|Dim intRow As Integer, intCol As Integer, intDem As Integer, intRep As Integer |

|Dim intInd As Integer, intTotal As Integer |

|Dim strFont As String, sngSize As Single |

|Dim strPS1 As String * 3, strPS2 As String * 3, strPS3 As String * 3 |

|Dim strPS4 As String * 3, strPS5 As String * 4 |

|'accumulate totals |

|For intCol = 1 To 4 |

|intDem = intDem + intCounter(1, intCol) |

|intRep = intRep + intCounter(2, intCol) |

|intInd = intInd + intCounter(3, intCol) |

|Next intCol |

|intTotal = intDem + intRep + intInd |

|strFont = Printer.Font 'save current printer settings |

|sngSize = Printer.FontSize |

|Printer.Font = "courier new" 'change printer settings |

|Printer.FontSize = 10 'print title and headings |

|Printer.Print Tab(30); "PAO Information - 1999" |

|Printer.Print |

|Printer.Print Tab(5); "Party"; Tab(20); "18-35"; Tab(30); "36-50"; _ |

|Tab(40); "51-65"; Tab(50); "Over 65"; Tab(60); "Total" |

|'align democrat numbers and print |

|RSet strPS1 = Format(intCounter(1, 1), "general number") |

|RSet strPS2 = Format(intCounter(1, 2), "general number") |

|RSet strPS3 = Format(intCounter(1, 3), "general number") |

|RSet strPS4 = Format(intCounter(1, 4), "general number") |

|RSet strPS5 = Format(intDem, "general number") |

|Printer.Print Tab(5); "Democrat"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|'align republican numbers and print |

|RSet strPS1 = Format(intCounter(2, 1), "general number") |

|RSet strPS2 = Format(intCounter(2, 2), "general number") |

|RSet strPS3 = Format(intCounter(2, 3), "general number") |

|RSet strPS4 = Format(intCounter(2, 4), "general number") |

|RSet strPS5 = Format(intRep, "general number") |

|Printer.Print Tab(5); "Republican"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|'align independent numbers and print |

|RSet strPS1 = Format(intCounter(3, 1), "general number") |

|RSet strPS2 = Format(intCounter(3, 2), "general number") |

|RSet strPS3 = Format(intCounter(3, 3), "general number") |

|RSet strPS4 = Format(intCounter(3, 4), "general number") |

|RSet strPS5 = Format(intInd, "general number") |

|Printer.Print Tab(5); "Independent"; Tab(22); strPS1; Tab(32); strPS2; _ |

|Tab(42); strPS3; Tab(54); strPS4; Tab(61); strPS5 |

|Printer.Print 'print two blank lines |

|Printer.Print |

|'print grand total |

|RSet strPS5 = Format(intTotal, "general number") |

|Printer.Print Tab(41); "Total respondents"; Tab(61); strPS5 |

|Printer.Print 'print a blank line |

|Printer.Print Tab(5); "End of report" 'print message |

|Printer.EndDoc 'send report to printer |

|Printer.Font = strFont |

|Printer.FontSize = sngSize |

|End Sub |

Tutorial 10, Lesson B

Questions

1. a,e ConnectionString, RecordSource

2. d DataSource

3. b cell

4. c right-click

5. c AllowUpdate

6. a Columns

7. c Format

8. d Locked

9. e Layout

10. d Edit, Edit

11. a,b,d AfterColEdit, AfterColUpdate, BeforeColUpdate

12. c,e AfterUpdate, BeforeUpdate

13. e adoNum.Recordset.Fields(“fldTot”) = adoNum.Recorset.Fields(“fldNum1”) * 3

14. b Dim objFlds as Object

15. e Set objFlds = adoNum.Recordset.Fields

16. c objFlds(“fldTot”) + Round(objFlds(“fldNum1”) * .15, 3)

Exercises

1. lb1Done project – The student should submit three printouts of the interface with the test data showing and three printouts of the code.

Printout #1 (step g): Printout #2 (step h): [pic] [pic]

Printout #3 (step i):

[pic]

|Code (step g) | |

|Option Explicit | |

| | |

|Private Sub dgdSales_AfterColUpdate(ByVal ColIndex As Integer) | |

|adoSales.Recordset.Fields(“fldCommission”) = _ | |

|Round(adoSales.Recordset.Fields(“fldSales”) * 0.1, 2) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmSales.Left = (Screen.Width – frmSales.Width) / 2 | |

| = (Screen.Height – frmSales.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmSales | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

|Code (step h) | |

|Option Explicit | |

| | |

|Private Sub dgdSales_AfterColUpdate(ByVal ColIndex As Integer) | |

|Dim objFlds As Object | |

|Set objFlds = adoSales.Recordset.Fields | |

|objFlds(“fldCommission”) = Round(objFlds(“fldSales”) * 0.1, 2) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmSales.Left = (Screen.Width – frmSales.Width) / 2 | |

| = (Screen.Height – frmSales.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmSales | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

|Code (step i) | |

|Option Explicit | |

| | |

|Private Sub dgdSales_AfterColUpdate(ByVal ColIndex As Integer) | |

|Dim objRec As Recordset | |

|Set objRec = adoSales.Recordset | |

|objRec.Fields(“fldCommission”) = _ | |

|Round(objRec.Fields(“fldSales”) * 0.1, 2) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmSales.Left = (Screen.Width – frmSales.Width) / 2 | |

| = (Screen.Height – frmSales.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmSales | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

2. lb2Done project – The student should submit three printouts of the interface with the test data showing and three printouts of the code.

Printout #1 (step g): Printout #2 (step h):

[pic] [pic]

Printout #3 (step i):

[pic]

|Code (step g) | |

|Option Explicit | |

| | |

|Private Sub dgdPrice_AfterColUpdate(ByVal ColIndex As Integer) | |

|adoPrice.Recordset.Fields(“fldNewPrice”) = _ | |

|Round(adoPrice.Recordset.Fields(“fldCurPrice”) * _ | |

|(1 + adoPrice.Recordset.Fields(“fldIncrease”)), 2) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmPrice.Left = (Screen.Width – frmPrice.Width) / 2 | |

| = (Screen.Height – frmPrice.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmPrice | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

|Code (step h) | |

|Option Explicit | |

| | |

|Private Sub dgdPrice_AfterColUpdate(ByVal ColIndex As Integer) | |

|Dim objFlds As Object | |

|Set objFlds = adoPrice.Recordset.Fields | |

|objFlds(“fldNewPrice”) = Round(objFlds(“fldCurPrice”) * _ | |

|(1 + objFlds(“fldIncrease”)), 2) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmPrice.Left = (Screen.Width – frmPrice.Width) / 2 | |

| = (Screen.Height – frmPrice.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmPrice | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

|Code (step i) | |

|Option Explicit | |

| | |

|Private Sub dgdPrice_AfterColUpdate(ByVal ColIndex As Integer) | |

|Dim objRec As Recordset | |

|Set objRec = adoPrice.Recordset | |

|objRec.Fields(“fldNewPrice”) = Round(objRec.Fields(“fldCurPrice”) * _ | |

|(1 + objRec.Fields(“fldIncrease”)), 2) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmPrice.Left = (Screen.Width – frmPrice.Width) / 2 | |

| = (Screen.Height – frmPrice.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmPrice | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

3. lb3Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

[pic]

|Option Explicit | |

| | |

|Private Sub dgdBills_AfterColUpdate(ByVal ColIndex As Integer) | |

|Dim objFlds As Object | |

|Set objFlds = adoBills.Recordset.Fields | |

|objFlds(“fldTotal”) = objFlds(“fldElectric”) + _ | |

|objFlds(“fldGas”) + objFlds(“fldWater”) | |

|End Sub | |

| | |

|Private Sub Form_Load() | |

|frmBills.Left = (Screen.Width – frmBills.Width) / 2 | |

| = (Screen.Height – frmBills.Height) / 2 | |

|End Sub | |

| | |

|Private Sub mnuFileExit_Click() | |

|Unload frmBills | |

|End Sub | |

| | |

|Private Sub mnuFilePrint_Click() | |

|PrintForm | |

|End Sub | |

4. lb4Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

[pic]

|Option Explicit | |

|Dim strTitles(1 To 4) As String | |

| | |

|Private Sub dgdEmp_AfterColUpdate(ByVal ColIndex As Integer) | |

|Dim objFlds As Object, intCode As Integer | |

|Set objFlds = adoEmp.Recordset.Fields | |

|intCode = Val(objFlds(“fldCode”)) | |

|If intCode >= 1 And intCode ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download