481
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 1

Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

  • Upload
    lamminh

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Programming with Microsoft Visual Basic 6.0 – Enhanced EditionAnswers to Questions and Exercises

Table of Contents

Tutorial 1, Lesson A Page 1Tutorial 1, Lesson B Page 4Tutorial 1, Lesson C Page 7Tutorial 1, Debugging Page 17

Tutorial 2, Lesson A Page 20Tutorial 2, Lesson B Page 24Tutorial 2, Lesson C Page 26Tutorial 2, Debugging Page 74

Tutorial 3, Lesson A Page 75Tutorial 3, Lesson B Page 76Tutorial 3, Lesson C Page 82Tutorial 3, Debugging Page 93

Tutorial 4, Lesson A Page 95Tutorial 4, Lesson B Page 106Tutorial 4, Lesson C Page 109Tutorial 4, Debugging Page 113

Tutorial 5, Lesson A Page 116Tutorial 5, Lesson B Page 122Tutorial 5, Lesson C Page 126Tutorial 5, Debugging Page 134

Tutorial 6, Lesson A Page 135Tutorial 6, Lesson B Page 156Tutorial 6, Lesson C Page 161Tutorial 6, Debugging Page 174

Tutorial 7, Lesson A Page 175Tutorial 7, Lesson B Page 176Tutorial 7, Lesson C Page 179Tutorial 7, Debugging Page 194

Tutorial 8, Lesson A Page 196Tutorial 8, Lesson B Page 203Tutorial 8, Lesson C Page 213Tutorial 8, Debugging Page 227

Tutorial 9, Lesson A Page 230Tutorial 9, Lesson B Page 234

1

Page 2: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 9, Lesson C Page 244Tutorial 9, Debugging Page 251

Tutorial 10, Lesson A Page 252Tutorial 10, Lesson B Page 274Tutorial 10, Lesson C Page 283Tutorial 10, Debugging Page 292

Tutorial 11, Lesson A Page 293Tutorial 11, Lesson B Page 294

Tutorial 12, Lesson A Page 297Tutorial 12, Lesson B Page 299

2

Page 3: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 1, Lesson AQuestions1. b form2. b toolbox3. d Properties4. e .frm5. e .vbp6. a BackColor7. a Caption8. c Caption9. d Name10. d Name11. H Form window I Properties List

D Main window A Properties windowC Menu bar J Settings boxE Object box B ToolbarG 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.

Exercises1. Text shaded gray indicates specific application requirements to note. The student should

submit a printout of the Form As Text.VERSION 5.00Begin VB.Form frmCharity BackColor = &H00800000& Caption = "Charities Unlimited" ClientHeight = 4140 ClientLeft = 1035 ClientTop = 1515 ClientWidth = 8220 LinkTopic = "Form1" PaletteMode = 1 'UseZOrder ScaleHeight = 4140 ScaleWidth = 8220 Begin VB.Label Label1 BackColor = &H00FFFF80&

BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 0 Weight = 700 Underline = 0 'False Italic = -1 'True Strikethrough = 0 'False EndProperty Height = 1935 Left = 120 TabIndex = 0 Top = 720 Width = 7935

3

Page 4: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Caption = "Please help Charities Unlimited help others."

EndEnd

4

Page 5: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

VERSION 5.00Begin VB.Form frmPhotos BackColor = &H000000FF& Caption = "Photos Inc." ClientHeight = 4140 ClientLeft = 1200 ClientTop = 1515 ClientWidth = 6690 LinkTopic = "Form1" PaletteMode = 1 'UseZOrder ScaleHeight = 4140 ScaleWidth = 6690

Begin VB.Image Image1 Height = 3495 Left = 480 Picture = "La2.frx":0000 Stretch = -1 'True Top = 360 Width = 5775 EndEnd

3. A Caption B ForeColorB Enabled C IconB FillColor A LeftB FillStyle A NameC 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 Stackb. 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.

5

Page 6: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 1, Lesson BQuestions1. a F12. d Label3. d twips4. c points5. e AutoSize6. a Form7. 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 <filename> 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.

Exercises1. lb1Done project—Text shaded gray indicates specific application requirements to note. The

student should submit a printout of the Form As Text.VERSION 5.00Begin VB.Form frmIMA BackColor = &H00FFFFFF& Caption = "IMA" ClientHeight = 3915 ClientLeft = 1155 ClientTop = 1545 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

Height = 300 Left = 795 TabIndex = 0 Top = 1000 Width = 4365 EndEnd

6

Page 7: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

VERSION 5.00Begin VB.Form frmJefferson BackColor = &H00FFFFC0& Caption = "Jefferson Cleaning Inc." ClientHeight = 3915 ClientLeft = 1440 ClientTop = 1515 ClientWidth = 6585 LinkTopic = "Form1" ScaleHeight = 3915 ScaleWidth = 6585 Begin VB.Label Label2 AutoSize = -1 'True BackColor = &H00FFFFFF& Caption = "Jefferson Cleaning Inc." BeginProperty Font Name = "Arial" 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"

BeginProperty Font Name = "Arial" Size = 24 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 540 Left = 2055 TabIndex = 0 Top = 1200 Width = 2670 EndEnd

7

Page 8: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

VERSION 5.00Begin VB.Form frmYorktown BackColor = &H0080FFFF& Caption = "Yorktown Shopping Center" ClientHeight = 3915 ClientLeft = 1155 ClientTop = 1545 ClientWidth = 6585 LinkTopic = "Form1" ScaleHeight = 3915 ScaleWidth = 6585 Begin VB.Label Label2 AutoSize = -1 'True BackColor = &H0080FFFF& Caption = "Your one-stop shopping center" BeginProperty Font Name = "Arial" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = -1 'True Strikethrough = 0 'False EndProperty Height = 270 Left = 1560 TabIndex = 1 Top = 2040 Width = 3480 End

Begin VB.Label Label1 AutoSize = -1 'True BackColor = &H0080FFFF& Caption = "The Yorktown Mall of Kentucky"BeginProperty Font Name = "Arial" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 285 Left = 1530 TabIndex = 0 Top = 1440 Width = 3540 EndEnd

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.

8

Page 9: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 1, Lesson CQuestions1. e Picture2. b End3. b Form As Text4. a Code5. b events6. c event procedures7. e syntax8. e keyword9. a BorderStyle10. e Selection11. a Current Module12. c Form As Text13. 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 <projectname.exe> 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.

Exercises1. 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.)

VERSION 5.00Begin VB.Form frmAnimal BackColor = &H00FFFFFF& Caption = "Peoria Animal Shelter" ClientHeight = 5130 ClientLeft = 1155 ClientTop = 1545

Begin VB.Image imgLogo Height = 2820 Left = 840 Picture = "lc1Done.frx":0000 Stretch = -1 'True Top = 1080 Width = 4755

9

Page 10: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

ClientWidth = 6585 LinkTopic = "Form1" ScaleHeight = 5130 ScaleWidth = 6585 Begin VB.Frame Frame1 Caption = "Click the logo" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 4935 Left = 120 TabIndex = 0 Top = 120 Width = 6375 Begin VB.CommandButton cmdExit Caption = "Exit" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 5280 TabIndex = 2 Top = 4320 Width = 855 End

End Begin VB.Label lblTitle AutoSize = -1 'True Caption = "Welcome to the Peoria Animal Shelter" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 300 Left = 840 TabIndex = 1 Top = 600 Visible = 0 'False Width = 4560 End EndEnd

Code:Private Sub cmdExit_Click() EndEnd Sub

Private Sub imgLogo_Click() lblTitle.Visible = TrueEnd Sub

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.00Begin VB.Form frmOnOff Caption = "On and Off" ClientHeight = 2940

Begin VB.Image imgOnOff Height = 1410 Left = 720 Picture = "lc3Done.frx":0000

10

Page 11: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

ClientLeft = 2415 ClientTop = 1560 ClientWidth = 4440 LinkTopic = "Form1" ScaleHeight = 2940 ScaleWidth = 4440 Begin VB.CommandButton cmdExit Caption = "Exit" Height = 495 Left = 2880 TabIndex = 2 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdOff Caption = "Off" Height = 495 Left = 1560 TabIndex = 1 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdOn Caption = "On" Height = 495 Left = 240 TabIndex = 0 Top = 2040 Width = 1215 End

Stretch = -1 'True Top = 240 Width = 2955 EndEnd

Code:Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdOff_Click() imgOnOff.Visible = FalseEnd Sub

Private Sub cmdOn_Click() imgOnOff.Visible = TrueEnd Sub

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.

11

Page 12: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 1 – Debugging

TechniqueThe 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.

Exercises1. 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.00Begin VB.Form frmGlamour Appearance = 0 'Flat BackColor = &H00C0C0C0& Caption = "Glamour-Us" ClientHeight = 4320 ClientLeft = 1275 ClientTop = 1455 ClientWidth = 7485 BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& LinkTopic = "Form1" MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 4320 ScaleWidth = 7485

Begin VB.Label LblTitle Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BackStyle = 0 'Transparent Caption = "Glamour-Us Beauty Salon" BeginProperty Font Name = "MS Sans Serif" Size = 24 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 555 Left = 720 TabIndex = 0 Top = 1200 Width = 5925 EndEnd

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:Private Sub Command1_Click() EndEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Code from step k:Private Sub cmdExit_Click() EndEnd Sub

17

Page 13: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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() lblMessage.Caption = "OK"End Sub

Private Sub cmdExit_Click() EndEnd 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 aVERSION 5.00Begin VB.Form frmDebug4 Appearance = 0 'Flat BackColor = &H00C0C0C0& BorderStyle = 1 'Fixed Single Caption = "Debugging Exercise 4" ClientHeight = 2160 ClientLeft = 1845 ClientTop = 2175 ClientWidth = 5355 BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& LinkTopic = "Form1" MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 2160 ScaleWidth = 5355 Begin VB.CommandButton cmdExit Appearance = 0 'Flat BackColor = &H00C0C0C0& Caption = "Command1" 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

Begin VB.Label lblNote Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H00C0C0C0& BackStyle = 0 'Transparent Caption = "The command button should end the application:" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 195 Left = 240 TabIndex = 0 Top = 1080 Width = 3465 EndEnd

Code:Private Sub cmdExit_DragDrop(Source As Control, X As Single, Y As Single) End

End Sub

18

Page 14: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Step fVERSION 5.00Begin VB.Form frmDebug4 Appearance = 0 'Flat BackColor = &H00C0C0C0& BorderStyle = 1 'Fixed Single Caption = "Debugging Exercise 4" ClientHeight = 2160 ClientLeft = 1845 ClientTop = 2175 ClientWidth = 5355 BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& LinkTopic = "Form1" MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 2160 ScaleWidth = 5355 Begin VB.CommandButton cmdExit Appearance = 0 'Flat BackColor = &H00C0C0C0& 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

Begin VB.Label lblNote Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H00C0C0C0& BackStyle = 0 'Transparent Caption = "The command button should end the application:" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 195 Left = 240 TabIndex = 0 Top = 1080 Width = 3465 EndEnd

Code:Private Sub cmdExit_Click() EndEnd Sub

19

Page 15: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 2, Lesson A

Questions1. c label2. e text box3. a command button4. e TOE5. a either horizontally or vertically6. d upper-left corner7. e either a (a frame) or d (white space)

20

Page 16: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 screen9. d six10. a first11. d A command button’s caption should end with a colon (:).12. b sentence capitalization13. c Labels for controls (other than command buttons) shoud be entered using book title

capitalization.14. b sentence capitalization15. a book title capitalization16. 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.

Exercises1. 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 EventGet the following from the user: name territory sales

txtNametxtTerritorytxtSales

NoneNoneNone

Calculate the commission cmdCalc ClickDisplay the following: name territory sales commission

txtNametxtTerritorytxtSalescmdCalc, lblComm

NoneNoneNoneClick, None

Print the interface cmdPrint ClickEnd the application cmdExit ClickClear the screen cmdClear Click

Task Object Event1. Calculate the commission 2. Display the commission

in the lblComm control

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit Click

21

Page 17: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Print the interface cmdPrint ClickDisplay the commission (from cmdCalc)

lblComm None

Get and display the name, territory, and sales

txtName, txtTerritory, txtSales

None

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

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 EventGet the following from the user: current year’s sales for each region projected increase % for each region

txtNsales, txtSsales, txtEsales, txtWsalestxtNinc, txtSinc, txtEinc, txtWinc

NoneNone

Calculate the projected sales for each region

cmdCalc Click

Display the following: current year’s sales for each region projected increase % for each region projected sales for each region

txtNsales, txtSsales, txtEsales, txtWsalestxtNinc, txtSinc, txtEinc, txtWinccmdCalc, lblNsales, lblSsales, lblEsales, lblWsales

NoneNoneClick, None, None, None, None

Print the interface cmdPrint ClickEnd the application cmdExit ClickClear the screen cmdClear Click

Task Object Event1. Calculate the projected sales

for each region2. Display the projected

sales in the lblNsales, lblSsales, lblEsales, and lblWsales controls

cmdCalc Click

Clear the screen cmdClear Click

22

Page 18: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the projected sales (from cmdCalc)

lblNsales, lblSsales, lblEsales, lblWsales

None

Get and display the projected increase % for each region

txtNinc, txtSinc, txtEinc, txtWinc

None

Get and display the current year’s sales for each region

txtNsales, txtSsales, txtEsales, txtWsales

None

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

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

23

Page 19: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 2, Lesson B

Questions1. c TabIndex2. b two or three3. a the same height4. c the same height and the same width5. e both b (color before black and white) and c (graphics before text)6. b dark text on a light background7. b 8, 10, or 12 point8. a one or two9. a sans serif10. a one11. d all of the above12. d BorderStyle13. a Appearance14. b BackStyle15. a &16. b Caption17. 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.

Exercises1. lb1Done project – The student is instructed to print the interface. The background color is a

pale yellow.

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

24

Page 20: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

25

Page 21: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 2, Lesson C

Questions1. e PrintForm2. d txtName.Text = “Jones”3. e None of the above is valid4. e All of the above are correct5. a Close6. d ControlBox7. b Format8. e Val9. 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 error11. b a syntax error

26

Page 22: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1. lc1Done project - The student should submit a printout of the interface and the code. The

background color is a pale yellow.

Private Sub cmdCalc_Click() lblComm.Caption = Val(txtSales.Text) * 0.1 lblComm.Caption = Format(lblComm.Caption, "currency") cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtName.Text = "" txtTerritory.Text = "" txtSales.Text = "" lblComm.Caption = "" txtName.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

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

27

Page 23: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdCalc_Click() lblNSales.Caption = Val(txtNsales.Text) + _ Val(txtNsales.Text) * Val(txtNinc.Text) lblSsales.Caption = Val(txtSsales.Text) + _ Val(txtSsales.Text) * Val(txtSinc.Text) lblEsales.Caption = Val(txtEsales.Text) + _ Val(txtEsales.Text) * Val(txtEinc.Text) lblWsales.Caption = Val(txtWsales.Text) + _ Val(txtWsales.Text) * Val(txtWinc.Text) lblNSales.Caption = Format(lblNSales.Caption, "standard") lblSsales.Caption = Format(lblSsales.Caption, "standard") lblEsales.Caption = Format(lblEsales.Caption, "standard") lblWsales.Caption = Format(lblWsales.Caption, "standard") cmdPrint.SetFocusEnd 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.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

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

28

Page 24: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Convert twips to inches 2. Display inches in lblInches control

cmdConvert Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay 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 controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtTwips controlClear the Caption property of the lblInches controlSend the focus to the txtTwips control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

29

Page 25: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Printout # 1: Printout # 2:

VERSION 5.00Begin VB.Form frmTwips Caption = "Twips to Inches" ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 3915 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 3915 Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2400 TabIndex = 5 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 2400 TabIndex = 4 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2400 TabIndex = 3 Top = 840 Width = 1215 EndBegin VB.CommandButton cmdConvert Caption = "&Convert" Height = 495 Left = 2400 TabIndex = 2 Top = 240 Width = 1215 End

Begin VB.TextBox txtTwips Height = 285 Left = 1200 TabIndex = 1 Top = 240 Width = 975 End Begin VB.Label lblInches Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1200 TabIndex = 7 Top = 600 Width = 975 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Inches:" Height = 195 Left = 240 TabIndex = 6 Top = 600 Width = 525 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Enter &twips:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 825 EndEnd

30

Page 26: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdClear_Click() txtTwips.Text = "" lblInches.Caption = "" txtTwips.SetFocusEnd Sub

Private Sub cmdConvert_Click() lblInches.Caption = Val(txtTwips.Text) / 1440 cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() cmdConvert.Visible = False cmdPrint.Visible = False cmdClear.Visible = False cmdExit.Visible = False PrintForm cmdConvert.Visible = True cmdPrint.Visible = True cmdClear.Visible = True cmdExit.Visible = True cmdClear.SetFocusEnd 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 Event1. Calculate ending balance 2. Display ending balance in lblEnd

control

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the ending balance (from cmdCalc)

lblEnd None

Get and display the beginning balance, monthly earnings, monthly expenses

txtBegin, txtEarn, txtExpense

None

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

expensesDisplay ending balance in lblEnd controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtBegin, txtEarn, txtExpense controlsClear the Caption property of the lblEnd controlSend the focus to the txtBegin control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

31

Page 27: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Printout # 1: Printout # 2:

VERSION 5.00Begin VB.Form frmLee Caption = "John Lee's Finances" ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4620 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 4620 Begin VB.TextBox txtExpense Height = 285 Left = 1680 TabIndex = 5 Top = 960 Width = 975 End Begin VB.TextBox txtEarn Height = 285 Left = 1680 TabIndex = 3 Top = 600 Width = 975 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 3120 TabIndex = 9 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 3120 TabIndex = 8 Top = 1440 Width = 1215 EndBegin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 3120 TabIndex = 7 Top = 840 Width = 1215

Begin VB.TextBox txtBegin Height = 285 Left = 1680 TabIndex = 1 Top = 240 Width = 975 End Begin VB.Label Label4 AutoSize = -1 'True Caption = "&Monthly &expenses:" Height = 195 Left = 240 TabIndex = 4 Top = 960 Width = 1320 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Ending balance:" Height = 195 Left = 240 TabIndex = 11 Top = 1320 Width = 1155 End Begin VB.Label lblEnd Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1680 TabIndex = 10 Top = 1320 Width = 975 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "&Monthly earnings:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 1245 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Beginning balance:"

32

Page 28: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 3120 TabIndex = 6 Top = 240 Width = 1215 End

Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 1365 EndEnd

Private Sub cmdCalc_Click() lblEnd.Caption = Val(txtBegin.Text) + Val(txtEarn.Text) _ - Val(txtExpense.Text) cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtBegin.Text = "" txtEarn.Text = "" txtExpense.Text = "" lblEnd.Caption = "" txtBegin.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate average of three numbers 2. Display average in lblAverage control

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the average (from cmdCalc) lblAverage NoneGet and display the first number, second number, and third number

txtFirst, txtSecond,txtThird

None

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

Display average in lblAverage controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtFirst, txtSecond, txtThird controlsClear the Caption property of the lblAverage controlSend the focus to the txtFirst control

cmdExit: End the application

cmdPrint Hide the command buttons33

Page 29: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Print the formDisplay the command buttonsSend the focus to the Clear Screen button

Printout # 1: Printout # 2:

VERSION 5.00Begin VB.Form frmJones Caption = "Average Calculator" ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4620 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 4620 Begin VB.TextBox txtThird Height = 285 Left = 1680 TabIndex = 5 Top = 960 Width = 975 End Begin VB.TextBox txtSecond Height = 285 Left = 1680 TabIndex = 3 Top = 600 Width = 975 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 3120 TabIndex = 9 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 3120 TabIndex = 8 Top = 1440 Width = 1215 EndBegin VB.CommandButton cmdPrint Caption = "&Print"

Begin VB.TextBox txtFirst Height = 285 Left = 1680 TabIndex = 1 Top = 240 Width = 975 EndBegin VB.Label Label4 AutoSize = -1 'True Caption = "&Third number:" Height = 195 Left = 240 TabIndex = 4 Top = 960 Width = 975 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Average:" Height = 195 Left = 240 TabIndex = 11 Top = 1320 Width = 645 End Begin VB.Label lblAverage Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1680 TabIndex = 10 Top = 1320 Width = 975 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "&Second number:" Height = 195 Left = 240 TabIndex = 2 Top = 600

34

Page 30: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Height = 495 Left = 3120 TabIndex = 7 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 3120 TabIndex = 6 Top = 240 Width = 1215 End

Width = 1170 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&First number:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 900 EndEnd

Private Sub cmdCalc_Click() lblAverage.Caption = (Val(txtFirst.Text) + _ Val(txtSecond.Text) + Val(txtThird.Text)) / 3 cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtFirst.Text = "" txtSecond.Text = "" txtThird.Text = "" lblAverage.Caption = "" txtFirst.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate the paperback value, hardcover

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

2. Display the calculated amounts in the lblPaperVal, lblHardVal, lblTotalNum, and lblTotalVal controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the paperback value, hardcover value, total number of paperbacks and hardcover versions, and total value of paperback and hardcover versions (from cmdCalc)

lblPaperVal, lblHardVal, lblTotalNum, lblTotalVal

None

Get and display the title, number of txtTitle, None

35

Page 31: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

paperback versions, number of hardcover versions, cost of paperback version, cost of hardcover version

txtNumPaper, txtNumHard, txtCostPaper, txtCostHard

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

Calculate hardcover value = number of hardcover versions * hardcover costCalculate total number of paperback and hardcover versions = number of

paperback versions + number of hardcover versionsCalculate total value of paperback and hardcover versions = paperback value +

hardcover valueDisplay 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 buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

Printout # 1: Printout # 2:

VERSION 5.00Begin VB.Form frmBookworms Caption = "Bookworms Inc." ClientHeight = 3540 ClientLeft = 2370 ClientTop = 1770 ClientWidth = 5655 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 3540 ScaleWidth = 5655 Begin VB.TextBox txtNumHard Height = 285 Left = 697 TabIndex = 7

Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 4200 TabIndex = 13 Top = 2760 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 2880 TabIndex = 12 Top = 2760 Width = 1215 End

36

Page 32: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Top = 1440 Width = 975 End Begin VB.TextBox txtCostHard Height = 285 Left = 2377 TabIndex = 9 Top = 1440 Width = 975 End Begin VB.TextBox txtCostPaper Height = 285 Left = 2377 TabIndex = 5 Top = 840 Width = 975 End Begin VB.TextBox txtNumPaper Height = 285 Left = 697 TabIndex = 3 Top = 840 Width = 975 End

Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 1560 TabIndex = 11 Top = 2760 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 240 TabIndex = 10 Top = 2760 Width = 1215 End Begin VB.TextBox txtTitle Height = 285 Left = 1177 TabIndex = 1 Top = 240 Width = 2535 End

Begin VB.Label lblHardVal Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 3697 TabIndex = 21 Top = 1440 Width = 975 End Begin VB.Label lblPaperVal Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 3697 TabIndex = 20 Top = 840 Width = 975 End Begin VB.Label Label10 AutoSize = -1 'True Caption = "Total versions:" Height = 195 Left = 697 TabIndex = 19 Top = 2040 Width = 1035 End

Begin VB.Label Label7 AutoSize = -1 'True Caption = "Number of &hardcover:" Height = 195 Left = 697 TabIndex = 6 Top = 1200 Width = 1545 End Begin VB.Label Label6 AutoSize = -1 'True Caption = "&Har&dcover cost:" Height = 195 Left = 2377 TabIndex = 8 Top = 1200 Width = 1140 End Begin VB.Label Label5 AutoSize = -1 'True Caption = "Hardcover value:" Height = 195 Left = 3697 TabIndex = 16 Top = 1200 Width = 1230 End Begin VB.Label Label4 AutoSize = -1 'True Caption = "&Paper&back cost:" Height = 195 Left = 2377 TabIndex = 4

37

Page 33: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label Label9 AutoSize = -1 'True Caption = "Total value:" Height = 195 Left = 3697 TabIndex = 18 Top = 2040 Width = 840 End Begin VB.Label lblTotalVal Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 3697 TabIndex = 17 Top = 2280 Width = 975 End

Top = 600 Width = 1170 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Paperback value:" Height = 195 Left = 3697 TabIndex = 15 Top = 600 Width = 1260 End Begin VB.Label lblTotalNum Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 697 TabIndex = 14 Top = 2280 Width = 975 End

Begin VB.Label Label2 AutoSize = -1 'True Caption = "&Number of paperback:" Height = 195 Left = 697 TabIndex = 2 Top = 600 Width = 1590 End

Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Title:" Height = 195 Left = 697 TabIndex = 0 Top = 240 Width = 345 EndEnd

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.SetFocusEnd Sub

Private Sub cmdClear_Click() txtTitle.Text = "" txtNumPaper.Text = "" txtNumHard.Text = "" txtCostPaper.Text = "" txtCostHard.Text = "" lblPaperVal.Caption = "" lblHardVal.Caption = "" lblTotalNum.Caption = "" lblTotalVal.Caption = "" txtTitle.SetFocusEnd Sub

Private Sub cmdExit_Click()38

Page 34: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

EndEnd 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.SetFocusEnd Sub

39

Page 35: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Event1. Calculate the discount and the new price 2. Display the discount and the new

price in the lblDisc and lblNewPrice controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay 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 – discountDisplay the discount in the lblDisc controlDisplay the new price in the lblNewPrice controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtOrigPrice controlClear the Caption property of the lblDisc and lblNewPrice controlsSend the focus to the txtOrigPrice control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

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

40

Page 36: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

VERSION 5.00Begin VB.Form frmJackets Caption = "Jackets Unlimited" ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4020 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 4020 Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2520 TabIndex = 5 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 2520 TabIndex = 4 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2520 TabIndex = 3 Top = 840 Width = 1215 EndBegin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2520 TabIndex = 2 Top = 240 Width = 1215 End Begin VB.TextBox txtOrigPrice Height = 285 Left = 1320 TabIndex = 1 Top = 240 Width = 975 End

Begin VB.Label Label4 AutoSize = -1 'True Caption = "New price:" Height = 195 Left = 240 TabIndex = 9 Top = 960 Width = 765 EndBegin VB.Label lblNewPrice Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1320 TabIndex = 8 Top = 960 Width = 975 End Begin VB.Label lblDisc Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1320 TabIndex = 7 Top = 600 Width = 975 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Discount:" Height = 195 Left = 240 TabIndex = 6 Top = 600 Width = 675 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Original price:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 960 EndEnd

41

Page 37: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdCalc_Click() lblDisc.Caption = Val(txtOrigPrice.Text) * 0.25 lblNewPrice.Caption = Val(txtOrigPrice.Text) - Val(lblDisc.Caption) lblDisc.Caption = Format(lblDisc.Caption, "standard") lblNewPrice.Caption = Format(lblNewPrice.Caption, "standard") cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtOrigPrice.Text = "" lblDisc.Caption = "" lblNewPrice.Caption = "" txtOrigPrice.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate the total due2. Display the total due in the lblTotal

control

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the total due (from cmdCalc) lblTotal NoneGet and display the name, number of typed envelopes, and number of typed pages

txtName, txtEnvelopes, txtPages

None

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

number of typed pages * .25Display the total due in the lblTotal controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtName, txtEnvelopes, and txtPages controlsClear the Caption property of the lblTotal controlSend the focus to the txtName control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

42

Page 38: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

VERSION 5.00Begin VB.Form frmTyping Caption = "Typing Salon" ClientHeight = 2775 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 5040 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2775 ScaleWidth = 5040 Begin VB.TextBox txtPages Height = 285 Left = 2880 TabIndex = 5 Top = 600 Width = 375 End Begin VB.TextBox txtEnvelopes Height = 285 Left = 1320 TabIndex = 3 Top = 600 Width = 375 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 3480 TabIndex = 9 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 3480 TabIndex = 8 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 3480 TabIndex = 7 Top = 840 Width = 1215 End

Begin VB.TextBox txtName Height = 285 Left = 1320 TabIndex = 1 Top = 240 Width = 1935 EndBegin VB.Label Label3 AutoSize = -1 'True Caption = "&Pages:" Height = 195 Left = 2280 TabIndex = 4 Top = 600 Width = 495 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "&Envelopes:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 795 End Begin VB.Label Label4 AutoSize = -1 'True Caption = "Total due:" Height = 195 Left = 240 TabIndex = 11 Top = 960 Width = 720 End Begin VB.Label lblTotal Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1320 TabIndex = 10 Top = 960 Width = 975 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Name:" Height = 195

43

Page 39: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 3480 TabIndex = 6 Top = 240 Width = 1215 End

Left = 240 TabIndex = 0 Top = 240 Width = 465 EndEnd

Private Sub cmdCalc_Click() lblTotal.Caption = Val(txtEnvelopes.Text) * 0.1 _ + Val(txtPages.Text) * 0.25 lblTotal.Caption = Format(lblTotal.Caption, "standard") cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtName.Text = "" txtEnvelopes.Text = "" txtPages.Text = "" lblTotal.Caption = "" txtName.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate the total number of registered

employees and the total cost2. Display the total number of registered

employees and the total cost in the lblTotalNum and lblTotalCost controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the total number of registered employees and the total cost (from cmdCalc)

lblTotalNum, lblTotalCost

None

Get and display the name, address, city, state, zip, number of employees registering for the “How to be an Effective Manager” seminar, and number of employees registering for the “How to Run a Small Business” seminar

txtName, txtAddress, txtCity, txtState, txtZip, txtEffective, txtRun

None

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

44

Page 40: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Calculate the total cost = total number of registered employees * 200Display the total number of registered employees in the lblTotalNum controlDisplay the total cost in the lblTotalCost controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtName, txtAddress, txtCity, txtState, txtZip, txtEffective, and txtRun controlsClear the Caption property of the lblTotalNum and lblTotalCost controlsSend the focus to the txtName control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

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

VERSION 5.00Begin VB.Form frmRegister Caption = "Management USA" ClientHeight = 4665 ClientLeft = 1620 ClientTop = 1725 ClientWidth = 6030 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 4665 ScaleWidth = 6030 Begin VB.TextBox txtCity BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1080 TabIndex = 5 Top = 1440

Begin VB.CommandButton cmdCalc Caption = "&Calculate" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4320 TabIndex = 14 Top = 2040 Width = 1215 End Begin VB.TextBox txtName BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

45

Page 41: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Width = 2895 End

Height = 495 Left = 1080 TabIndex = 1 Top = 240 Width = 2895 End

Begin VB.TextBox txtAddress BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1080 TabIndex = 3 Top = 840 Width = 2895 End Begin VB.TextBox txtState BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1080 TabIndex = 7 Top = 2040 Width = 735 End Begin VB.TextBox txtZip BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 3000 TabIndex = 9 Top = 2040 Width = 975 End

Begin VB.TextBox txtEffective BackColor = &H00FFFFFF& BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 3000 TabIndex = 11 Top = 2760 Width = 975 End Begin VB.TextBox txtRun BackColor = &H00FFFFFF& BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 3000 TabIndex = 13 Top = 3360 Width = 975 End Begin VB.CommandButton cmdPrint Caption = "&Print" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4320 TabIndex = 15 Top = 2640 Width = 1215 End

46

Page 42: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.CommandButton cmdClear Caption = "C&lear" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4320 TabIndex = 16 Top = 3240 Width = 1215 End Begin VB.CommandButton cmdExit Caption = "E&xit" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4320 TabIndex = 17 Top = 3840 Width = 1215 EndBegin VB.Label lblTotalNum 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 = 21 Top = 480 Width = 1215 End

Begin VB.Label Label1 AutoSize = -1 'True Caption = "Total registered:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 4320 TabIndex = 20 Top = 240 Width = 1470 End Begin VB.Label Label2 Caption = "&Name:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 0 Top = 240 Width = 600 EndBegin VB.Label Label3 Caption = "&Address:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 2 Top = 840 Width = 810 End

47

Page 43: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label Label4 Caption = "Cit&y:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 4 Top = 1440 Width = 375 End Begin VB.Label Label5 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 Height = 240 Left = 240 TabIndex = 6 Top = 2040 Width = 510 End Begin VB.Label Label6 Caption = "&Zip:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 2640 TabIndex = 8 Top = 2040 Width = 330 End

Begin VB.Label Label7 AutoSize = -1 'True Caption = "&Effective manager seminar:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 10 Top = 2760 Width = 2430 End Begin VB.Label Label8 AutoSize = -1 'True Caption = "Small &business seminar:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 12 Top = 3360 Width = 2175 EndBegin VB.Label Label11 AutoSize = -1 'True Caption = "Total due:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 4320 TabIndex = 18 Top = 1080 Width = 900 End

48

Page 44: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 EndEnd

Private Sub cmdCalc_Click() lblTotalNum.Caption = Val(txtEffective.Text) + Val(txtRun.Text) lblTotalCost.Caption = Val(lblTotalNum.Caption) * 200 lblTotalCost.Caption = Format(lblTotalCost.Caption, "currency") cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtName.Text = "" txtAddress.Text = "" txtCity.Text = "" txtState.Text = "" txtZip.Text = "" txtEffective.Text = "" txtRun.Text = "" lblTotalNum.Caption = "" lblTotalCost.Caption = "" txtName.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

49

Page 45: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Event1. Calculate gross pay, FWT, FICA, state tax,

and net pay2. Display the calculated amounts in the

lblGross, lblFwt, lblFica, lblState, and lbllNet controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the gross pay, FWT, FICA, state tax, and net pay (from cmdCalc)

lblGross, lblFwt, lblFica, lblState, lblNet

None

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 taxDisplay the gross pay in the lblGross controlDisplay the FWT in the lblFwt controlDisplay the FICA in the lblFica controlDisplay the state tax in the lblState controlDisplay the net pay in the lblNet controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtName, txtHours, and txtRate controlsClear the Caption property of the lblGross, lblFwt, lblFica, lblState, and lblNet controlsSend the focus to the txtName control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

50

Page 46: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

VERSION 5.00Begin VB.Form frmSun Caption = "Sun Projects Payroll" ClientHeight = 4665 ClientLeft = 2520 ClientTop = 1665 ClientWidth = 3960 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 4665 ScaleWidth = 3960 Begin VB.TextBox txtRate BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2880 TabIndex = 5 Top = 840 Width = 735 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2400 TabIndex = 6 Top = 2040

Height = 495 Left = 960 TabIndex = 1 Top = 240 Width = 2655 End Begin VB.TextBox txtHours BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 960 TabIndex = 3 Top = 840 Width = 735 End Begin VB.CommandButton cmdPrint Caption = "&Print" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2400 TabIndex = 7 Top = 2640 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear" BeginProperty Font Name = "MS Sans Serif" Size = 9.75

51

Page 47: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Width = 1215 End Begin VB.TextBox txtName BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2400 TabIndex = 8 Top = 3240 Width = 1215 End

Begin VB.CommandButton cmdExit Caption = "E&xit" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2400 TabIndex = 9 Top = 3840 Width = 1215 End Begin VB.Label lblNet Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 495 Left = 960 TabIndex = 20 Top = 3840 Width = 735 End Begin VB.Label lblState Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 495 Left = 960 TabIndex = 19 Top = 3240 Width = 735 End Begin VB.Label lblFica Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent

Begin VB.Label lblFwt Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 495 Left = 960 TabIndex = 17 Top = 2040 Width = 735 EndBegin VB.Label lblGross Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 495 Left = 960 TabIndex = 16 Top = 1440 Width = 735 End Begin VB.Label Label9 AutoSize = -1 'True Caption = "Net:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 15 Top = 3840 Width = 360 End Begin VB.Label Label1 AutoSize = -1 'True BeginProperty Font

52

Page 48: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 495 Left = 960 TabIndex = 18 Top = 2640 Width = 735 End

Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Height = 240 Left = 960 TabIndex = 14 Top = 1560 Width = 45 End Begin VB.Label Label2 Caption = "&Name:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 0 Top = 240 Width = 600 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "&Hours:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 2 Top = 840 Width = 585 End Begin VB.Label Label4 AutoSize = -1 'True Caption = "&Rate:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400

Height = 240 Left = 2280 TabIndex = 4 Top = 840 Width = 480 End Begin VB.Label Label5 AutoSize = -1 'True Caption = "Gross:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 10 Top = 1440 Width = 585 End Begin VB.Label Label6 AutoSize = -1 'True Caption = "FWT:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 240 TabIndex = 11 Top = 2040 Width = 495 End Begin VB.Label Label7 AutoSize = -1 'True Caption = "FICA:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0

53

Page 49: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Height = 240 Left = 240 TabIndex = 12 Top = 2640 Width = 480 End Begin VB.Label Label8 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

Height = 240 Left = 240 TabIndex = 13 Top = 3240 Width = 510 EndEnd

Private Sub cmdCalc_Click() lblGross.Caption = Val(txtHours.Text) * Val(txtRate.Text) lblFwt.Caption = Val(lblGross.Caption) * 0.2 lblFica.Caption = Val(lblGross.Caption) * 0.08 lblState.Caption = Val(lblGross.Caption) * 0.02 lblNet.Caption = lblGross.Caption - lblFwt.Caption _ - lblFica.Caption - lblState.Caption lblGross.Caption = Format(lblGross.Caption, "standard") lblFwt.Caption = Format(lblFwt.Caption, "standard") lblFica.Caption = Format(lblFica.Caption, "standard") lblState.Caption = Format(lblState.Caption, "standard") lblNet.Caption = Format(lblNet.Caption, "standard") cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtName.Text = "" txtHours.Text = "" txtRate.Text = "" lblGross.Caption = "" lblFwt.Caption = "" lblFica.Caption = "" lblState.Caption = "" lblNet.Caption = "" txtName.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

54

Page 50: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Event1. Calculate the number of full boxes and the

number remaining2. Display the number of full boxes and

the number remaining in the lblFull and lblRemain controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the number of full boxes and the number remaining (from cmdCalc)

lblFull, lblRemain None

Get and display the inventory quantity and the number that can be packed in a box

txtQuantity, txtBoxAmt

None

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

packed in a boxCalculate 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 controlDisplay the number remaining in the lblRemain controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtQuantity and txtBoxAmt controlsClear the Caption property of the lblFull and lblRemain controlsSend the focus to the txtQuantity control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

55

Page 51: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

VERSION 5.00Begin VB.Form frmColfax Caption = "Colfax Industries" ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4770 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 4770 Begin VB.TextBox txtBoxAmt Height = 285 Left = 1680 TabIndex = 3 Top = 600 Width = 975 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 3240 TabIndex = 7 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 3240 TabIndex = 6 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 3240 TabIndex = 5 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 3240 TabIndex = 4 Top = 240

Begin VB.Label Label5 AutoSize = -1 'True Caption = "Number remaining:" Height = 195 Left = 240 TabIndex = 11 Top = 1560 Width = 1320 End Begin VB.Label lblRemain Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1680 TabIndex = 10 Top = 1560 Width = 975 EndBegin VB.Label Label3 AutoSize = -1 'True Caption = "&Box quantity:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 915 End Begin VB.Label lblFull Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1680 TabIndex = 9 Top = 1200 Width = 975 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Full boxes:" Height = 195 Left = 240 TabIndex = 8 Top = 1200 Width = 750 End

56

Page 52: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Width = 1215 End Begin VB.TextBox txtQuantity Height = 285 Left = 1680 TabIndex = 1 Top = 240 Width = 975 End

Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Inventory quantity:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 1305 EndEnd

Private Sub cmdClear_Click() txtQuantity.Text = "" txtBoxAmt.Text = "" lblFull.Caption = "" lblRemain.Caption = "" txtQuantity.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblFull.Caption = Val(txtQuantity.Text) \ Val(txtBoxAmt.Text) lblRemain.Caption = Val(txtQuantity.Text) Mod Val(txtBoxAmt.Text) 'Note: The student also could use the following equation: 'lblRemain.Caption = Val(txtQuantity.Text) _ - Val(lblFull.Caption) * Val(txtBoxAmt.Text) cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate the perimeter of a polygon2. Display the perimeter in the

lblPerimeter control

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the perimeter (from cmdCalc) lblPerimeter NoneGet and display the length of four sides of a polygon

txtSide1, txtSide2, txtSide3, txtSide4

None

57

Page 53: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

length + side 4 lengthDisplay the perimeter in the lblPerimeter controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtSide1, txtSide2, txtSide3, txtSide4 controlsClear the Caption property of the lblPerimeter controlSend the focus to the txtSide1 control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

VERSION 5.00Begin VB.Form frmPerimeter Caption = "Perimeter of a Polygon" ClientHeight = 2775 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 3780 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2775 ScaleWidth = 3780 Begin VB.TextBox txtSide3 Height = 285 Left = 1080 TabIndex = 5 Top = 960 Width = 495 End Begin VB.TextBox txtSide4 Height = 285 Left = 1080 TabIndex = 7 Top = 1320 Width = 495 End Begin VB.TextBox txtSide2 Height = 285 Left = 1080

Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 2280 TabIndex = 10 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2280 TabIndex = 9 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2280 TabIndex = 8 Top = 240 Width = 1215 EndBegin VB.TextBox txtSide1 Height = 285 Left = 1080 TabIndex = 1 Top = 240

58

Page 54: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

TabIndex = 3 Top = 600 Width = 495 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2280 TabIndex = 11 Top = 2040 Width = 1215 End

Width = 495 End Begin VB.Label Label6 AutoSize = -1 'True Caption = "Side &3:" Height = 195 Left = 240 TabIndex = 4 Top = 960 Width = 495 End

Begin VB.Label Label4 AutoSize = -1 'True Caption = "Side &4:" Height = 195 Left = 240 TabIndex = 6 Top = 1320 Width = 495 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Side &2:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 495 EndBegin VB.Label lblPerimeter 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

Begin VB.Label Label2 AutoSize = -1 'True Caption = "Perimeter:" Height = 195 Left = 240 TabIndex = 12 Top = 1680 Width = 705 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Side &1:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 495 EndEnd

Private Sub cmdClear_Click() txtSide1.Text = "" txtSide2.Text = "" txtSide3.Text = "" txtSide4.Text = "" lblPerimeter.Caption = "" txtSide1.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblPerimeter.Caption = Val(txtSide1.Text) + Val(txtSide2.Text) _ + Val(txtSide3.Text) + Val(txtSide4.Text) cmdPrint.SetFocusEnd Sub

Pivate Sub cmdExit_Click() EndEnd 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

59

Page 55: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

cmdExit.Visible = True cmdClear.SetFocusEnd Sub

60

Page 56: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Event1. Calculate the circumference of a circle and

the total price of railing material2. Display the circumference and the

total price in the lblCircumference and lblTotalPrice controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the circumference and the total price (from cmdCalc)

lblCircumference, lblTotalPrice

None

Get and display the diameter of a circle and the price per foot of railing material

txtDiameter, txtFootPrice

None

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 controlDisplay the total price of railing material in the lblTotalPrice controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtDiameter and txtFootPrice controlsClear the Caption property of the lblCircumference and lblTotalPrice controlsSend the focus to the txtDiameter control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

(The total price may not be formatted.)

61

Page 57: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

VERSION 5.00Begin VB.Form frmBuilders Caption = "Builders Inc." ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 3990 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 3990 Begin VB.TextBox txtFootPrice Height = 285 Left = 1440 TabIndex = 3 Top = 600 Width = 855 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2520 TabIndex = 7 Top = 2040 Width = 1215 EndBegin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 2520 TabIndex = 6 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2520 TabIndex = 5 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2520 TabIndex = 4 Top = 240 Width = 1215 End

Begin VB.TextBox txtDiameter Height = 285 Left = 1440 TabIndex = 1 Top = 240 Width = 855 EndBegin VB.Label Label5 AutoSize = -1 'True Caption = "Total price:" Height = 195 Left = 240 TabIndex = 11 Top = 1560 Width = 795 End Begin VB.Label lblTotalPrice Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1440 TabIndex = 10 Top = 1560 Width = 855 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Price per &foot:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 990 EndBegin VB.Label lblCircumference Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1440 TabIndex = 9 Top = 1200 Width = 855 End

62

Page 58: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label Label2 AutoSize = -1 'True Caption = "Circumference:" Height = 195 Left = 240 TabIndex = 8 Top = 1200 Width = 1065 End

Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Diameter:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 675 EndEnd

Private Sub cmdClear_Click() txtDiameter.Text = "" txtFootPrice.Text = "" lblCircumference.Caption = "" lblTotalPrice.Caption = "" txtDiameter.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblCircumference.Caption = Val(txtDiameter.Text) * 3.14 lblTotalPrice.Caption = Val(lblCircumference.Caption) _ * Val(txtFootPrice.Text) lblTotalPrice.Caption = Format(lblTotalPrice.Caption, "currency") cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate the number of weeks, days, and

hours worked2. Display the number of weeks, days,

and hours worked in the lblWeeks, lblDays, and lblHours controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the number of weeks, days, and hours worked (from cmdCalc)

lblWeeks, lblDays, lblHours

None

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) \ 8Calculate the number of hours worked = number of hours mod 40 mod 8Display the number of weeks worked in the lblWeeks controlDisplay the number of days worked in the lblDays controlDisplay the number of hours worked in the lblHours controlSend the focus to the Print button

63

Page 59: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

cmdClear: Clear the Text property of the txtHours controlClear the Caption property of the lblWeeks, lblDays, and lblHours controlsSend the focus to the txtHours control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

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

VERSION 5.00Begin VB.Form frmTemp Caption = "Temp Employers" ClientHeight = 2820 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 3990 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2820 ScaleWidth = 3990 Begin VB.Frame Frame1 Caption = "Worked" Height = 1575 Left = 240 TabIndex = 6 Top = 960 Width = 1575 Begin VB.Label Label4 AutoSize = -1 'True Caption = "Weeks:" Height = 195 Left = 120 TabIndex = 12 Top = 360 Width = 555 End

Begin VB.Label lblWeeks Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 720 TabIndex = 11 Top = 360 Width = 615 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Days:" Height = 195 Left = 120 TabIndex = 10 Top = 720 Width = 405 End Begin VB.Label lblDays Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 720 TabIndex = 9 Top = 720 Width = 615 End

64

Page 60: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

65

Page 61: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label lblHours Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 720 TabIndex = 8 Top = 1080 Width = 615 EndBegin VB.Label Label5 AutoSize = -1 'True Caption = "Hours:" Height = 195 Left = 120 TabIndex = 7 Top = 1080 Width = 465 End End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2520 TabIndex = 5 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "C&lear Screen" Height = 495 Left = 2520 TabIndex = 4 Top = 1440 Width = 1215 End

Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2520 TabIndex = 3 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2520 TabIndex = 2 Top = 240 Width = 1215 EndBegin VB.TextBox txtHours Height = 285 Left = 840 TabIndex = 1 Top = 240 Width = 615 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Hours:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 465 EndEnd

Private Sub cmdClear_Click() txtHours.Text = "" lblWeeks.Caption = "" lblDays.Caption = "" lblHours.Caption = "" txtHours.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblWeeks.Caption = Val(txtHours.Text) \ 40 lblDays.Caption = (Val(txtHours.Text) Mod 40) \ 8 lblHours.Caption = Val(txtHours.Text) Mod 40 Mod 8 cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

66

Page 62: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Event1. Calculate the area of a rectangle and the total

price of tile2. Display the area and the total price in

the lblArea and lblTotalPrice controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the area and the total price (from cmdCalc)

lblArea, lblTotalPrice

None

Get and display the length of a rectangle, the width of a rectangle, and the price per square foot of tile

txtLength, txtWidth, txtFootPrice

None

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 tileDisplay the area in the lblArea controlDisplay the total price of tile in the lblTotalPrice controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtLength, txtWidth, and txtFootPrice controlsClear the Caption property of the lblArea and lblTotalPrice controlsSend the focus to the txtLength control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

(The total price may not be formatted.)

VERSION 5.00Begin VB.Form frmTile Caption = "Tile Limited" ClientHeight = 2895

Begin VB.Label Label5 AutoSize = -1 'True Caption = "Total price:" Height = 195

67

Page 63: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4260 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 4260 Begin VB.Frame Frame1 Height = 1335 Left = 240 TabIndex = 10 Top = 1320 Width = 2295 Begin VB.Label Label2 AutoSize = -1 'True Caption = "Area:" Height = 195 Left = 240 TabIndex = 14 Top = 360 Width = 375 EndBegin VB.Label lblArea Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1080 TabIndex = 13 Top = 360 Width = 735 EndBegin VB.Label lblTotalPrice Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1080 TabIndex = 12 Top = 720 Width = 735 End

Left = 240 TabIndex = 11 Top = 720 Width = 795 End End Begin VB.TextBox txtFootPrice Height = 285 Left = 1680 TabIndex = 5 Top = 960 Width = 855 End Begin VB.TextBox txtWidth Height = 285 Left = 1680 TabIndex = 3 Top = 600 Width = 855 EndBegin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2760 TabIndex = 9 Top = 2040 Width = 1215 EndBegin VB.CommandButton cmdClear Caption = "Clear &Screen" Height = 495 Left = 2760 TabIndex = 8 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2760 TabIndex = 7 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2760 TabIndex = 6 Top = 240 Width = 1215 End

68

Page 64: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.TextBox txtLength Height = 285 Left = 1680 TabIndex = 1 Top = 240 Width = 855 End Begin VB.Label Label4 AutoSize = -1 'True Caption = "&Tile price/sq. foot:" Height = 195 Left = 240 TabIndex = 4 Top = 960 Width = 1290 End

Begin VB.Label Label3 AutoSize = -1 'True Caption = "&Width in feet:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 945 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Length in feet:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 1020 EndEnd

Private Sub cmdClear_Click() txtLength.Text = "" txtWidth.Text = "" txtFootPrice.Text = "" lblArea.Caption = "" lblTotalPrice.Caption = "" txtLength.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblArea.Caption = Val(txtLength.Text) * Val(txtWidth.Text) lblTotalPrice.Caption = Val(lblArea.Caption) _ * Val(txtFootPrice.Text) lblTotalPrice.Caption = Format(lblTotalPrice.Caption, "currency") cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd 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 Event1. Calculate the volume of a rectangle2. Display the volume in the lblVolume

control

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the volume (from cmdCalc) lblVolume NoneGet and display the length of a rectangle, the width of a rectangle, and the height of a rectangle

txtLength, txtWidth, txtHeight

None

69

Page 65: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

height of rectangleDisplay the volume in the lblVolume controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtLength, txtWidth, and txtHeight controlsClear the Caption property of the lblVolume controlSend the focus to the txtLength control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

VERSION 5.00Begin VB.Form frmWillow Caption = "Willow Pools" ClientHeight = 2895 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4260 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2895 ScaleWidth = 4260 Begin VB.TextBox txtHeight Height = 285 Left = 1320 TabIndex = 5 Top = 960 Width = 855 End Begin VB.TextBox txtWidth Height = 285 Left = 1320 TabIndex = 3 Top = 600 Width = 855 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2760 TabIndex = 9 Top = 2040

Begin VB.CommandButton cmdClear Caption = "Clear &Screen" Height = 495 Left = 2760 TabIndex = 8 Top = 1440 Width = 1215 End Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2760 TabIndex = 7 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2760 TabIndex = 6 Top = 240 Width = 1215 EndBegin VB.TextBox txtLength Height = 285 Left = 1320 TabIndex = 1 Top = 240 Width = 855 End

70

Page 66: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Width = 1215 End

Begin VB.Label lblVolume Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1320 TabIndex = 11 Top = 1320 Width = 855 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Volume:" Height = 195 Left = 240 TabIndex = 10 Top = 1320 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

Begin VB.Label Label3 AutoSize = -1 'True Caption = "&Width in feet:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 945 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Length in feet:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 1020 EndEnd

Private Sub cmdClear_Click() txtLength.Text = "" txtWidth.Text = "" txtHeight.Text = "" lblVolume.Caption = "" txtLength.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblVolume.Caption = Val(txtLength.Text) _ * Val(txtWidth.Text) * Val(txtHeight.Text) cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

71

Page 67: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Event1. Calculate the total amount of interest and the

total amount repaid2. Display the interest and repaid

amounts in the lblInterest and lblRepaid controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the interest and repaid amounts (from cmdCalc)

lblInterest, lblRepaid

None

Get and display the loan amount, the interest rate, and the term

txtLoan, txtRate, txtTerm

None

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 amountDisplay the total amount repaid in the lblRepaid controlDisplay the total amount of interest in the lblInterest controlSend the focus to the Print button

cmdClear: Clear the Text property of the txtLoan, txtRate, and txtTerm controlsClear the Caption property of the lblInterest and lblRepaid controlsSend the focus to the txtLoan control

cmdExit: End the application

cmdPrint Hide the command buttonsPrint the formDisplay the command buttonsSend the focus to the Clear Screen button

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

72

Page 68: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

VERSION 5.00Begin VB.Form frmQuick Caption = "Quick Loans" ClientHeight = 2790 ClientLeft = 2625 ClientTop = 1950 ClientWidth = 4260 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2790 ScaleWidth = 4260 Begin VB.TextBox txtTerm Height = 285 Left = 1320 TabIndex = 5 Top = 960 Width = 855 End Begin VB.TextBox txtRate Height = 285 Left = 1320 TabIndex = 3 Top = 600 Width = 855 End Begin VB.CommandButton cmdExit Caption = "E&xit" Height = 495 Left = 2760 TabIndex = 9 Top = 2040 Width = 1215 End Begin VB.CommandButton cmdClear Caption = "Clear &Screen" Height = 495 Left = 2760 TabIndex = 8 Top = 1440 Width = 1215 End

Begin VB.CommandButton cmdPrint Caption = "&Print" Height = 495 Left = 2760 TabIndex = 7 Top = 840 Width = 1215 End Begin VB.CommandButton cmdCalc Caption = "&Calculate" Height = 495 Left = 2760 TabIndex = 6 Top = 240 Width = 1215 End Begin VB.TextBox txtLoan Height = 285 Left = 1320 TabIndex = 1 Top = 240 Width = 855 End Begin VB.Label Label6 AutoSize = -1 'True Caption = "Total repaid:" Height = 195 Left = 240 TabIndex = 13 Top = 1680 Width = 885 EndBegin VB.Label lblRepaid Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1320 TabIndex = 12 Top = 1680 Width = 855 End

73

Page 69: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label lblInterest Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single ForeColor = &H80000008& Height = 255 Left = 1320 TabIndex = 11 Top = 1320 Width = 855 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Total interest:" Height = 195 Left = 240 TabIndex = 10 Top = 1320 Width = 960 End

Begin VB.Label Label4 AutoSize = -1 'True Caption = "&Term (years):" Height = 195 Left = 240 TabIndex = 4 Top = 960 Width = 915 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "&Interest rate:" Height = 195 Left = 240 TabIndex = 2 Top = 600 Width = 885 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "&Loan amount:" Height = 195 Left = 240 TabIndex = 0 Top = 240 Width = 975 EndEnd

Private Sub cmdClear_Click() txtLoan.Text = "" txtRate.Text = "" txtTerm.Text = "" lblInterest.Caption = "" lblRepaid.Caption = "" txtLoan.SetFocusEnd Sub

Private Sub cmdCalc_Click() lblRepaid.Caption = -(Val(txtTerm.Text) * 12 _ * Pmt(Val(txtRate.Text) / 12, Val(txtTerm.Text) * 12, _ Val(txtLoan.Text), 0, 0)) lblInterest.Caption = Val(lblRepaid.Caption) – Val(txtLoan.Text) lblInterest.Caption = Format(lblInterest.Caption, "standard") lblRepaid.Caption = Format(lblRepaid.Caption, "standard") cmdPrint.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

74

Page 70: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 2 – Debugging

TechniqueYou 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.

75

Page 71: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 3, Lesson A

Questions1. d Variables2. e All of the above3. b Integer4. e Variant5. c Local6. a literal constant7. e variable8. c symbolic constant9. d Variant10. a True

Exercises1. Dim strName as String

Dim sngPrice as Single (or curPrice as Currency)2. Dim strName as String

Dim sngHeight as SingleDim intWeight as Integer

3. Dim strName as String, intBegin as Integer, intPurchase as IntegerDim intSold as Integer, intEnd as Integer

4. Dim strCity as String, lngPopulation as Long5. Dim strPart as String, sngCost as Single (or curCost as Currency)6. Public strName as String7. Public intAge as Integer8. strCity = “Miami”9. strPartno = “AB103”10. strName = “Desk”

intInStock = 40intOnorder = 20

11. curTotalsales = curReg1sales + curReg2sales12. curSalary = curSalary * 1.513. 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 CurrencyEnter the Dim statement in the cmdSouth button’s Click event. The variable is local.Dim curCompany as CurrencyEnter the Dim statement in the form’s General declarations section. The variable is form-level.

76

Page 72: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

15. Public strEmployee as StringEnter 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 SingleEnter the Public statement in a code module’s General declarations section. The variable is global.

17. Const conTaxRate as Single = .0518. 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

Questions1. e all of the above2. d &3. a lblRegion.Caption = strReg1 & strReg24. d lblAddress.Caption = strCity & “, “ & strState5. d vbNewLine6. b Default7. d Object Browser8. d sngNum = Val(InputBox(“Enter a number:”, “Number”))9. c strCity = InputBox(“Enter the city:”, “City”)

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

Option Explicit

Private Sub cmdCalc_Click() Dim sngSales As Single, sngComm As Single sngSales = Val(txtSales.Text) sngComm = sngSales * 0.1

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm

77

Page 73: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lblComm.Caption = Format(sngComm, "currency") cmdPrint.SetFocusEnd Sub

txtName.SetFocusEnd Sub

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

Option Explicit

Private Sub cmdExit_Click() End End Sub

Private Sub cmdPrint_Click() PrintForm End Sub

Private Sub cmdSqRoot_Click() Dim intNumber As Integer, sngSqRt As Single intNumber = Val(txtNumber.Text) sngSqRt = Sqr(intNumber) lblSqRoot.Caption = sngSqRtEnd Sub

78

Page 74: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

Option Explicit

Private Sub cmdCalc_Click() Dim sngNY As Single, sngMaine As Single, sngFla As Single Dim sngTotal As Single, sngComm As Single sngNY = Val(txtNewYork.Text) sngMaine = Val(txtMaine.Text) sngFla = Val(txtFlorida.Text) sngTotal = sngNY + sngMaine + sngFla sngComm = sngTotal * 0.05 lblTsales.Caption = Format(sngTotal, "standard") lblComm.Caption = Format(sngComm, "standard") cmdPrint.SetFocusEnd Sub

Private Sub cmdClear_Click() txtFlorida.Text = "" txtMaine.Text = "" txtNewYork.Text = "" lblTsales.Caption = "" lblComm.Caption = "" txtNewYork.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm cmdClear.SetFocusEnd Sub

79

Page 75: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.SetFocusEnd Sub

Private Sub cmdClear_Click() txtFlorida.Text = "" txtMaine.Text = "" txtNewYork.Text = "" lblTsales.Caption = "" lblComm.Caption = "" txtNewYork.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm cmdClear.SetFocusEnd Sub

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

80

Page 76: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim 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.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm txtCurrent1.SetFocusEnd Sub

Private Sub Form_Load() sngRaiseRate = Val(InputBox("Enter the raise rate:", "Raise Rate"))End Sub

81

Page 77: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm txtCurrent1.SetFocusEnd Sub

5. lblAddress.Caption = strCity & “, “ & strState6. 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.

82

Page 78: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 3, Lesson CQuestions1. c Add Form2. e the startup form3. c Load statement4. e Unload statement5. d Show method6. d Show method7. b Hide method8. b modeless form9. a modal form10. c either modal or modeless11. b global12. b, d Left, Top13. c BorderStyle14. d Timer15. d MousePointer

Exercises1. 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.

83

Page 79: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

lc2Done.frmOption Explicit

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmAward.Left = (Screen.Width - frmAward.Width) / 2 frmAward.Top = (Screen.Height - frmAward.Height) / 2 Const conMsg As String = "The award goes to " lblMsg.Caption = conMsg & strName & "."End Sub

lc2Input.frmOption Explicit

Private Sub cmdOK_Click() strName = txtSperson.Text frmAward.Show Unload frmInputEnd Sub

Private Sub Form_Load() frmInput.Left = (Screen.Width - frmInput.Width) / 2 frmInput.Top = (Screen.Height - frmInput.Height) / 2End Sub

lc2Mod.basOption ExplicitPublic strName As String

3. 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.

84

Page 80: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lc3Done.frmOption Explicit

Private Sub cmdOK_Click() sngNrate = Val(txtNrate.Text) sngSrate = Val(txtSrate.Text) sngErate = Val(txtErate.Text) sngWrate = Val(txtWrate.Text) frmRMsales.Show Unload frmRateEnd Sub

Private Sub Form_Load() frmRate.Left = (Screen.Width – frmRate.Width) / 2 frmRate.Top = (Screen.Height – frmRate.Height) / 2End Sub

lc3Sales.frmOption 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.SetFocusEnd Sub

Private Sub cmdExit_Click() End End Sub

Private Sub cmdPrint_Click() PrintForm txtNorth.SetFocusEnd Sub

Private Sub Form_Load() frmRMsales.Top = (Screen.Height - frmRMsales.Height) / 2 frmRMsales.Left = (Screen.Width - frmRMsales.Width) / 2End Sub

lc3Mod.basOption ExplicitPublic sngNrate As Single, sngSrate As SinglePublic sngErate As Single, sngWrate As Single

85

Page 81: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. 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 Event1. Show the frmMain form2. Unload the frmName form

frmName.cmdOk

Click

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

3. Get a number from the user and display it in the frmMain.lblNumber control

4. Calculate the square and square root of the number 5. Display the number and the calculated

amounts in the lblNumber, lblSquare, and lblSqRoot controls on the frmMain form

frmMain.cmdCalc

Click

End the application frmMain.cmdExit ClickPrint the interface frmMain.cmdPri

ntClick

Display the student’s name on the frmMain form (from frmMain form’s Load event)

frmMain.lblName None

Display the number on the frmMain form (from cmdCalc)

frmMain.lblNumber None

Display the square and square root (from cmdCalc)

frmMain.lblSquare, frmMain.lblSqRoot

None

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 formUnload the name form

Pseudocode for the main form:Square/Square Root button’s Click event:

Declare variablesGet a number from the userCalculate the square and square root of the numberDisplay 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 formSend the focus to the Square/Square Root button

86

Page 82: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Step e printouts:

Step f printouts:

lc4Done.frmOption Explicit

Private Sub cmdCalc_Click() Dim sngNumber As Single sngNumber = Val(InputBox("Enter a number:", "Number")) lblNumber.Caption = sngNumber lblSquare.Caption = sngNumber ^ 2 lblSqRoot.Caption = Sqr(sngNumber)End Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm cmdCalc.SetFocusEnd Sub

Private Sub Form_Load() frmMain.Left = (Screen.Width – frmMain.Width) / 2 frmMain.Top = (Screen.Height – frmMain.Height) / 2 lblName.Caption = strNameEnd Sub

lc4Mod.basOption ExplicitPublic strName As String

lc4Name.frmOption Explicit

Private Sub cmdOk_Click() strName = txtName.Text frmMain.Show Unload frmNameEnd Sub

Private Sub Form_Load() frmName.Left = (Screen.Width - frmName.Width) / 2 frmName.Top = (Screen.Height - frmName.Height) / 2End Sub

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

Task Object Event

87

Page 83: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

1. Calculate the number of dollars, quarters, dimes, nickels, and pennies

2. Display the calculated amounts in the lblDollars, lblQuarters, lblDimes, lblNickels, and lblPennies controls

cmdCalc Click

End the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the number of dollars, quarters, dimes, nickels, and pennies (from cmdCalc)

lblDollars, lblQuarters, lblDimes, lblNickels, lblPennies

None

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 variableCalculate the number of dollars, quarters, dimes, nickels, and

penniesDisplay the calculated amounts in the appropriate label

controls

Exit button’s Click event: End the application

Print button’s Click event: Print the formSend the focus to the txtPennies control

Printout #1: Printout #2:

Option Explicit

Private Sub cmdCalc_Click() Dim intDollars As Integer, intQuarters As Integer Dim intDimes As Integer, intNickels As Integer Dim intPennies As Integer 'assign value to variable intPennies = Val(txtPennies.Text) intDollars = intPennies \ 100 'calculate dollars intPennies = intPennies - intDollars * 100 intQuarters = intPennies \ 25 'calculate quarters intPennies = intPennies - intQuarters * 25 intDimes = intPennies \ 10 'calculate dimes intPennies = intPennies - intDimes * 10 intNickels = intPennies \ 5 'calculate nickels

Private Sub cmdPrint_Click() PrintForm txtPennies.SetFocusEnd Sub

Private Sub Form_Load() frmJoe.Left = (Screen.Width – frmJoe.Width) / 2 frmJoe.Top = (Screen.Height – frmJoe.Height) / 2End Sub

88

Page 84: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

intPennies = intPennies - intNickels * 5 'calculate pennies lblDollars.Caption = intDollars lblQuarters.Caption = intQuarters lblDimes.Caption = intDimes lblNickels.Caption = intNickels lblPennies.Caption = intPennies txtPennies.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

89

Page 85: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

6. lc6Done project – The student should submit a TOE chart, sketch, pseudocode, three printouts with the test data showing, and the code.

Task Object Event1. Get the amount due and the amount paid2. Calculate the change due, as well as the number

of dollars, quarters, dimes, nickels, and pennies to return to the customer

3. Display the amount due, amount paid, and the calculated amounts in the lblDue, lblPaid, lblChange, lblDollars, lblQuarters, lblDimes, lblNickels, and lblPennies controls

cmdCalc Click

Clear the screen cmdClear ClickEnd the application cmdExit ClickPrint the interface cmdPrint ClickDisplay the amount due, amount paid, change, as well as the number of dollars, quarters, dimes, nickels, and pennies (from cmdCalc)

lblDue, lblPaid, lblChange, lblDollars, lblQuarters, lblDimes, lblNickels, lblPennies

None

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 paidCalculate the change dueCalculate the number of dollars, quarters, dimes, nickels, and

pennies to return to the customerDisplay 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 controlsSend the focus to the Calculate Change button

Exit button’s Click event: End the application

Print button’s Click event: Print the formSend the focus to the Clear Screen button

Printout #1: Printout #2:

90

Page 86: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Printout #3:

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 = intPenniesEnd Sub

Private Sub cmdClear_Click() lblPaid.Caption = "" lblDue.Caption = "" lblChange.Caption = "" lblDollars.Caption = "" lblQuarters.Caption = "" lblDimes.Caption = "" lblNickels.Caption = "" lblPennies.Caption = "" cmdCalc.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintForm cmdClear.SetFocus

91

Page 87: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

Private Sub Form_Load() frmHinsbrook.Left = (Screen.Width - frmHinsbrook.Width) / 2 frmHinsbrook.Top = (Screen.Height - frmHinsbrook.Height) / 2End Sub

92

Page 88: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

93

Page 89: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

Exercises1. T3db1 project – shaded areas show the changes the student would need to makeOriginal code:Private Sub CmdAvg_Click() Dim intNum1 As Integer Dim intNum2 As Integer intNumb1 = Val(InputBox("Enter the first number:", "First Number")) intNum2 = Val(InputBox("Enter the second number:", "Second Number")) sngAvg = intNum1 + intNum2 / 2 lblAnswer.Caption = sngAveEnd Sub

Private Sub CmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmAverage.Top = (Screen.Height – frmAverage.Height) / 2 frmAverage.Left = (Screen.Width – frmAverage.Width) / 2End Sub

Debugged code:Option Explicit

Private Sub CmdAvg_Click() Dim intNum1 As Integer Dim intNum2 As Integer Dim sngAvg As Single intNum1 = Val(InputBox("Enter the first number:", "First Number")) intNum2 = Val(InputBox("Enter the second number:", "Second Number")) sngAvg = (intNum1 + intNum2) / 2 lblAnswer.Caption = sngAvgEnd Sub

Private Sub CmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmAverage.Top = (Screen.Height - frmAverage.Height) / 2 frmAverage.Left = (Screen.Width - frmAverage.Width) / 2End Sub

93

Page 90: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. T3db2 project – shaded areas show the changes the student would need to makeOption Explicit

Private Sub cmdExit_Click() EndEnd 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 = intSumEnd Sub

Private Sub Form_Load() frmSum.Top = (Screen.Height - frmSum.Height) / 2 frmSum.Left = (Screen.Width - frmSum.Width) / 2End Sub

3. T3db3 projectThe 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 $.

94

Page 91: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 4, Lesson A

Questions1. d curCost > 100 And curCost <= 10002. d UCase3. e UCase(txtName.Text) = “BOB”4. a txtName.Text = UCase(txtName.Text)5. 2 And 1 Not 3 Or6. 1 Mathematical 3 Logical 2 Relational7. b False8. a True9. a True10. a True11. b False12. a True13. b False14. a True15. a True16. a True17. c 18018. d 300019. b 20020. a diamond21. a diamond22. a, d Case 2, 4, 6, 8

Case Is >= 823. a, d, e Case “TEXAS”

Case “COLORADO”, “CALIFORNIA”Case “ALABAMA” To “ARKANAS”

24. c process25. a input/output26. d rectangle27. c parallelogram28. a diamond29. Case “NUTS” To “SOUP”

95

Page 92: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1.

2.

96

Start

Hours > 40

Display “Overtime”

Display “Regular”

Stop

FT

Start

curSales

Commission = .1 * curSales

Commission = .05 * curSales

Commission = 0

Stop

>= 10000

>= 5000 Else

Page 93: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3.

4. Select Case intStatusCase 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 Select5. Dim intCode as Integer, curCharge as Currency, curTotal as Currency

intCode = Val(txtData.Text)Select Case intCode

Case Is 1 To 3curCharge = 25

Case Is 4 To 6curCharge = 20

Case Is 7 To 10curCharge = 15

Case Is > 10curCharge = 10

Case ElsecurCharge = 0

End Select

97

Start

sngHours

Display “Overtime”

Display “Regular”

Stop

Else>=40

Page 94: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

curTotal = curCharge * intCode lblTotal.Caption = curTotal6. If UCase(txtCar.Text) = “GRAND AM” Then

lblType.Caption = “Pontiac” End If7. If intUnits < 0 Then

lblMsg.Caption = “Entry error” Else

lblMsg.Caption = “Valid Number” End If

98

Page 95: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

8. If curPrice < 10 ThenlblMsg.Caption = “Reorder”

ElselblMsg.Caption = “OK”

End If9. If curSales <= 250 Then

curBonus = 10 Else

curBonus = 15 End If10. If UCase(strState) = “HAWAII” Then

lblShipping.Caption = 25 Else

lblShipping.Caption = 50 End If11.

Code: If UCase(strState) = “COLORADO” Then

lblStax.Caption = curSales * .03 Else lblStax.Caption = curSales * .04 End If

99

Start

Stop

state = “Colorado”

sales tax = 4% * sales

sales tax = 3% * sales

Display sales tax in lblStax control

TF

Page 96: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

12. Pseudocode:If hours <= 40 then

calculate gross = hours * rate else

calculate gross = hours * rate + (hours – 40) * rate / 2 end ifDisplay gross in lblGross control

Code:If sngHours <= 40 Then

sngGross = sngHours * sngRate Else

sngGross=sngHours * sngRate + (sngHours – 40) * sngRateEnd If

Note: The student also may use the gross = 40 * rate + (hours-40) * rate * 1.5 equation to calculate the overtime pay.

13.

Code:If UCase(strAnimal) = “D” Then

lblType.Caption = “Dog”Else

lblType.Caption = “Cat”End If

14. Pseudocode:If the item is a desk and the state is Colorado then

calculate the discount = 10% * salesdisplay the discount in the lblDisc control

End If100

Start

Stop

animal is a dog

Display “Dog”

Display “Cat”

Page 97: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Code:If UCase(strItem) = “DESK” And UCase(strState) = “COLORADO” Then

lblDisc.Caption = Format(.1 * curSales, “standard”)End If

15. Select Case UCase(strState)Case “CALIFORNIA”, “TEXAS”

lblDisc.Caption = Format(.1 * curSales, “standard”) End Select

101

Page 98: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

16. Select Case Val(txtEntry.Text)Case 1, 2

lblEntry.Caption = “Valid Entry”Case Else

lblEntry.Caption = “Entry Error” End Select Note: The student also may use the following Case statement. Select Case txtEntry.Text

Case “1”, “2”lblEntry.Caption = “Valid Entry”

Case ElselblEntry.Caption = “Entry Error”

End Select17. If UCase(strColor) = “RED” And UCase(strItem) = “SHIRT” Then

sngIncrease = .02 * sngOrigPrice Else

sngIncrease = .01 * sngOrigPrice End If sngNewprice = sngOrigPrice + sngIncrease lblOrig.Caption = Format(sngOrigPrice, “standard”) lblIncrease.Caption = Format(sngIncrease, “standard”) lblNew.Caption = Format(sngNewPrice, “currency”)18. Select Case intAnimal

Case 1lblAnimal.Caption = “Dog”

Case 2lblAnimal.Caption = “Cat”

Case ElselblAnimal.Caption = “Bird”

End Select19. Dim intNum as Integer

intNum = Val(txtReg.Text)Select Case intNum

Case 1 To 4curTotalDue = intNum * 100

Case 5 To 10curTotalDue = intNum * 80

Case >= 11curTotalDue = intNum * 60

Case ElsecurTotalDue = 0

End Select20.

Pseudocode:Case of state

= “Hawaii” display $25 in lblShip control= “Oregon” display $30 in lblShip control= “California” display $32.50 in lblShip control

102

Page 99: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Other display “Incorrect State” in lblShip controlEnd case state

Code:Dim strState as StringstrState = UCase(txtState.Text)Select Case strState

Case “HAWAII”lblship.Caption = 25

Case “OREGON”lblship.Caption = 30

Case “CALIFORNIA”lblship.Caption = 32.50

Case Elselblship.Caption = “Incorrect State”

End Select21. If…Then…Else code

Dim strSeat as StringstrSeat = UCase(txtSeat.Text)If strSeat = “BOX” Then

lblPrice.Caption = 75 Else

If strSeat = “PAVILION” ThenlblPrice.Caption = 30

ElseIf strSeat = “LAWN” Then

lblPrice.Caption = 21Else

lblPrice.Caption = “Incorrect Seat Location”End If

End If End If

Select Case code:Dim strSeat as StringstrSeat = UCase(txtSeat.Text)Select Case strSeat

Case “BOX”lblPrice.Caption = 75

Case “PAVILION”lblPrice.Caption = 30

Case “LAWN”lblPrice.Caption = 21

Case ElselblPrice.Caption = “Incorrect Seat Location”

End Select22. If…Then…Else code

Dim intYears as IntegerintYears = Val(txtYears.Text)

103

Page 100: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

If intYears < 1 ThenlblWeeks.Caption = 0

ElseIf intYears <= 5 Then

lblWeeks.Caption = 1Else

If intYears <= 10 ThenlblWeeks.Caption = 2

ElselblWeeks.Caption = 3

End IfEnd If

End If

Select Case code:Dim intYears as IntegerintYears = Val(txtYears.Text)Select Case intYears

Case Is < 1lblWeeks.Caption = 0

Case 1 To 5lblWeeks.Caption = 1

Case 6 to 10lblWeeks.Caption = 2

Case ElselblWeeks.Caption = 3

End Select23. If…Then…Else code

Dim curSales as CurrencyIf curSales > 10000 Then

lblComm.Caption = .1 * curSalesElse

If curSales > 5000 ThenlblComm.Caption = .075 * curSales

ElseIf curSales >= 1 Then

lblComm.Caption = .05 * curSalesElse

lblComm.Caption = “Data Error”End If

End If End If

Select Case codeDim curSales as CurrencySelect Case curSales

Case Is > 10000lblComm.Caption = .1 * curSales

Case Is > 5000104

Page 101: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lblComm.Caption = .075 * curSalesCase Is >= 1

lblComm.Caption = .05 * curSalesCase Else

lblComm.Caption = “Data Error” End Select24. If…Then…Else code

strState = UCase(strState)If strState = “CALIFORNIA” Or strState = “TEXAS” Then

lblDisc.Caption = .1 * curSalesElse

If strState = “OREGON” Or strState = “NEW MEXICO” ThenlblDisc.Caption = .07 * curSales

ElselblDisc.Caption = .06 * curSales

End IfEnd IflblDisc.Caption =Format(lblDisc.Caption, “standard”)

Select Case codestrState = UCase(strState)Select Case strState

Case “CALIFORNIA”, “TEXAS” lblDisc.Caption = .1 * curSales

Case “OREGON”, “NEW MEXICO”lblDisc.Caption = .07 * curSales

Cae ElselblDisc.Caption = .06 * curSales

End SelectlblDisc.Caption =Format(lblDisc.Caption, “standard”)

25. txtData.Text = “P” or txtDate.Text = “p”

105

Page 102: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 4, Lesson BQuestions1. d option button2. a check box3. d frame4. a one5. b two6. c three7. d four8. d four9. c Randomize10. b between 0 and 1, including 0 but not including 111. b (30 – 5 + 1) * Rnd + 512. e Int((25 – 1 + 1) * Rnd + 1)13. a Call14. e optInsured.Value = True15. 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).

106

Page 103: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1. lb1Done project – The student should submit two printouts of the interface and the code.Printout #1: Printout #2:

Option ExplicitDim strCapital As String, strChoice As String

Private Sub cmdCheck_Click() If strCapital = strChoice Then lblMsg.Caption = “Correct” Else lblMsg.Caption = “Incorrect” End IfEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmStates.Left = (Screen.Width – frmStates.Width) / 2 frmStates.Top = (Screen.Height – frmStates.Height) / 2 optCal.Value = True optDen.Value = TrueEnd Sub

Private Sub optCal_Click() strCapital = “Sacramento” lblMsg.Caption = “”End Sub

Private Sub optCol_Click() strCapital = “Denver” lblMsg.Caption = “”End Sub

Private Sub optDen_Click() strChoice = “Denver” lblMsg.Caption = “”End Sub

Private Sub optIll_Click() strCapital = “Springfield” lblMsg.Caption = “”End Sub

Private Sub optMad_Click() strChoice = “Madison” lblMsg.Caption = “”End Sub

Private Sub optOre_Click() strCapital = “Salem” lblMsg.Caption = “”End Sub

Private Sub optSac_Click() strChoice = “Sacramento” lblMsg.Caption = “”End Sub

Private Sub optSal_Click() strChoice = “Salem” lblMsg.Caption = “”End Sub

Private Sub optSpr_Click() strChoice = “Springfield” lblMsg.Caption = “”End Sub

Private Sub optWis_Click() strCapital = “Madison” lblMsg.Caption = “”End Sub

107

Page 104: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. lb2Done project – The student should submit two printouts of the interface and the code.Printout #1: Printout #2:

Option ExplicitDim intTennis As Integer, intGolf As Integer, intRacquet As Integer

Private Sub chkGolf_Click() If chkGolf.Value = 1 Then ‘checked intGolf = 25 Else ‘unchecked intGolf = 0 End If lblAdditional.Caption = “” 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 = intTotalEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmWillow.Left = (Screen.Width – frmWillow.Width) / 2 frmWillow.Top = (Screen.Height – frmWillow.Height) / 2End Sub

108

Page 105: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 4, Lesson C

Questions1. e both b and c (1 and vbChecked)2. c False3. c static variable4. 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 Message8. b Warning Message9. c Information Message10. a application modal11. c system modal12. d txtName.SelStart = 013. e txtName.SelLength = Len(txtName.Text)14. b GotFocus

Exercises1. 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:

Option Explicit

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() cmdSelect.Visible = False cmdPrint.Visible = False cmdExit.Visible = False PrintForm cmdSelect.Visible = True cmdPrint.Visible = True cmdExit.Visible = TrueEnd Sub

Private Sub cmdSelect_Click() Randomize lblNum1.Caption = Int((54 - 1 + 1) * Rnd + 1) lblNum2.Caption = Int((54 - 1 + 1) * Rnd + 1) lblNum3.Caption = Int((54 - 1 + 1) * Rnd + 1) lblNum4.Caption = Int((54 - 1 + 1) * Rnd + 1) lblNum5.Caption = Int((54 - 1 + 1) * Rnd + 1) lblNum6.Caption = Int((54 - 1 + 1) * Rnd + 1)End Sub

Private Sub Form_Load() frmLotto.Left = (Screen.Width - frmLotto.Width) / 2 frmLotto.Top = (Screen.Height - frmLotto.Height) / 2End Sub

109

Page 106: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. lc2Done project – Shaded areas indicate changes made by student.Option ExplicitDim 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() EndEnd 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 = intNumIncorrectEnd Sub

Private Sub Form_Load() frmMath.Top = (Screen.Height – frmMath.Height) / 2 frmMath.Left = (Screen.Width – frmMath.Width) / 2 optLevel1.Value = True optAdd.Value = TrueEnd Sub

110

Page 107: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = sngNum2End Sub

Private Sub optAdd_Click() Call RandomNumbers imgOperator.Picture = imgPlus.PictureEnd Sub

Private Sub optDivide_Click() Call RandomNumbers imgOperator.Picture = imgDivide.PictureEnd Sub

Private Sub optLevel1_Click() Call RandomNumbersEnd Sub

Private Sub optLevel2_Click() Call RandomNumbersEnd Sub

Private Sub optMultiply_Click() Call RandomNumbers imgOperator.Picture = imgMultiply.PictureEnd Sub

Private Sub optSub_Click() Call RandomNumbers imgOperator.Picture = imgMinus.PictureEnd Sub

Private Sub txtAnswer_GotFocus() txtAnswer.SelStart = 0 txtAnswer.SelLength = Len(txtAnswer.Text)End Sub

111

Page 108: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3. lc3Done project – The student should submit two printouts of the interface and the code.Printout #1: Printout #2:

Option ExplicitDim 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 = sngTotalEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() fraButtons.Visible = False PrintForm fraButtons.Visible = TrueEnd Sub

Private Sub Form_Load() frmReg.Left = (Screen.Width – frmReg.Width) / 2 frmReg.Top = (Screen.Height – frmReg.Height) / 2 optSem1.Value = TrueEnd Sub

112

Page 109: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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:

Option Explicit

Private Sub cmdCalc_Click() Const conBtns As String = vbOKOnly + vbInformation _ + vbDefaultButton1 + vbApplicationModal Const conMsg As String = _ "The number of units must be greater than 0." Dim intRetVal As Integer, intUnits As Integer, sngTotal As Single intUnits = Val(txtUnits.Text) If intUnits <= 0 Then intRetVal = MsgBox(conMsg, conBtns, "Entry Error") Else If intUnits <= 4 Then sngTotal = intUnits * 10 Else If intUnits <= 10 Then sngTotal = intUnits * 9 Else sngTotal = intUnits * 7 End If End If End If lblTotal.Caption = Format(sngTotal, "currency") txtUnits.SelStart = 0 txtUnits.SelLength = Len(txtUnits.Text) txtUnits.SetFocus

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() fraButtons.Visible = False PrintForm fraButtons.Visible = TrueEnd Sub

Private Sub Form_Load() frmJacob.Left = (Screen.Width – frmJacob.Width) / 2 frmJacob.Top = (Screen.Height – frmJacob.Height) / 2End Sub

Private Sub txtUnits_GotFocus() txtUnits.SelStart = 0 txtUnits.SelLength = Len(txtUnits.Text)End Sub

113

Page 110: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

Printout #3: Printout #4:

Option Explicit

Private Sub cmdCalc_Click() Const conBtns As String = vbOKOnly + vbInformation _ + vbDefaultButton1 + vbApplicationModal Const conMsg As String = _ "The number of units must be greater than 0." Dim intRetVal As Integer, intUnits As Integer, sngTotal As Single intUnits = Val(txtUnits.Text) Select Case intUnits Case 1 To 4 sngTotal = intUnits * 10 Case 5 To 10 sngTotal = intUnits * 9 Case Is >= 11 sngTotal = intUnits * 7 Case Else intRetVal = MsgBox(conMsg, conBtns, "Entry Error") End Select lblTotal.Caption = Format(sngTotal, "currency") txtUnits.SelStart = 0 txtUnits.SelLength = Len(txtUnits.Text) txtUnits.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() fraButtons.Visible = False PrintForm fraButtons.Visible = TrueEnd Sub

Private Sub Form_Load() frmJacob.Left = (Screen.Width – frmJacob.Width) / 2 frmJacob.Top = (Screen.Height – frmJacob.Height) / 2End Sub

Private Sub txtUnits_GotFocus() txtUnits.SelStart = 0 txtUnits.SelLength = Len(txtUnits.Text)End Sub

114

Page 111: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

115

Page 112: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

5. lc5Done project – The student should submit three printouts of the interface and the code. The design of the interface will vary. The bonus may not be formatted.

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

Option Explicit

Private Sub cmdCalc_Click() Const conBtns As String = vbOKOnly + vbInformation _ + vbDefaultButton1 + vbApplicationModal Const conMsg As String = _ "The sales amount must be greater than 0." Dim intRetVal As Integer, sngSales As Single, sngBonus As Single sngSales = Val(txtSales.Text) Select Case sngSales Case 0 To 3000.99 sngBonus = 0 Case 3001 To 5000.99 sngBonus = 50 Case 5001 To 9999.99 sngBonus = 100 Case Is > 10000 sngBonus = 250 Case Else intRetVal = MsgBox(conMsg, conBtns, "Entry Error") End Select lblBonus.Caption = Format(sngBonus, "currency") txtSales.SelStart = 0 txtSales.SelLength = Len(txtSales.Text) txtSales.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() fraButtons.Visible = False PrintForm fraButtons.Visible = TrueEnd Sub

Private Sub Form_Load() frmFlowers.Left = (Screen.Width - frmFlowers.Width) / 2 frmFlowers.Top = (Screen.Height - frmFlowers.Height) / 2End Sub

Private Sub txtSales_GotFocus() txtSales.SelStart = 0 txtSales.SelLength = Len(txtSales.Text)End Sub

116

Page 113: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

6. (Discovery) lc6Done project – The student should submit two printouts of the interface and the code. The design of the interface will vary. The fee may not be formatted.

Printout #1: Printout #2:

Option Explicit

Private Sub cmdCalc_Click() Const conBtns As String = vbOKOnly + vbInformation _ + vbDefaultButton1 + vbApplicationModal Const conMsg As String = "Invalid Entry" Dim intRetVal As Integer, strCode As String, intFee As Integer strCode = Ucase(txtCode.Text) Select Case strCode Case "TC" intFee = 50 Case "RV", "HW", "OV" intFee = 15 Case "OS", "FC" intFee = 5 Case Else intRetVal = MsgBox(conMsg, conBtns, "Entry Error") End Select lblFee.Caption = Format(intFee, "currency") txtCode.SelStart = 0 txtCode.SelLength = Len(txtCode.Text) txtCode.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() fraButtons.Visible = False PrintForm fraButtons.Visible = TrueEnd Sub

Private Sub Form_Load() frmVets.Left = (Screen.Width – frmVets.Width) / 2 frmVets.Top = (Screen.Height – frmVets.Height) / 2End Sub

Private Sub txtCode_GotFocus() txtCode.SelStart = 0 txtCode.SelLength = Len(txtCode.Text)End Sub

117

Page 114: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

7. (Discovery) lc7Done project – The student should submit four printouts of the interface and the code. The design of the interface will vary. The total due may not be formatted.

Printout #1: Printout #2:

Printout #3: Printout #4:

Option Explicit

Private Sub cmdCalc_Click() Const conBtns As String = vbOKOnly + vbInformation _ + vbDefaultButton1 + vbApplicationModal Const conMsg As String = _ "The number of units must be greater than 0." Dim intRetVal As Integer, intUnits As Integer, sngTotal As Single intUnits = Val(txtUnits.Text) If optWhole.Value = True Then Select Case intUnits Case 1 To 4 sngTotal = intUnits * 10 Case Is >= 5 sngTotal = intUnits * 9 Case Else intRetVal = MsgBox(conMsg, conBtns, "Entry Error") End Select Else Select Case intUnits Case 1 To 3 sngTotal = intUnits * 15 Case 4 To 8 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

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() fraButtons.Visible = False PrintForm fraButtons.Visible = TrueEnd Sub

Private Sub Form_Load() frmMarine.Left = (Screen.Width - frmMarine.Width) / 2 frmMarine.Top = (Screen.Height - frmMarine.Height) / 2 optRetail.Value = TrueEnd Sub

Private Sub txtUnits_GotFocus() txtUnits.SelStart = 0 txtUnits.SelLength = Len(txtUnits.Text)End Sub

118

Page 115: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

119

Page 116: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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() Text1.SetFocusEnd Sub

Private Sub Form_Load() Form1.Show Check1.Value = vbCheckedEnd 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: 16Rectangle area: 15Parallelogram area: 12Circle area: 12.56Triangle area: 6

120

Page 117: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub cmdCalc_Click() Dim sngSide As Single, sngLength As Single, sngWidth As Single Dim sngPbase As Single, sngPheight As Single, sngRadius As Single Dim sngTbase As Single, sngTheight As Single sngSide = Val(txtSide.Text) sngLength = Val(txtLength.Text) sngWidth = Val(txtWidth.Text) sngPbase = Val(txtPbase.Text) sngPheight = Val(txtPheight.Text) sngRadius = Val(txtRadius.Text) sngTbase = Val(txtTbase.Text) sngTheight = Val(txtTheight.Text) lblSqArea.Caption = sngSide ^ 2 lblRecArea.Caption = sngLength * sngWidth lblParArea.Caption = sngPbase * sngPheight lblCirArea.Caption = 3.14 * sngRadius ^ 2 lblTriArea.Caption = 0.5 * sngTbase * sngTheightEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmArea.Left = (Screen.Width – frmArea.Width) / 2 frmArea.Top = (Screen.Height – frmArea.Height) / 2End Sub

Private Sub txtLength_GotFocus() txtLength.SelStart = 0 txtLength.SelLength = Len(txtLength.Text)End Sub

Private Sub txtPbase_GotFocus() txtPbase.SelStart = 0 txtPbase.SelLength = Len(txtPbase.Text)End Sub

Private Sub txtPheight_GotFocus() txtPheight.SelStart = 0 txtPheight.SelLength = Len(txtPheight.Text)End Sub

Private Sub txtRadius_GotFocus() txtRadius.SelStart = 0 txtRadius.SelLength = Len(txtRadius.Text)End Sub

Private Sub txtSide_GotFocus() txtSide.SelStart = 0 txtSide.SelLength = Len(txtSide.Text)End Sub

Private Sub txtTbase_GotFocus() txtTbase.SelStart = 0 txtTbase.SelLength = Len(txtTbase.Text)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.

121

Page 118: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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() EndEnd 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 = "" '<enter the appropriate Call statement(s) here> Case Else imgIcon.Picture = LoadPicture() intRetVal = MsgBox("Try again.", conBtns, "Math Application") txtAnswer.SelStart = 0 txtAnswer.SelLength = Len(txtAnswer.Text) End Select txtAnswer.SetFocusEnd Sub

Private Sub Form_Load() frmMath.Top = (Screen.Height - frmMath.Height) / 2 frmMath.Left = (Screen.Width - frmMath.Width) / 2 optLevel1.Value = TrueEnd Sub

Private Sub txtAnswer_GotFocus() txtAnswer.SelStart = 0 txtAnswer.SelLength = Len(txtAnswer.Text)End Sub

122

Page 119: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Modified code:Option Explicit

Private Sub cmdExit_Click() EndEnd 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.SetFocusEnd Sub

Private Sub Form_Load() frmMath.Top = (Screen.Height - frmMath.Height) / 2 frmMath.Left = (Screen.Width - frmMath.Width) / 2 optLevel1.Value = TrueEnd 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

123

Page 120: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

12. (Discovery) lc12Done project – The student should submit a printout of the code.lc12Done.frm

Private Sub Form_Load() Call CenterForm(Me)End Sub

Procs.bas

Public Sub CenterForm(FormName As Form) FormName.Left = (Screen.Width - FormName.Width) / 2 FormName.Top = (Screen.Height - FormName.Height) / 2End Sub

124

Page 121: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 4 – Debugging

TechniqueUse 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.

Exercises1. 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 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")End Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmDebug1.Left = (Screen.Width – frmDebug1.Width) / 2 frmDebug1.Top = (Screen.Height – frmDebug1.Height) / 2End 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

113

Page 122: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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, curTotCdEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmDebug1.Left = (Screen.Width - frmDebug1.Width) / 2 frmDebug1.Top = (Screen.Height - frmDebug1.Height) / 2End 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

114

Page 123: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 ExplicitDim curPrice As Currency

Private Sub cmdCalc_Click() Dim intQuantity As Integer intQuantity = Val(txtQuantity.Text) lblTotal.Caption = intQuantity * curPrice txtQuantity.SetFocus End Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmTotalDue.Top = (Screen.Height – frmTotalDue.Height) / 2 frmTotalDue.Left = (Screen.Width – frmTotalDue.Width) / 2End Sub

Private Sub optRetail_Click() curPrice = 15 lblTotal.Caption = ""End Sub

Private Sub optWhole_Click() curPrice = 10 lblTotal.Caption = ""End Sub

Private Sub txtQuantity_Change() lblTotal.Caption = ""End Sub

Private Sub txtQuantity_GotFocus() txtQuantity.SelStart = 0 txtQuantity.SelLength = Len(txtQuantity.Text)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 ExplicitDim curPrice As Currency

Private Sub cmdCalc_Click() Dim intQuantity As Integer intQuantity = Val(txtQuantity.Text) lblTotal.Caption = intQuantity * curPrice txtQuantity.SetFocusEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmTotalDue.Top = (Screen.Height – frmTotalDue.Height) / 2 frmTotalDue.Left = (Screen.Width – frmTotalDue.Width) / 2 optWhole.Value = TrueEnd Sub

Private Sub optRetail_Click() curPrice = 15 lblTotal.Caption = ""End Sub

Private Sub optWhole_Click() curPrice = 10 lblTotal.Caption = ""End Sub

Private Sub txtQuantity_Change() lblTotal.Caption = ""End Sub

Private Sub txtQuantity_GotFocus() txtQuantity.SelStart = 0 txtQuantity.SelLength = Len(txtQuantity.Text)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.

115

Page 124: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 5, Lesson AQuestions1. b hexagon2. d 63. d 74. c 45. e 126. e less than or equal to7. c greater than or equal to8. e For intTemp = 1 to 109. 3 Adds the stepvalue to the counter

1 Initializes the counter to the startvalue2 Checks if the value in the counter is greater (less) than the endvalue

10. b 111. b,c,e Do Until, Do while, For Next12. 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 Until16. b Do While17. a Do Until18. a Do Until, Do While19. d counter20. a accumulator21. c, e initialized, updated22. b counter, accumulator23. e intNumber = intNumber + 124. d curTotal = curTotal + curSales25. b the Dim statement

116

Page 125: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1. 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 = 10Do While intCount < 100

Print intCount * 2intCount = intCount + 10

Loop3.

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 intTempEnd 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

117

Start

intNumber

>10

1Print “Hello”

Stop

Page 126: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

For intTemp = 2 To 12 Step 2 Print intTemp ^ 2 Next intTempEnd Sub

118

Page 127: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

6. la6Done project – The student should submit a printout of the code. Changes to the original code are shaded.

Option Explicit

Private Sub cmdExam1_Click() Dim intCount As Integer For intCount = 1 To 3 Step 1 Print intCount Next intCountEnd 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 intCountEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmFor.Top = (Screen.Height - frmFor.Height) / 2 frmFor.Left = (Screen.Width - frmFor.Width) / 2End Sub

7. la7Done project – The student should submit a printout of the code. Changes to the original code are shaded.

Option Explicit

Private Sub cmdExam1_Click() Dim intCount As Integer For intCount = 1 To 3 Step 1 Print intCount Next intCountEnd Sub

Private Sub cmdExam2_Click() Dim intCount As Integer For intCount = 0 To 6500 Step 50 imgAirPlane.Left = intCount Next intCountEnd Sub

Private Sub cmdExam3_Click() Dim intCount As Integer For intCount = 0 To 3600 Step 50 imgAirPlane.Top = intCount Next intCountEnd Sub

Private Sub cmdExam4_Click() Dim intCount As Integer imgAirPlane.Left = 0 imgAirPlane.Top = 0 For intCount = 0 To 3600 Step 50 imgAirPlane.Left = imgAirPlane.Left + 100 imgAirPlane.Top = intCount Next intCountEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmFor.Top = (Screen.Height – frmFor.Height) / 2 frmFor.Left = (Screen.Width – frmFor.Width) / 2End Sub

8. la8Done project – The student should submit a printout of the code.Option ExplicitPrivate Sub cmdDisplay_Click() Dim intNum1 As Integer, intNum2 As Integer Dim intTemp As Integer, intSum As Integer intNum1 = 1 intNum2 = 1 Print intNum1; intNum2; For intTemp = 1 To 8 intSum = intNum1 + intNum2

Private Sub cmdExit_Click() EndEnd Sub

119

Page 128: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Print intSum; intNum1 = intNum2 intNum2 = intSum Next intTempEnd Sub

120

Page 129: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Print "Hello" intCount = intCount + 1 LoopEnd Sub

10. The student should submit the code. Changes to the code are shaded.Option Explicit

Private Sub Command1_Click() Dim intTemp As Integer intTemp = 1 Do Print "Hello" intTemp = intTemp + 1 Loop Until intTemp > 10End Sub

11. Do While curSales <> 012. Loop Until curSales = 013. Do While UCase(strName) <> “DONE”14. Loop Until UCase(strName) = “DONE”15. 0, 1, 2, 3, 416. 0, 1, 2, 3, 4, 517. 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 + 122. intQuantity = intQuantity + 523. curTotal = curTotal + curSales24. sngTotal = sngTotal + sngGross25. intEmployees = 126. 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, 4121

Page 130: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

28. 1

Tutorial 5, Lesson BQuestions1. a control array2. d index3. e txtName(1)4. a 35. a agruments6. d parallel7. b GotFocus8. a Enabled9. c 210. 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.

Exercises1. lb1Done project – The student should submit a printout of the code.Option Explicit

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmImages.Left = (Screen.Width - frmImages.Width) / 2 frmImages.Top = (Screen.Height - frmImages.Height) / 2 optElement(0).Value = TrueEnd Sub

Private Sub optElement_Click(Index As Integer) imgPicture.Picture = imgElement(Index).PictureEnd Sub

2. lb2Done project – The student should submit a printout of the code.Option Explicit

Private Sub cmdBlue_Click() Dim intX As Integer For intX = 0 To 2 lblColor(intX).BackColor = vbBlue Next intXEnd Sub

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdYellow_Click() Dim intX As Integer Do While intX <= 2 lblColor(intX).BackColor = vbYellow intX = intX + 1 LoopEnd Sub

Private Sub Form_Load() frmColor.Left = (Screen.Width - frmColor.Width) / 2 frmColor.Top = (Screen.Height - frmColor.Height) / 2End Sub

122

Page 131: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3. lb3Done project – The student should submit a printout of the code. The student may use a nested If statement rather than the Select Case statement.

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmImages.Top = (Screen.Height – frmImages.Height) / 2 frmImages.Left = (Screen.Width – frmImages.Width) / 2End Sub

Private Sub imgFace_Click(Index As Integer) Select Case Index Case 0 lblWord.Caption = "Sad" Case 1 lblWord.Caption = "Neutral" Case Else lblWord.Caption = "Happy" End SelectEnd Sub

123

Page 132: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. (Discovery) lb4Done project – The student should submit a printout of the code.Option ExplicitDim intNum As Integer

Private Sub cmdExit_Click() EndEnd Sub

Private Sub Form_Load() frmFaces.Top = (Screen.Height – frmFaces.Height) / 2 frmFaces.Left = (Screen.Width – frmFaces.Width) / 2End Sub

Private Sub tmrFaces1_Timer() imgFace(intNum).Visible = True intNum = intNum + 1 If intNum > 3 Then intNum = 3 tmrFaces1.Enabled = False tmrFaces2.Enabled = True End IfEnd Sub

Private Sub tmrFaces2_Timer() imgFace(intNum).Visible = False intNum = intNum - 1 If intNum < 0 Then intNum = 0 tmrFaces2.Enabled = False tmrFaces1.Enabled = True End IfEnd 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.00Begin VB.Form Form1 Caption = "Form1" ClientHeight = 1380 ClientLeft = 3705 ClientTop = 2700 ClientWidth = 1785 LinkTopic = "Form1" ScaleHeight = 1380 ScaleWidth = 1785 Begin VB.HScrollBar HScroll1 Height = 255 LargeChange = 10 Left = 240 Max = 50 TabIndex = 1 Top = 840 Width = 1215 End

Begin VB.Label Label1 Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single Caption = "0" ForeColor = &H80000008& Height = 495 Left = 240 TabIndex = 0 Top = 240 Width = 1215 EndEnd

Code:Private Sub HScroll1_Change() Label1.Caption = HScroll1.ValueEnd Sub

Private Sub HScroll1_Scroll() Label1.Caption = HScroll1.ValueEnd Sub

124

Page 133: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.00Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"Begin VB.Form Form1 Caption = "Form1" ClientHeight = 1830 ClientLeft = 3585 ClientTop = 2535 ClientWidth = 2175 LinkTopic = "Form1" ScaleHeight = 1830 ScaleWidth = 2175 Begin MSComctlLib.Slider Slider1 Height = 630 Left = 120 TabIndex = 1 Top = 840 Width = 1575 _ExtentX = 2778 _ExtentY = 1111 _Version = 393216 LargeChange = 1 Min = 1 Max = 20 SelStart = 1 Value = 1 End

Begin VB.Label Label1 Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single Caption = "1" ForeColor = &H80000008& Height = 495 Left = 240 TabIndex = 0 Top = 240 Width = 1500 EndEnd

Code:Private Sub Slider1_Change() Label1.Caption = Slider1.ValueEnd Sub

Private Sub Slider1_Click() Label1.Caption = Slider1.ValueEnd Sub

125

Page 134: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 5, Lesson CQuestions1. d MsgBox2. e Unload3. a Change4. b Alignment5. a For intX = 2 To 0 Step –1

sngTotal = sngTotal + Val(txtSales(intX).Text)Next intX

6. a -1

Exercises1. 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)

126

Page 135: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmColfaxEnd Sub

Private Sub cmdPrint_Click() Frame1.Visible = False PrintForm Frame1.Visible = TrueEnd Sub

Private Sub Form_Load() frmColfax.Left = (Screen.Width - frmColfax.Width) / 2 frmColfax.Top = (Screen.Height - frmColfax.Height) / 2End 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 IfEnd 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

127

Page 136: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Code #2 (step m)Option Explicit

Private Sub cmdAdd_Click() Dim intX As Integer, sngSales As Single, sngTotal As Single Do While intX <= 3 sngSales = Val(txtRegion(intX).Text) sngTotal = sngTotal + sngSales intX = intX + 1 Loop lblTotal.Caption = Format(sngTotal, "currency")End Sub

Private Sub cmdExit_Click() Unload frmColfaxEnd Sub

Private Sub cmdPrint_Click() Frame1.Visible = False PrintForm Frame1.Visible = TrueEnd Sub

Private Sub Form_Load() frmColfax.Left = (Screen.Width - frmColfax.Width) / 2 frmColfax.Top = (Screen.Height - frmColfax.Height) / 2End 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 IfEnd 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

128

Page 137: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. lc2Done – The student should submit two printouts of the interface with the test data showing and a printout of the code.

Printout #1 (step i) Printout #2 (step j)

Option ExplicitDim intState As Integer, intCapital As Integer

Private Sub cmdExit_Click() Unload frmStatesEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub cmdVerify_Click() If intState = intCapital Then lblAnswer.Caption = "Correct" Else lblAnswer.Caption = "Incorrect" End IfEnd Sub

Private Sub Form_Load() frmStates.Left = (Screen.Width – frmStates.Width) / 2 frmStates.Top = (Screen.Height – frmStates.Height) / 2 optState(0).Value = True optCapital(1).Value = TrueEnd 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, " States and Capitals") If intUser = vbNo Then Cancel = 1 End IfEnd Sub

Private Sub optCapital_Click(Index As Integer) lblAnswer.Caption = "" intCapital = IndexEnd Sub

Private Sub optState_Click(Index As Integer) lblAnswer.Caption = "" intState = IndexEnd Sub

3. lc3Done – The student should submit a printout of the interface with the test data showing and a printout of the code. The total sales and the bonus may not be formatted.

129

Page 138: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub cmdCalc_Click() Dim strSales As String, sngTotal As Single strSales = InputBox("Enter a sales amount. Click Cancel to stop.", "Sales Entry") Do While strSales <> "" sngTotal = sngTotal + Val(strSales) strSales = InputBox("Enter a sales amount. Click Cancel to stop.", "Sales Entry") Loop lblTotal.Caption = Format(sngTotal, "currency") lblBonus.Caption = Format(sngTotal * 0.1, "currency")End Sub

Private Sub cmdExit_Click() Unload frmSalesEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmSales.Left = (Screen.Width – frmSales.Width) / 2 frmSales.Top = (Screen.Height – frmSales.Height) / 2End 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, "RM Sales") If intUser = vbNo Then Cancel = 1 End IfEnd Sub

4. lc4Done project – The student should submit two printouts of the interface with the test data showing and a printout of the code. The total income, total expense, and profit/(loss) may not be formatted. The interface design may vary.

Printout #1: Printout #2:

130

Page 139: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub cmdCalc_Click() Dim strIncome As String, strExpense As String Dim sngTotInc As Single, sngTotExp As Single 'get income amounts strIncome = InputBox("Enter an income amount:", "Income Entry") Do While strIncome <> "" sngTotInc = sngTotInc + Val(strIncome) strIncome = InputBox("Enter an income amount:", "Income Entry") Loop 'get expense amounts strExpense = InputBox("Enter an expense amount:", "Expense Entry") Do While strExpense <> "" sngTotExp = sngTotExp + Val(strExpense) strExpense = InputBox("Enter an expense amount:", "Expense Entry") Loop lblIncome.Caption = Format(sngTotInc, "currency") lblExpense.Caption = Format(sngTotExp, "currency") lblProfLoss.Caption = Format(sngTotInc - sngTotExp, "currency")End Sub

Private Sub cmdExit_Click() Unload frmPremiumEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmPremium.Left = (Screen.Width - frmPremium.Width) / 2 frmPremium.Top = (Screen.Height - frmPremium.Height) / 2End 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, "Premium Paper") If intUser = vbNo Then Cancel = 1 End IfEnd Sub

5. (Discovery) lc5Done project – The student should submit a printout of the code, as well as a handwritten answer to step g. Changes to the original code are shaded.

step g:The 32 was calculated by adding together the 24 stored in the txtFirst control and the 8 stored in the txtSecond control.

131

Page 140: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub cmdCalc_Click() Dim sngFirst As Single, sngSecond As Single Dim sngTotal As Single sngFirst = Val(txtFirst.Text) sngSecond = Val(txtSecond.Text) sngTotal = sngFirst + sngSecond lblTotal.Caption = sngTotalEnd Sub

Private Sub cmdExit_Click() Unload frmTextAlignEnd Sub

Private Sub Form_Load() frmTextAlign.Top = (Screen.Height - frmTextAlign.Height) / 2 frmTextAlign.Left = (Screen.Width - frmTextAlign.Width) / 2End Sub

Private Sub txtFirst_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 End IfEnd Sub

Private Sub txtSecond_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 End IfEnd Sub

6. (Discovery) lc6Done project – The student should submit a printout of the code.Option Explicit

Private Sub cmdClear_Click() Dim intX As Integer For intX = 0 To 8 optO(intX).Value = False optX(intX).Value = False optO(intX).Enabled = True optX(intX).Enabled = True lblXO(intX).Caption = "" Next intXEnd Sub

Private Sub cmdExit_Click() Unload frmTTTEnd Sub

Private Sub Form_Load() frmTTT.Top = (Screen.Height - frmTTT.Height) / 2 frmTTT.Left = (Screen.Width - frmTTT.Width) / 2End Sub

Private Sub optO_Click(Index As Integer) lblXO(Index).Caption = "O" optX(Index).Enabled = False Call VerifyWinnerEnd Sub

Private Sub optX_Click(Index As Integer) lblXO(Index).Caption = "X" optO(Index).Enabled = False Call VerifyWinnerEnd Sub

132

Page 141: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub VerifyWinner() Dim intUser As Integer Const conBtns As String = _ vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal Select Case True Case lblXO(0).Caption & lblXO(1).Caption & lblXO(2).Caption = "XXX" _ Or lblXO(0).Caption & lblXO(1).Caption & lblXO(2).Caption = "OOO" intUser = MsgBox(lblXO(0) & " is the winner!", conBtns, "Winner") Case lblXO(3).Caption & lblXO(4).Caption & lblXO(5).Caption = "XXX" _ Or lblXO(3).Caption & lblXO(4).Caption & lblXO(5).Caption = "OOO" intUser = MsgBox(lblXO(3) & " is the winner!", conBtns, "Winner") Case lblXO(6).Caption & lblXO(7).Caption & lblXO(8).Caption = "XXX" _ Or lblXO(6).Caption & lblXO(7).Caption & lblXO(8).Caption = "OOO" intUser = MsgBox(lblXO(6) & " is the winner!", conBtns, "Winner") Case lblXO(0).Caption & lblXO(3).Caption & lblXO(6).Caption = "XXX" _ Or lblXO(0).Caption & lblXO(3).Caption & lblXO(6).Caption = "OOO" intUser = MsgBox(lblXO(0) & " is the winner!", conBtns, "Winner") Case lblXO(1).Caption & lblXO(4).Caption & lblXO(7).Caption = "XXX" _ Or lblXO(1).Caption & lblXO(4).Caption & lblXO(7).Caption = "OOO" intUser = MsgBox(lblXO(1) & " is the winner!", conBtns, "Winner") Case lblXO(2).Caption & lblXO(5).Caption & lblXO(8).Caption = "XXX" _ Or lblXO(2).Caption & lblXO(5).Caption & lblXO(8).Caption = "OOO" intUser = MsgBox(lblXO(2) & " is the winner!", conBtns, "Winner") Case lblXO(0).Caption & lblXO(4).Caption & lblXO(8).Caption = "XXX" _ Or lblXO(0).Caption & lblXO(4).Caption & lblXO(8).Caption = "OOO" intUser = MsgBox(lblXO(0) & " is the winner!", conBtns, "Winner") Case lblXO(2).Caption & lblXO(4).Caption & lblXO(6).Caption = "XXX" _ Or lblXO(2).Caption & lblXO(4).Caption & lblXO(6).Caption = "OOO" intUser = MsgBox(lblXO(2) & " is the winner!", conBtns, "Winner") End SelectEnd Sub

133

Page 142: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 5 – Debugging

TechniqueYou can use the KeyPress event to control what the user can enter into a text box. For example, you can use the KeyPress event to prevent a user from entering anything other than a number. The KeyPress event occurs when the user presses and releases a key that is a member of the ANSI (American National Standards Institute) character set. The ANSI character set contains 256 characters. The first 128 characters (0-127) correspond to the letters and symbols on a standard U.S. keyboard. For example, the ANSI characters 48 through 57 correspond to the numbes 0 through 9, respectively. The ANSI character 8 corresponds to the Backspace key. The remaining 128 characters (128-255) in the ANSI character set represent special characters, such as letters in international alphabets, accents, currency symbols, and fractions.

Exercises1. Debug1 project – The student is not instructed to submit anything for this debugging

exercise.2. The student should submit a printout of both the original and the modified code. Changes to

the original code are shaded.

Original code:Private Sub cmdExit_Click() Unload frmDebug2End Sub

Private Sub Form_Load() frmDebug2.Top = (Screen.Height – frmDebug2.Height) / 2 frmDebug2.Left = (Screen.Width – frmDebug2.Width) / 2End Sub

Private Sub txtFirst_KeyPress(KeyAscii As Integer) Const conEnter As Integer = 12 If KeyAscii = conEnter Then txtSecond.SetFocus End IfEnd Sub

Private Sub txtSecond_Change() Const conEnter As Integer = 13 If KeyAscii = conEnter Then cmdExit.SetFocus End IfEnd Sub

Modified code:Private Sub cmdExit_Click() Unload frmDebug2End Sub

Private Sub Form_Load() frmDebug2.Top = (Screen.Height - frmDebug2.Height) / 2 frmDebug2.Left = (Screen.Width - frmDebug2.Width) / 2End Sub

Private Sub txtFirst_KeyPress(KeyAscii As Integer) Const conEnter As Integer = 13 If KeyAscii = conEnter Then KeyAscii = 0 txtSecond.SetFocus End IfEnd Sub

Private Sub txtSecond_KeyPress(KeyAscii As Integer) Const conEnter As Integer = 13 If KeyAscii = conEnter Then KeyAscii = 0 cmdExit.SetFocus End IfEnd Sub

134

Page 143: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 6, Lesson AQuestions1. a AddItem2. a three, eight3. e Text4. d all of the above (alphabetical, chronological, numerical)5. d Sorted6. d ListIndex7. c Load8. d lstOffice.AddItem “DESK”9. d lstYear.AddItem 199910. a 111. b lstTerm.ListIndex = 012. b field13. d record14. a data file15. b Input16. c Output17. a Append18. c Open “a:\data.dat” for append as #119. a Write #1, strLname, strFname20. d Close #321. b intTotal = intTotal + 122. b, cDo Until EOF(1), Do While Not EOF(1)23. b end of file24. a Input #1, strName, curSalary25. You use a label control to give keyboard access to a list box. Assign the access key to the

label control’s Caption property, then set the label control’s TabIndex property to a value that is one less than the TabIndex value of the list box.

26. a Printer.Print “January”, “February”27. d Printer.Print , 5,28. c Visual Basic prints strings with a trailing space.29. d All of the above30. c Printer.Print Tab(13); “Item”; Tab(25); “Price”31. e Dim strName as String * 2032. b RSet strNumber = Format(intNum, “general number”)33. d EndDoc

135

Page 144: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1. la1DoneA and la1DoneB projects – The student should submit two printouts of the

interface with the test data showing and two printouts of the code.

Printout #1: Printout #2:

Code printout #1:Private Sub cmdExit_Click() Unload frmExtEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmExt.Top = (Screen.Height – frmExt.Height) / 2 frmExt.Left = (Screen.Width – frmExt.Width) / 2 lstExt.AddItem "Smith, Joe" lstExt.AddItem "Jones, Mary" lstExt.AddItem "Adkari, Joel" lstExt.AddItem "Lin, Sue" lstExt.AddItem "Li, Vicky" lstExt.ListIndex = 0End Sub

Private Sub lstExt_Click() Select Case lstExt.Text Case "Smith, Joe" lblExt.Caption = 3388 Case "Jones, Mary" lblExt.Caption = 3356 Case "Adkari, Joel" lblExt.Caption = 2487 Case "Lin, Sue" lblExt.Caption = 1111 Case "Li, Vicky" lblExt.Caption = 2222 End SelectEnd Sub

Code printout #2:Private Sub cmdExit_Click() Unload frmExtEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmExt.Top = (Screen.Height - frmExt.Height) / 2 frmExt.Left = (Screen.Width - frmExt.Width) / 2 lstExt.AddItem "Smith, Joe" lstExt.AddItem "Jones, Mary" lstExt.AddItem "Adkari, Joel" lstExt.AddItem "Lin, Sue" lstExt.AddItem "Li, Vicky" lstExt.ListIndex = 0End Sub

Private Sub lstExt_Click() Select Case lstExt.ListIndex Case 4 lblExt.Caption = 3388 Case 1 lblExt.Caption = 3356 Case 0 lblExt.Caption = 2487 Case 3 lblExt.Caption = 1111 Case 2 lblExt.Caption = 2222 End SelectEnd Sub

136

Page 145: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. la2Done project – The student should submit a printout of a report and a printout of the code.

Consolidated Advertising

City Zip CodeDarien 60561Hinsdale 60544Glen Ellyn 60137Downers Grove 60135Burr Ridge 60136

Total records: 5End of report

Option Explicit

Private Sub cmdExit_Click() Unload frmConsolidEnd Sub

Private Sub cmdPrint_Click() Dim strCity As String, strZip As String, intRecords As Integer Dim strFont As String, sngSize As Single strFont = Printer.Font sngSize = Printer.FontSize Printer.Font = "courier new" Printer.FontSize = 10 Printer.Print "Consolidated Advertising" Printer.Print Printer.Print "City"; Tab(30); "Zip Code" Open "a:\tut06\la2.dat" For Input As #1 Do While Not EOF(1) Input #1, strCity, strZip intRecords = intRecords + 1 Printer.Print strCity; Tab(30); strZip Loop Close #1 Printer.Print Printer.Print "Total records: "; intRecords Printer.Print "End of report" Printer.EndDoc Printer.Font = strFont Printer.FontSize = sngSizeEnd Sub

Private Sub cmdWrite_Click() Open "a:\tut06\la2.dat" For Append As #1 Write #1, txtCity.Text, txtZip.Text Close #1 txtCity.SetFocusEnd Sub

Private Sub Form_Load() frmConsolid.Top = (Screen.Height - frmConsolid.Height) / 2

Private Sub txtCity_GotFocus() txtCity.SelStart = 0 txtCity.SelLength = Len(txtCity.Text)End Sub

Private Sub txtZip_GotFocus() txtZip.SelStart = 0 txtZip.SelLength = Len(txtZip.Text)End Sub

137

Page 146: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

frmConsolid.Left = (Screen.Width - frmConsolid.Width) / 2End Sub

138

Page 147: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3. la3Done project – The student should submit two printouts of the report and a printout of the code.

Report printout #1:Boggs Inc.

Number Quantity PriceABC12 100 10.50XYZ35 50 15.99KLK25 150 20.00

Average price: $16.17End of report

Report printout #2:Boggs Inc.

Number Quantity PriceABC12 100 10.50XYZ35 50 15.99KLK25 150 20.00WER10 110 5.53JAN24 20 4.56

Average price: $12.90End of report

Option Explicit

Private Sub cmdExit_Click() Unload frmBoggsEnd Sub

Private Sub cmdPrint_Click() Dim strNum As String, intQuantity As Integer, sngPrice As Single Dim intItems As Integer, sngTotPrice As Single, sngAvgPrice As Single Dim strFont As String, sngSize As Single Dim strPS1 As String * 8, strPS2 As String * 10 strFont = Printer.Font sngSize = Printer.FontSize Printer.Font = "courier new" Printer.FontSize = 10 Printer.Print "Boggs Inc." Printer.Print Printer.Print "Number"; Tab(17); "Quantity"; Tab(28); "Price" Open "a:\tut06\la3.dat" For Input As #1 Do While Not EOF(1) Input #1, strNum, intQuantity, sngPrice intItems = intItems + intQuantity sngTotPrice = sngTotPrice + intQuantity * sngPrice RSet strPS1 = Format(sngPrice, "fixed") RSet strPS2 = Format(intQuantity, "general number") Printer.Print strNum; Tab(15); strPS2; Tab(25); strPS1 Loop Close #1 If intItems > 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 = sngSizeEnd Sub

139

Page 148: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdWrite_Click() Dim intQuantity As Integer, sngPrice As Single intQuantity = Val(txtQuantity.Text) sngPrice = Val(txtPrice.Text) Open "a:\tut06\la3.dat" For Append As #1 Write #1, txtNum.Text, intQuantity, sngPrice Close #1 txtNum.SetFocusEnd Sub

Private Sub Form_Load() frmBoggs.Top = (Screen.Height – frmBoggs.Height) / 2 frmBoggs.Left = (Screen.Width – frmBoggs.Width) / 2End Sub

Private Sub txtNum_GotFocus() txtNum.SelStart = 0 txtNum.SelLength = Len(txtNum.Text)End Sub

Private Sub txtQuantity_GotFocus() txtQuantity.SelStart = 0 txtQuantity.SelLength = Len(txtQuantity.Text)End Sub

Private Sub txtPrice_GotFocus() txtPrice.SelStart = 0 txtPrice.SelLength = Len(txtPrice.Text)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.5Option Explicit

Private Sub cmdExit_Click() Unload frmAreaEnd Sub

Private Sub Form_Load() frmArea.Left = (Screen.Width - frmArea.Width) / 2 frmArea.Top = (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 = sngAreaEnd Sub

140

Page 149: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = TrueEnd 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 = FalseEnd Sub

Private Sub cmdExit_Click() Unload frmPaoEnd 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

141

Page 150: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

'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 = sngSizeEnd Sub

142

Page 151: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub Form_Load() frmPao.Top = (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 = 1End 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

143

Page 152: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmPaoEnd Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

144

Page 153: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = sngSizeEnd Sub

Private Sub Form_Load() frmPao.Top = (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

145

Page 154: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

Option Explicit

Private Sub cmdExit_Click() Unload frmExtEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() Dim strName As String frmExt.Top = (Screen.Height - frmExt.Height) / 2 frmExt.Left = (Screen.Width - frmExt.Width) / 2 Open "a:\tut06\la7.dat" For Input As #1 Do While Not EOF(1) Input #1, strName lstExt.AddItem strName Loop lstExt.ListIndex = 0End Sub

Private Sub lstExt_Click() Select Case lstExt.Text Case "Smith, Joe" lblExt.Caption = 3388 Case "Jones, Mary" lblExt.Caption = 3356 Case "Adkari, Joel" lblExt.Caption = 2487 Case "Lin, Sue" lblExt.Caption = 1111 Case "Li, Vicky" lblExt.Caption = 2222 End SelectEnd 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:"Franklin Park","60131""River Grove","60171""Elmwood Park","60191""Northlake","60145""River Forest","60305""LaGrange","60525""Oak Park","60405""Chicago","60304"

Report:

Dr. Jonas Patient List

Name Birthday ---- -------- Sally Bramas 3/9/95

End of report

146

Page 155: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim strFound As String

Private Sub cmdExit_Click() Unload frmJonasEnd 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 = sngSizeEnd 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.SetFocusEnd Sub

Private Sub Form_Load() frmJonas.Top = (Screen.Height - frmJonas.Height) / 2 frmJonas.Left = (Screen.Width - frmJonas.Width) / 2 strFound = "N"End Sub

147

Page 156: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 IfEnd 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 IfEnd Sub

148

Page 157: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

9. (Discovery) la9Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

Option Explicit

Private Sub cmdExit_Click() Unload frmElementsEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmElements.Top = (Screen.Height - frmElements.Height) / 2 frmElements.Left = (Screen.Width - frmElements.Width) / 2 lstElements.AddItem "Cloud" lstElements.AddItem "Rain" lstElements.AddItem "Snow" lstElements.AddItem "Sun" lstElements.AddItem "Lightning" lstElements.ListIndex = 0End Sub

Private Sub lstElements_Click() imgElement.Picture = imgIcons(lstElements.ListIndex).PictureEnd Sub

149

Page 158: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 IfEnd 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 IfEnd Sub

150

Page 159: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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:0 (Default) Multiple selection is not allowed1 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.

2 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:Option Explicit

Private Sub Command1_Click() Print List1.TextEnd Sub

Private Sub Form_Load() List1.AddItem "Ahmad" List1.AddItem "Jim" List1.AddItem "Debbie" List1.AddItem "Jeanne" List1.AddItem "Bill"End Sub

step p code:Option Explicit

Private Sub Command1_Click() Dim intX As Integer For intX = 0 To List1.ListCount - 1 If List1.Selected(intX) = True Then Print List1.List(intX) End If Next intXEnd Sub

Private Sub Form_Load() List1.AddItem "Ahmad" List1.AddItem "Jim" List1.AddItem "Debbie" List1.AddItem "Jeanne" List1.AddItem "Bill"End Sub

151

Page 160: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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):"Smith, Joe""Jones, Mary""Adkari, Joel""Lin, Sue""Li, Vicky""Patel, Orman""White, Pam""Abram, Jill""Chen, Sue""Dune, Joe""Willard, Tom""Krisen, Jerry"

la12act.dat file (step l):"Abram, Jill""Adkari, Joel""Chen, Sue""Dune, Joe""Jones, Mary""Li, Vicky""Lin, Sue""Patel, Orman""Smith, Joe""White, Pam"

la12act.dat file (step n):"Abram, Jill""Adkari, Joel""Chen, Sue""Dune, Joe""Jones, Mary""Li, Vicky""Lin, Sue""Patel, Orman""Smith, Joe""White, Pam""Willard, Tom"

la12act.dat file (step q):"Abram, Jill""Adkari, Joel""Chen, Sue""Dune, Joe""Jones, Mary""Li, Vicky""Lin, Sue""Patel, Orman""Smith, Joe""White, Pam""Willard, Tom"

la12inac.dat file (step b):"Kendry, Paul""Yelton, Bob""Patel, Suman""Patel, Mamta""Lee, Janice""Jones, Scotty"

la12inac.dat file (step l):"Jones, Scotty""Kendry, Paul""Krisen, Jerry""Lee, Janice""Patel, Mamta""Patel, Suman""Willard, Tom""Yelton, Bob"

la12inac.dat file (step n):"Jones, Scotty""Kendry, Paul""Krisen, Jerry""Lee, Janice""Patel, Mamta""Patel, Suman""Yelton, Bob"

la12inac.dat file (step q):"Kendry, Paul""Lee, Janice""Patel, Mamta""Patel, Suman""Yelton, Bob"

152

Page 161: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub cmdExit_Click() Unload frmAbcEnd Sub

Private Sub cmdInactive_Click() Dim intX As Integer Do While intX < lstActive.ListCount If lstActive.Selected(intX) = True Then lstInactive.AddItem lstActive.List(intX) lstActive.RemoveItem intX Else intX = intX + 1 End If LoopEnd Sub

Private Sub cmdReactivate_Click() Dim intX As Integer Do While intX < lstInactive.ListCount If lstInactive.Selected(intX) = True Then lstActive.AddItem lstInactive.List(intX) lstInactive.RemoveItem intX Else intX = intX + 1 End If LoopEnd Sub

Private Sub cmdRemove_Click() Dim intX As Integer Do While intX < lstInactive.ListCount If lstInactive.Selected(intX) = True Then lstInactive.RemoveItem intX Else intX = intX + 1 End If LoopEnd Sub

Private Sub Form_Load() Dim strName As String frmAbc.Top = (Screen.Height – frmAbc.Height) / 2 frmAbc.Left = (Screen.Width - frmAbc.Width) / 2 Open "a:\tut06\la12act.dat" For Input As #1 Do While Not EOF(1) Input #1, strName lstActive.AddItem strName Loop Close #1 Open "a:\tut06\la12inac.dat" For Input As #1 Do While Not EOF(1) Input #1, strName lstInactive.AddItem strName Loop Close #1End Sub

Private Sub Form_Unload(Cancel As Integer) Dim intX As Integer Open "a:\tut06\la12act.dat" For Output As #1 Open "a:\tut06\la12inac.dat" For Output As #2 For intX = 0 To lstActive.ListCount - 1 Write #1, lstActive.List(intX) Next intX Close #1 For intX = 0 To lstInactive.ListCount - 1 Write #2, lstInactive.List(intX) Next intX Close #2End Sub

13. (Discovery) la13Done project – The student should submit two printouts of the multiplication table and a printout of the code.

Multiplication Table

1 X 5 = 52 X 5 = 103 X 5 = 154 X 5 = 205 X 5 = 256 X 5 = 307 X 5 = 358 X 5 = 409 X 5 = 45

Multiplication Table

1 X 9 = 92 X 9 = 183 X 9 = 274 X 9 = 365 X 9 = 456 X 9 = 547 X 9 = 638 X 9 = 729 X 9 = 81

153

Page 162: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End of report End of report

Option Explicit

Private Sub cmdExit_Click() Unload frmTableEnd 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.SetFocusEnd Sub

Private Sub Form_Load() frmTable.Left = (Screen.Width - frmTable.Width) / 2 frmTable.Top = (Screen.Height - frmTable.Height) / 2End Sub

Private Sub txtNum_Change() If txtNum.Text = "" Then cmdPrint.Enabled = False Else cmdPrint.Enabled = True End IfEnd Sub

Private Sub txtNum_GotFocus() txtNum.SelStart = 0 txtNum.SelLength = Len(txtNum.Text)End Sub

154

Page 163: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

14. (Discovery) la14Done project – The student should submit a printout of the three columns of numbers and a printout of the code.

564 777 9094,500 888 9 4 59 34,556

Option Explicit

Private Sub cmdExit_Click() Unload frmFormatEnd 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 = sngSizeEnd Sub

155

Page 164: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 6, Lesson BQuestions1. d Resize2. c ScaleWidth, Width3. c form’s Resize4. a,d Height, Width5. b,c ScaleHeight,ScaleWidth6. a,c Caption, Name7. b Click8. b menu titles9. e separator bar10. c hyphen11. a access12. e shortcut13. 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.Clear17. d Clipboard.SetText “Hello”18. b lblMsg.Caption = Clipboard.GetText()19. b SelText20. a GetText()21. c Enabled22. b MultiLine23. c ScrollBars24. b MultiLine

Exercises1. lb1Done project – The student should submit a printout of the interface with the test data

showing and a printout of the code.

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)

156

Page 165: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.SetFocusEnd Sub

Private Sub Form_Load() frmGrade.Left = (Screen.Width – frmGrade.Width) / 2 frmGrade.Top = (Screen.Height – frmGrade.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmGradeEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

Private Sub txtFinal_GotFocus() txtFinal.SelStart = 0 txtFinal.SelLength = Len(txtFinal.Text)End Sub

Private Sub txtMid_GotFocus() txtMid.SelStart = 0 txtMid.SelLength = Len(txtMid.Text)End Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

Private Sub txtP1_GotFocus() txtP1.SelStart = 0 txtP1.SelLength = Len(txtP1.Text)End Sub

Private Sub txtP2_GotFocus() txtP2.SelStart = 0 txtP2.SelLength = Len(txtP2.Text)End Sub

157

Page 166: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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:

Option Explicit

Private Sub Form_Load() frmVenus.Top = (Screen.Height - frmVenus.Height) / 2 frmVenus.Left = (Screen.Width - frmVenus.Width) / 2 optModel(0).Value = True optPkg(0).Value = TrueEnd Sub

Private Sub mnuCompute5_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.05 sngTotal = sngSub + sngTax lblSub.Caption = sngSub lblTax.Caption = sngTax lblTotal.Caption = sngTotalEnd 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 = sngTotalEnd Sub

Private Sub mnuFileClear_Click() txtName.Text = "" txtTrade.Text = "" lblSub.Caption = "" lblTax.Caption = "" lblTotal.Caption = ""End Sub

Private Sub mnuFileExit_Click() Unload frmVenusEnd Sub

Private Sub mnuFilePrintNologo_Click() imgLogo.Visible = False PrintForm imgLogo.Visible = TrueEnd Sub

158

Page 167: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub optModel_Click(Index As Integer) Select Case Index Case 0 lblBase.Caption = 10500 Case 1 lblBase.Caption = 21000 Case 2 lblBase.Caption = 15500 End Select lblSub.Caption = "" lblTax.Caption = "" lblTotal.Caption = ""End Sub

Private Sub optPkg_Click(Index As Integer) If Index = 0 Then lblPkg.Caption = 2000 Else lblPkg.Caption = 3000 End If lblSub.Caption = "" lblTax.Caption = "" lblTotal.Caption = ""End Sub

Private Sub mnuFilePrintWithlogo_Click() PrintFormEnd Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

Private Sub txtTrade_Change() lblSub.Caption = "" lblTax.Caption = "" lblTotal.Caption = ""End Sub

Private Sub txtTrade_GotFocus() txtTrade.SelStart = 0 txtTrade.SelLength = Len(txtTrade.Text)End Sub

3. (Discovery) lb3Adone and lb3Bdone projects – The student should submit two printouts of the code.

lb3Adone.frmOption Explicit

Private Sub Form_Load() frmTrans.Top = (Screen.Height – frmTrans.Height) / 2 frmTrans.Left = (Screen.Width – frmTrans.Width) / 2End Sub

Private Sub mnuDisplayBicycle_Click() lblBike.Visible = True imgBike.Visible = True lblRocket.Visible = False imgRocket.Visible = False mnuDisplayBicycle.Checked = True mnuDisplayRocket.Checked = FalseEnd Sub

Private Sub mnuDisplayRocket_Click() lblRocket.Visible = True imgRocket.Visible = True lblBike.Visible = False imgBike.Visible = False mnuDisplayRocket.Checked = True mnuDisplayBicycle.Checked = FalseEnd Sub

lb3Bdone.frmOption Explicit

Private Sub Form_Load() frmTrans.Top = (Screen.Height – frmTrans.Height) / 2 frmTrans.Left = (Screen.Width – frmTrans.Width) / 2End Sub

Private Sub mnuDisplayBicycle_Click() lblBike.Visible = Not lblBike.Visible imgBike.Visible = Not imgBike.Visible mnuDisplayBicycle.Checked = Not mnuDisplayBicycle.CheckedEnd Sub

Private Sub mnuDisplayRocket_Click() lblRocket.Visible = Not lblRocket.Visible imgRocket.Visible = Not imgRocket.Visible mnuDisplayRocket.Checked = Not mnuDisplayRocket.CheckedEnd Sub

159

Page 168: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. (Discovery) lb4Done project – The student should submit a printout of the code. Changes to the original code are shaded.

Option ExplicitPrivate Sub Form_Load() frmVenus.Top = (Screen.Height – frmVenus.Height) / 2 frmVenus.Left = (Screen.Width – frmVenus.Width) / 2 optModel(0).Value = True optPkg(0).Value = TrueEnd Sub

Private Sub mnuCompute5_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.05 sngTotal = sngSub + sngTax lblSub.Caption = sngSub lblTax.Caption = sngTax lblTotal.Caption = sngTotalEnd 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 = sngTotalEnd Sub

Private Sub mnuFileClear_Click() txtName.Text = "" txtTrade.Text = "" Call ClearEnd Sub

Private Sub mnuFileExit_Click() Unload frmVenusEnd Sub

Private Sub mnuFilePrintNologo_Click() imgLogo.Visible = False PrintForm imgLogo.Visible = TrueEnd Sub

Private Sub mnuFilePrintWithlogo_Click() PrintFormEnd Sub

Private Sub optModel_Click(Index As Integer) Select Case Index Case 0 lblBase.Caption = 10500 Case 1 lblBase.Caption = 21000 Case 2 lblBase.Caption = 15500 End Select Call ClearEnd Sub

Private Sub optPkg_Click(Index As Integer) If Index = 0 Then lblPkg.Caption = 2000 Else lblPkg.Caption = 3000 End If Call ClearEnd Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

Private Sub txtTrade_Change() Call ClearEnd Sub

Private Sub txtTrade_GotFocus() txtTrade.SelStart = 0 txtTrade.SelLength = Len(txtTrade.Text)End Sub

Private Sub Clear() lblSub.Caption = "" lblTax.Caption = "" lblTotal.Caption = ""End Sub

160

Page 169: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 6, Lesson CQuestions1. b,c Left, Mid2. c,d Mid Right3. c Mid4. d Ha5. c ay6. c lcom7. b Mid(strName, 1, 3)8. d Mid(strName, 11, 3)9. a 010. c 1711. c 1712. a 013. d SelStart14. a 9

Exercises1. Mary

thBck

161

Page 170: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. nCalifoornialifor

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:

Error messages from step e: “Incorrect status” and “Incorrect type”Option ExplicitPrivate 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.SetFocusEnd Sub

162

Page 171: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdExit_Click() Unload frmBobCatEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmBobCat.Left = (Screen.Width – frmBobCat.Width) / 2 frmBobCat.Top = (Screen.Height – frmBobCat.Height) / 2End Sub

Private Sub txtId_Change() lblStatus.Caption = "" lblInitials.Caption = "" lblType.Caption = ""End Sub

Private Sub txtId_GotFocus() txtId.SelStart = 0 txtId.SelLength = Len(txtId.Text)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:

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.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmAcmeEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

163

Page 172: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub Form_Load() frmAcme.Left = (Screen.Width – frmAcme.Width) / 2 frmAcme.Top = (Screen.Height – frmAcme.Height) / 2End Sub

Private Sub txtNumber_Change() lblStatus.Caption = ""End Sub

Private Sub txtNumber_GotFocus() txtNumber.SelStart = 0 txtNumber.SelLength = Len(txtNumber.Text)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:

164

Page 173: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub Form_Load() frmComputer.Top = (Screen.Height – frmComputer.Height) / 2 frmComputer.Left = (Screen.Width – frmComputer.Width) / 2 lstItem.AddItem "ABC11" lstItem.AddItem "CVA33" lstItem.AddItem "BDX22" lstItem.ListIndex = 0End Sub

Private Sub mnuFileExit_Click() Unload frmComputerEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd 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

165

Page 174: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 SoldBDX22 100 BDX22 100ABC11 150 BDX22 250BDX22 250 BDX22 200CVA33 100 BDX22 120ABC11 300BDX22 200 Total records: 4ABC11 140BDX22 120 End of reportCVA33 110ABC11 500

Total records: 10

End of report

Option Explicit

Private Sub Form_Load() frmComputer.Top = (Screen.Height - frmComputer.Height) / 2 frmComputer.Left = (Screen.Width - frmComputer.Width) / 2 lstItem.AddItem "ABC11" lstItem.AddItem "CVA33" lstItem.AddItem "BDX22" lstItem.ListIndex = 0End Sub

Private Sub mnuFileExit_Click() Unload frmComputerEnd 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

166

Page 175: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = sngSizeEnd Sub

167

Page 176: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = sngSizeEnd Sub

168

Page 177: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.frmOption ExplicitDim 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 clipboardEnd 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.SetFocusEnd 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

169

Page 178: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lc7Find.frmOption 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 IfEnd Sub

Private Sub cmdCancel_Click() Unload frmFindEnd Sub

Private Sub Form_Load() frmFind.Top = (Screen.Height - frmFind.Height) / 2 frmFind.Left = (Screen.Width - frmFind.Width) / 2End Sub

Private Sub txtFind_Change() strNewSearch = "Y"End Sub

Private Sub txtFind_GotFocus() txtFind.SelStart = 0 txtFind.SelLength = Len(txtFind.Text)End Sub

lc7Done.basOption ExplicitPublic strNewSearch As String

170

Page 179: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 Digit1357 135764273 427313907 390754621 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.SetFocusEnd Sub

Private Sub Form_Load() frmNumber.Top = (Screen.Height - frmNumber.Height) / 2 frmNumber.Left = (Screen.Width - frmNumber.Width) / 2End Sub

Private Sub txtNumber_Change() lblMsg.Caption = ""End Sub

Private Sub txtNumber_GotFocus() txtNumber.SelStart = 0 txtNumber.SelLength = Len(txtNumber.Text)End Sub

171

Page 180: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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"

172

Page 181: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option Explicit

Private Sub cmdExit_Click() Unload frmBobCatEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmBobCat.Top = (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 = 0End 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 #1End Sub

173

Page 182: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 6 – Debugging

TechniqueVisual 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.

ExercisesThe 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 frmDebug2End Sub

Private Sub Form_Load() frmDebug2.Top = (Screen.Height – frmDebug2.Height) / 2 frmDebug2.Left = (Screen.Width – frmDebug2.Width) / 2End Sub

174

Page 183: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 7, Lesson AQuestions1. c Common Dialog2. e ShowOpen3. e ShowPrinter4. c Save As5. d ShowColor6. d ShowFont7. c Filter8. a “Picture Files(*.pic)|*.pic”9. b “Project Files(*.vbp;*.mak;*.vbg)|*.vbp;*.mak;*.vbg”10. c FileName11. c Flags12. c Flags

Exercises1. The student should submit a printout of the code.Private Sub cmdFull_Click() dlgColor.Flags = cdlCCFullOpen dlgColor.ShowColorEnd Sub

Private Sub cmdPartial_Click() dlgColor.Flags = cdlCCPreventFullOpen dlgColor.ShowColorEnd Sub

2. The student should submit a printout of the code.Private Sub cmdOpen_Click() dlg1.Filter = "All Files(*.*)|*.*" dlg1.Flags = cdlOFNCreatePrompt dlg1.ShowOpenEnd Sub

Private Sub cmdSave_Click() dlg1.Filter = "All Files(*.*)|*.*" dlg1.Flags = cdlOFNOverwritePrompt dlg1.ShowSaveEnd 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() dlgFont.Flags = cdlCFBoth + cdlCFEffects dlgFont.ShowFontEnd Sub

Private Sub cmdTT_Click() dlgFont.Flags = cdlCFBoth + cdlCFTTOnly dlgFont.ShowFontEnd Sub

Private Sub cmdWysiwyg_Click() dlgFont.Flags = cdlCFBoth + cdlCFWYSIWYG dlgFont.ShowFontEnd Sub

4. The student should submit a printout of the code.Private Sub cmdPrint_Click() dlgPrint.Flags = cdlPDDisablePrintToFile + cdlPDNoSelection + cdlPDNoPageNums dlgPrint.ShowPrinterEnd Sub

175

Page 184: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 7, Lesson BQuestions1. 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 cdlOFNOverwritePrompt5. b cdlOFNPathMustExist6. c dlgEdit.Filter = “Document Files(*.doc)|*.doc”7. e FileName

176

Page 185: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

8. d Write #9. b Print #10. d CancelError11. c error trapping12. c error-handling routine or error handler13. b On Error GoTo14. d Exit Sub15. a colon (:)16. d Call mnuFileSaveAs_Click17. a True and False

Exercises1. lb1Done project – The student should submit a printout of the code.Option ExplicitDim 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.SetFocusEnd Sub

Private Sub Form_Load() frmMthlyPay.Left = (Screen.Width - frmMthlyPay.Width) / 2 frmMthlyPay.Top = (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 = TrueEnd Sub

Private Sub lstInterest_Click() lblPayment.Caption = ""End Sub

Private Sub mnuFileExit_Click() Unload frmMthlyPayEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

177

Page 186: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub mnuFormatBackground_Click() dlgCommon.Flags = cdlCCRGBInit dlgCommon.Color = frmMthlyPay.BackColor dlgCommon.ShowColor frmMthlyPay.BackColor = dlgCommon.ColorEnd Sub

Private Sub mnuFormatFont_Click() dlgCommon.Flags = cdlCFScreenFonts dlgCommon.FontName = lblPayment.FontName dlgCommon.FontBold = lblPayment.FontBold dlgCommon.FontItalic = lblPayment.FontItalic dlgCommon.FontSize = lblPayment.FontSize dlgCommon.ShowFont lblPayment.FontName = dlgCommon.FontName lblPayment.FontBold = dlgCommon.FontBold lblPayment.FontItalic = dlgCommon.FontItalic lblPayment.FontSize = dlgCommon.FontSizeEnd Sub

Private Sub mnuFormatInfo_Click() Dim intX As Integer dlgCommon.Flags = cdlCCRGBInit dlgCommon.Color = fraInfo.BackColor dlgCommon.ShowColor For intX = 0 To 3 optTerm(intX).BackColor = dlgCommon.Color Next intX fraInfo.BackColor = dlgCommon.ColorEnd Sub

Private Sub optTerm_Click(Index As Integer) Select Case Index Case 0 intTerm = 2 Case 1 intTerm = 3 Case 2 intTerm = 4 Case Else intTerm = 5 End Select lblPayment.Caption = ""End Sub

Private Sub txtPrincipal_Change() lblPayment.Caption = ""End Sub

Private Sub txtPrincipal_GotFocus() txtPrincipal.SelStart = 0 txtPrincipal.SelLength = Len(txtPrincipal.Text)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.ColorEnd 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.FontSizeEnd Sub

178

Page 187: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 7, Lesson CQuestions1. 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 function3. d Input function4. d LOF5. a FileLen

Exercises1. 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"Smith, Joe""Jones, Mary""Adkari, Joel""Lin, Sue""Li, Vicky""Patel, Orman""White, Pam""Abram, Jill""Chen, Sue""Dune, Joe""Willard, Tom""Krisen, Jerry"

lcdata3.dat"Smith, Joe""Jones, Mary""Adkari, Joel""Lin, Sue""Li, Vicky""Patel, Orman""White, Pam""Abram, Jill""Chen, Sue""Dune, Joe"

179

Page 188: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lcdata2.dat"Kendry, Paul""Yelton, Bob""Patel, Suman""Patel, Mamta""Lee, Janice""Jones, Scotty"

lcdata4.dat"Franklin Park","60131""River Grove","60171""Elmwood Park","60191""Northlake","60145""River Forest","60305""LaGrange","60525""Oak Park","60405""North Park","60304"

Option Explicit

Private Sub Form_Resize() txtEdit.Height = frmEdit.ScaleHeight txtEdit.Width = frmEdit.ScaleWidthEnd Sub

Private Sub mnuFileExit_Click() Unload frmEditEnd 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

180

Page 189: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

Private Sub Form_Load() frmData.Left = (Screen.Width - frmData.Width) / 2 frmData.Top = (Screen.Height - frmData.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmDataEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

181

Page 190: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

182

Page 191: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 ExplicitDim strSearchFor As StringDim blnChange As Boolean, blnCancelSave As Boolean

Private Sub Form_Load() blnChange = False blnCancelSave = FalseEnd Sub

Private Sub Form_Resize() txtEdit.Height = frmEdit.ScaleHeight txtEdit.Width = frmEdit.ScaleWidthEnd 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 IfEnd Sub

183

Page 192: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 IfEnd Sub

Private Sub mnuEditCopy_Click() Clipboard.Clear 'clear clipboard Clipboard.SetText txtEdit.SelText 'send text to clipboardEnd Sub

Private Sub mnuEditCut_Click() Clipboard.Clear 'clear clipboard Clipboard.SetText txtEdit.SelText 'send text to clipboard txtEdit.SelText = "" 'remove selected text from text boxEnd 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 IfEnd 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 IfEnd Sub

184

Page 193: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub mnuEditPaste_Click() 'retrieve text from clipboard and paste into text box txtEdit.SelText = Clipboard.GetText()End Sub

Private Sub mnuFileExit_Click() Unload frmEditEnd 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

185

Page 194: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 SubPrintErrHandler: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 IfEnd Sub

186

Page 195: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 canceledEnd Sub

Private Sub txtEdit_Change() blnChange = TrueEnd 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.ShowOpenEnd Sub

187

Page 196: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmBonusEnd Sub

Private Sub Form_Load() frmBonus.Left = (Screen.Width – frmBonus.Width) / 2 frmBonus.Top = (Screen.Height – frmBonus.Height) / 2End 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 frmBonusEnd Sub

Private Sub Form_Load() frmBonus.Left = (Screen.Width - frmBonus.Width) / 2 frmBonus.Top = (Screen.Height - frmBonus.Height) / 2End Sub

188

Page 197: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmBonusEnd Sub

Private Sub Form_Load() frmBonus.Left = (Screen.Width - frmBonus.Width) / 2 frmBonus.Top = (Screen.Height - frmBonus.Height) / 2End 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.1Here: lblBonus.Caption = Format(sngBonus, "currency") Exit Sub

CalcErrHandler: intTemp = MsgBox(conMsg, conBtns, "Error") sngBonus = 0 Resume Here End Sub

Private Sub cmdExit_Click() Unload frmBonusEnd Sub

Private Sub Form_Load() frmBonus.Left = (Screen.Width - frmBonus.Width) / 2 frmBonus.Top = (Screen.Height - frmBonus.Height) / 2

189

Page 198: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

190

Page 199: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmPaoEnd Sub

Private Sub Form_Load() frmPao.Top = (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

191

Page 200: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 #1End Sub

192

Page 201: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

193

Page 202: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

Exercises1. 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 SelectEnd Sub

Private Sub cmdExit_Click() Unload frmDivideEnd Sub

Private Sub Form_Load() frmDivide.Left = (Screen.Width - frmDivide.Width) / 2 frmDivide.Top = (Screen.Height - frmDivide.Height) / 2End Sub

194

Page 203: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 SelectEnd Sub

Private Sub cmdExit_Click() Unload frmDivideEnd Sub

Private Sub Form_Load() frmDivide.Left = (Screen.Width - frmDivide.Width) / 2 frmDivide.Top = (Screen.Height - frmDivide.Height) / 2End Sub

195

Page 204: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 8, Lesson AQuestions1. e Type2. c either randomly or sequentially3. b General Declarations section of a code module4. e strCity As String * 155. d The string “Chicago” followed by eight blank spaces6. b byte7. d 88. d Open9. d Open10. c Put11. b Get12. c,e Open “a:\data.dat” for random as #1 Len = Len(udtEmpRec)

Open “a:\data.dat” for random as #1 Len = 10013. d Put #1, intRecNum, udtEmpRec14. d Close #315. a Len(udtStudRec)16. c either read from or written to17. d strFirst = Space(10)18. e CustStruc19. c udtCustRec20. a,b,d strName, strPhone, curSalary21. c 2522. a 823. d 4524. d udtCustRec.strPhone25. c udtCustRec26. a,c Get #1, 2, udtCustRec

Get #1, intNum, udtcustRec

Exercises1. Type BookStruc

strTitle as String * 20strAuthor as String * 20curCost as Currency

End Type2. Type TapeStruc

strName as String * 25strArtist as String * 20intSong as IntegerstrLength as String * 6

End Type3. Dim udtBookRec as BookStruc4. Dim udtTapeRec as TapeStruc5. 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, udtBookRec8. Put #1, intRecNum, udtTapeRec

196

Page 205: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

9. Get #1, intRecNum, udtBookRec10. Get #1, intRecNum, udtTapeRec11. Close #1

197

Page 206: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

12. a. Dim udtCompRec as ComputerStrucb. Open “a:\tut08\Computer.dat” for Random as #1 Len = Len(udtCompRec)c. Dim intX as Integer

udtCompRec.strName = Space(5)udtCompRec.curCost = 0For intX = 1 To 10

Put #1, intX, udtCompRecNext intX

d. udtCompRec.strName = “IB-50”e. udtCompRec.curCost = 2400f. Put #1, intRecNum, udtCompRecg. Get #1, intRecNum, udtCompRech. lblName.Caption = udtCompRec.strName

lblCost.Caption = udtCompRec.curCosti. Close #1

13. a. Dim udtFriendRec as FriendStrucb. 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, udtFriendRecNext intX

d. udtFriendRec.strFirst = txtFirst.Texte. udtFriendRec.strLast = txtLast.Textf. Put #1, intRecNum, udtFriendRecg. Get #1, intRecNum, udtFriendRech. lblName.Caption = udtFriendRec.strFirst & “ “ & udtFriendRec.strLastj. Close #1

14. a. Type CustStrucstrName as String * 25strPhone as String * 8curSales as Currency

End Typeb. Dim udtCustRec as CustStrucc. 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 = 0For intX = 1 To 5

Put #1, intX, udtCustRecNext intX

e. udtCustRec.strName = txtName.Textf. udtCustRec.strPhone = txtPhone.Textg. udtCustRec.curSales = Val(txtSales.Text)h. Put #1, intRecNum, udtCustReci. Get #1, intRecNum, udtCustReck. txtName.Text = udtCustRec.strNamel. txtPhone.Text = udtCustRec.strPhone

198

Page 207: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

m. txtSales.Text = udtCustRec.curSalesn. Close #1

199

Page 208: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 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.

la15Done.basOption ExplicitType CDStruc strName As String * 20 strArtist As String * 20End Type

la15Done.frmOption 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.SetFocusEnd 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.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmCd

200

Page 209: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

201

Page 210: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.SetFocusEnd Sub

Private Sub Form_Load() frmCd.Top = (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 #1End 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

202

Page 211: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 8, Lesson BQuestions1. e startup2. c Project3. b Call DoubleNumber(intNumber)4. c passing5. b receiving6. a Call PrintHeading7. e Private Sub DisplayName(strFriendName as String)8. e Private Sub UpdateAge(strFriendName as String, intAge as Integer)9. c Object Browser10. 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 value12. c by reference13. d by value14. c by reference15. c by reference

Exercises1. 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 = intNumberEnd Sub

Private Sub cmdExit_Click() Unload frmLb1End Sub

Private Sub DoubleNumber(intNum As Integer) intNum = intNum * 2 lblNum.Caption = intNumEnd Sub

Private Sub Form_Load() frmLb1.Top = (Screen.Height - frmLb1.Height) / 2 frmLb1.Left = (Screen.Width - frmLb1.Width) / 2End 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.

203

Page 212: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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

Printout #3:

Student List

Name Grade Paul Penny C Mark Place B Janice Jones F

End of report

204

Page 213: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lb2Done.basOption ExplicitType StudStruc strName As String * 20 strGrade As String * 1End Type

lb2Done.frmOption 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 <= 4 And strChecked = "N" 'determine if any check box If chkDone(intCount).Value = vbChecked Then 'is selected strChecked = "Y" End If intCount = intCount + 1 Loop If strChecked = "N" Then 'if no check box is cmdDisplay.Enabled = False 'selected, disable the End If 'Display Grade button End If 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

Private Sub txtScore_Change(Index As Integer) lblGrade.Caption = "" End Sub

Private Sub txtScore_GotFocus(Index As Integer) txtScore(Index).SelStart = 0 txtScore(Index).SelLength = Len(txtScore(Index).Text) End Sub

205

Page 214: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdDisplay_Click() Dim intEarned As Integer, intPossible As Integer Dim sngRatio As Single, intCount As Integer Dim StudRec As StudStruc, intX As Integer For intCount = 0 To 4 If chkDone(intCount).Value = vbChecked Then intEarned = intEarned + Val(txtScore(intCount).Text) Select Case intCount Case 0 To 2 intPossible = intPossible + 10 Case Else intPossible = intPossible + 50 End Select End If Next intCount sngRatio = intEarned / intPossible Select Case sngRatio Case Is >= 0.9 lblGrade.Caption = "A" Case Is >= 0.8 lblGrade.Caption = "B" Case Is >= 0.7 lblGrade.Caption = "C" Case Is >= 0.6 lblGrade.Caption = "D" Case Else lblGrade.Caption = "F" End Select 'write information to random access file intX = Val(txtNumber.Text) StudRec.strName = txtName.Text StudRec.strGrade = lblGrade.Caption Put #1, intX, StudRec txtNumber.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmGradeEnd Sub

206

Page 215: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdPrint_Click() Dim StudRec As StudStruc, intUser As Integer, intX As Integer Dim strFont As String, sngSize As Single Const conBtns As Integer = _ vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal intUser = MsgBox("Print the student list?", conBtns, "Print") If intUser = vbNo Then PrintForm Else strFont = Printer.Font sngSize = Printer.FontSize Printer.Font = "courier new" Printer.FontSize = 10 Printer.Print Tab(5); "Student List" Printer.Print Printer.Print Tab(5); "Name"; Tab(30); "Grade" For intX = 1 To 10 Get #1, intX, StudRec If StudRec.strName <> Space(20) Then Printer.Print Tab(5); StudRec.strName; Tab(30); StudRec.strGrade End If Next intX Printer.Print 'print two blank lines Printer.Print Printer.Print Tab(5); "End of report" 'print message Printer.EndDoc Printer.Font = strFont Printer.FontSize = sngSize End IfEnd Sub

Private Sub Form_Load() Dim StudRec As StudStruc, intX As Integer, intUser As Integer Const conBtns As Integer = _ vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal frmGrade.Top = (Screen.Height - frmGrade.Height) / 2 frmGrade.Left = (Screen.Width - frmGrade.Width) / 2 StudRec.strName = Space(20) StudRec.strGrade = Space(1) Open "a:\tut08\grades.dat" For Random As #1 Len = Len(StudRec) intUser = MsgBox("Initialize file?", conBtns, "Initialize") If intUser = vbYes Then For intX = 1 To 10 Put #1, intX, StudRec Next intX End IfEnd Sub

Private Sub Form_Unload(Cancel As Integer) Const conBtns As Integer = vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal Dim intUserResponse As Integer intUserResponse = MsgBox("Do you want to exit?", conBtns, "Grade Application") If intUserResponse = vbNo Then 'user does not want to quit the application Cancel = 1 'prevent form from being unloaded Else Close #1 End If

207

Page 216: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

208

Page 217: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3. (Discovery) lb3Done project – The student should submit two printouts of the report and a printout of the code. Changes made to the original code are shaded.

Printout #1: PAO Information – 1999

Party 18-35 36-50 51-65 Over 65 TotalDemocrat 1 1 2Republican 3 3Independent 1 1

Total respondents 6

End of report

Printout #2: PAO Information – 1999

Party 18-35 36-50 51-65 Over 65 TotalDemocrat 1 1Republican 2 2Independent 1 1

Total respondents 4

End of report

lb3Done.basOption ExplicitType VoterStruc strParty As String * 11 intAge As IntegerEnd Type

209

Page 218: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lb3Done.frmOption Explicit

Private Sub cmdDisplay_Click() Dim VoterRec As VoterStruc, intCount As Integer, intX As Integer For intCount = 0 To 3 'clear the label controls lblDem(intCount).Caption = "" lblRep(intCount).Caption = "" lblInd(intCount).Caption = "" Next intCount intX = 1 Get #1, intX, VoterRec Do While Not EOF(1) Select Case Trim(VoterRec.strParty) 'update appropriate label control Case "Democrat" lblDem(VoterRec.intAge).Caption = Val(lblDem(VoterRec.intAge).Caption) + 1 Case "Republican" lblRep(VoterRec.intAge).Caption = Val(lblRep(VoterRec.intAge).Caption) + 1 Case "Independent" lblInd(VoterRec.intAge).Caption = Val(lblInd(VoterRec.intAge).Caption) + 1 End Select intX = intX + 1 Get #1, intX, VoterRec LoopEnd Sub

Private Sub cmdEnter_Click() Dim VoterRec As VoterStruc, intX As Integer intX = Val(txtNumber.Text) VoterRec.strParty = lstParty.Text VoterRec.intAge = lstAge.ListIndex Put #1, intX, VoterRec 'write the record txtNumber.SelStart = 0 txtNumber.SelLength = Len(txtNumber.Text) txtNumber.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmPaoEnd Sub

210

Page 219: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = sngSizeEnd Sub

211

Page 220: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdRemove_Click() Dim VoterRec As VoterStruc, intX As Integer, intUser As Integer Const conBtns As Integer = _ vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal intX = Val(txtNumber.Text) VoterRec.strParty = Space(11) VoterRec.intAge = 0 Put #1, intX, VoterRec 'remove the record intUser = MsgBox("Record number " & intX & " was removed.", conBtns, "Remove") txtNumber.SelStart = 0 txtNumber.SelLength = Len(txtNumber.Text) txtNumber.SetFocusEnd Sub

Private Sub Form_Load() Dim VoterRec As VoterStruc, intX As Integer, intUser As Integer Const conBtns As Integer = _ vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal frmPao.Top = (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 VoterRec.strParty = Space(11) VoterRec.intAge = 0 Open "a:\tut08\pao.dat" For Random As #1 Len = Len(VoterRec) intUser = MsgBox("Initialize file?", conBtns, "Initialize") If intUser = vbYes Then For intX = 1 To 20 Put #1, intX, VoterRec Next intX End IfEnd Sub

Private Sub Form_Unload(Cancel As Integer) Close #1End Sub

Private Sub txtNumber_GotFocus() txtNumber.SelStart = 0 txtNumber.SelLength = Len(txtNumber.Text)End Sub

212

Page 221: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. (Discovery) lb4Done project – The student should submit a printout of the application’s code.

Option Explicit

Private Sub Command1_Click() Dim sngPrice As Single sngPrice = Val(Text1.Text) Label1.Caption = CalcNewPrice(sngPrice)End Sub

Private Function CalcNewPrice(sngOldPrice As Single) As Single CalcNewPrice = sngOldPrice * 1.1End Function

Private Function Cube(intNum As Integer) As Single Cube = intNum ^ 3End Function

Private Sub Command2_Click() Dim intNumber As Integer intNumber = Val(Text1.Text) Label1.Caption = Cube(intNumber)End Sub

Tutorial 8, Lesson CQuestions1. d txtPhone.Text2. b frmNumbers.txtPhone.Text3. d Show4. d Hide5. c Trim

Exercises1. lc1Done project – The student should submit a printout of the code.

lc1Desk.frmOption Explicit

Private Sub Form_Unload(Cancel As Integer) Unload frmStudentEnd Sub

Private Sub lblDesk_Click(Index As Integer) Dim intDesk As Integer, udtStudRec As StudStruc intDesk = Index + 1 frmStudent.lblNum.Caption = intDesk If lblDesk(Index).BackColor = vbYellow Then Get #1, intDesk, udtStudRec frmStudent.txtName.Text = Trim(udtStudRec.strName) frmStudent.txtGrade.Text = Trim(udtStudRec.strGrade) Else frmStudent.txtName.text = "" frmStudent.txtGrade.text = "" End If frmStudent.Show

213

Page 222: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

frmStudent.txtName.SetFocusEnd Sub

Private Sub mnuFileExit_Click() Unload frmDeskEnd Sub

Private Sub mnuFileNew_Click() On Error GoTo NewErrHandler dlgDesk.CancelError = True dlgDesk.Flags = cdlOFNOverwritePrompt dlgDesk.Filter = "Data (*.dat)|*.dat" dlgDesk.ShowSave Call Initialize(dlgDesk.FileName) Exit Sub NewErrHandler:End Sub

Private Sub Initialize(strFileName As String) Dim intDesk As Integer, udtStudRec As StudStruc udtStudRec.strName = Space(20) udtStudRec.strGrade = Space(1) Close #1 Open strFileName For Random As #1 Len = Len(udtStudRec) For intDesk = 0 To 19 Put #1, intDesk + 1, udtStudRec lblDesk(intDesk).BackColor = vbWhite lblDesk(intDesk).Visible = True Next intDesk frmDesk.Caption = strFileName & " - Mr. Fletcher's Class"End Sub

214

Page 223: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub mnuFileOpen_Click() Dim intDesk As Integer, udtStudRec As StudStruc On Error GoTo OpenErrHandler dlgDesk.CancelError = True dlgDesk.Flags = cdlOFNFileMustExist dlgDesk.Filter = "Data (*.dat)|*.dat" dlgDesk.FileName = "" dlgDesk.ShowOpen Close #1 Open dlgDesk.FileName For Random As #1 Len = Len(udtStudRec) frmDesk.Caption = dlgDesk.FileName & " - Mr. Fletcher's Class" For intDesk = 0 To 19 lblDesk(intDesk).Visible = True Get #1, intDesk + 1, udtStudRec If udtStudRec.strName <> Space(20) Then lblDesk(intDesk).BackColor = vbYellow Else lblDesk(intDesk).BackColor = vbWhite End If Next intDesk Exit Sub OpenErrHandler:End Sub

lc1Stud.frmOption Explicit

Private Sub cmdEnter_Click() Dim intDesk As Integer, udtStudRec As StudStruc intDesk = lblNum.Caption udtStudRec.strName = txtName.Text udtStudRec.strGrade = txtGrade.Text Put #1, intDesk, udtStudRec frmDesk.lblDesk(intDesk - 1).BackColor = vbYellow frmStudent.HideEnd Sub

Private Sub cmdRemove_Click() Dim intDesk As Integer, udtStudRec As StudStruc intDesk = lblNum.Caption udtStudRec.strName = Space(20) udtStudRec.strGrade = Space(1) Put #1, intDesk, udtStudRec frmDesk.lblDesk(intDesk - 1).BackColor = vbWhite frmStudent.HideEnd Sub

Private Sub cmdReturn_Click() frmStudent.HideEnd Sub

215

Page 224: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub Form_Load() frmStudent.Top = (Screen.Height - frmStudent.Height) / 2 frmStudent.Left = (Screen.Width - frmStudent.Width) / 2End Sub

Private Sub txtGrade_GotFocus() txtGrade.SelStart = 0 txtGrade.SelLength = Len(txtGrade.Text)End Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

lc1Done.basOption ExplicitType StudStruc strName As String * 20 strGrade As String * 1End Type

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

lc2Banq.frmOption Explicit

Private Sub Form_Unload(Cancel As Integer) Unload frmGuestEnd Sub

Private Sub imgSeat_Click(Index As Integer) Dim intSeat As Integer, udtGuestRec As GuestStruc intSeat = Index + 1 frmGuest.lblNum.Caption = intSeat If imgSeat(Index).Picture <> 0 Then Get #1, intSeat, udtGuestRec frmGuest.txtName.Text = Trim(udtGuestRec.strName) frmGuest.lstMeal.ListIndex = udtGuestRec.intMeal Else frmGuest.txtName.Text = "" frmGuest.lstMeal.ListIndex = 1 End If frmGuest.Show frmGuest.txtName.SetFocusEnd Sub

Private Sub mnuFileExit_Click() Unload frmBanquetEnd Sub

216

Page 225: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub mnuFileNew_Click() On Error GoTo NewErrHandler dlgSeat.CancelError = True dlgSeat.Flags = cdlOFNOverwritePrompt dlgSeat.Filter = "Data (*.dat)|*.dat" dlgSeat.ShowSave Call Initialize(dlgSeat.FileName) Exit Sub NewErrHandler:End Sub

Private Sub Initialize(strFileName As String) Dim intSeat As Integer, udtGuestRec As GuestStruc udtGuestRec.strName = Space(20) udtGuestRec.intMeal = 0 Close #1 Open strFileName For Random As #1 Len = Len(udtGuestRec) For intSeat = 0 To 39 Put #1, intSeat + 1, udtGuestRec imgSeat(intSeat).Picture = LoadPicture() Next intSeat Frame1.Visible = True Frame2.Visible = True frmBanquet.Caption = strFileName & " - Seating Chart"End Sub

Private Sub mnuFileOpen_Click() Dim intSeat As Integer, udtGuestRec As GuestStruc On Error GoTo OpenErrHandler dlgSeat.CancelError = True dlgSeat.Flags = cdlOFNFileMustExist dlgSeat.Filter = "Data (*.dat)|*.dat" dlgSeat.FileName = "" dlgSeat.ShowOpen Close #1 Open dlgSeat.FileName For Random As #1 Len = Len(udtGuestRec) frmBanquet.Caption = dlgSeat.FileName & " - Seating Chart" For intSeat = 0 To 39 Get #1, intSeat + 1, udtGuestRec If udtGuestRec.strName <> Space(20) Then imgSeat(intSeat).Picture = imgSmile.Picture Else imgSeat(intSeat).Picture = LoadPicture() End If Next intSeat Frame1.Visible = True Frame2.Visible = True Exit Sub OpenErrHandler:End Sub

217

Page 226: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lc2Guest.frmOption Explicit

Private Sub cmdDelete_Click() Dim intSeat As Integer, udtGuestRec As GuestStruc intSeat = lblNum.Caption udtGuestRec.strName = Space(20) udtGuestRec.intMeal = 0 Put #1, intSeat, udtGuestRec frmBanquet.imgSeat(intSeat - 1).Picture = LoadPicture() frmGuest.HideEnd Sub

Private Sub cmdEnter_Click() Dim intSeat As Integer, udtGuestRec As GuestStruc intSeat = lblNum.Caption udtGuestRec.strName = txtName.Text udtGuestRec.intMeal = lstMeal.ListIndex Put #1, intSeat, udtGuestRec frmBanquet.imgSeat(intSeat - 1).Picture = frmBanquet.imgSmile.Picture frmGuest.HideEnd Sub

Private Sub cmdReturn_Click() frmGuest.HideEnd Sub

Private Sub Form_Load() frmGuest.Top = (Screen.Height - frmGuest.Height) / 2 frmGuest.Left = (Screen.Width - frmGuest.Width) / 2 lstMeal.AddItem "Steak" lstMeal.AddItem "Fish" lstMeal.AddItem "Vegetarian" lstMeal.ListIndex = 1End Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

lc2Done.basOption ExplicitType GuestStruc strName As String * 20 intMeal As IntegerEnd Type

218

Page 227: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3. lc3Done project – The student should submit a printout of the code.lc3Desk.frmOption Explicit

Private Sub Form_Unload(Cancel As Integer) Unload frmStudentEnd Sub

Private Sub lblDesk_Click(Index As Integer) Dim intDesk As Integer, udtStudRec As StudStruc intDesk = Index + 1 frmStudent.lblNum.Caption = intDesk If lblDesk(Index).BackColor <> vbWhite Then Get #1, intDesk, udtStudRec frmStudent.txtName.Text = Trim(udtStudRec.strName) frmStudent.txtGrade.Text = Trim(udtStudRec.strGrade) Else frmStudent.txtName.Text = "" frmStudent.txtGrade.Text = "" End If frmStudent.Show frmStudent.txtName.SetFocusEnd Sub

Private Sub mnuFileExit_Click() Unload frmdeskEnd Sub

Private Sub mnuFileNew_Click() On Error GoTo NewErrHandler dlgDesk.CancelError = True dlgDesk.Flags = cdlOFNOverwritePrompt dlgDesk.Filter = "Data (*.dat)|*.dat" dlgDesk.ShowSave Call Initialize(dlgDesk.FileName) Exit Sub NewErrHandler:End Sub

Private Sub Initialize(strFileName As String) Dim intDesk As Integer, udtStudRec As StudStruc udtStudRec.strName = Space(20) udtStudRec.strGrade = Space(1) Close #1 Open strFileName For Random As #1 Len = Len(udtStudRec) For intDesk = 0 To 19 Put #1, intDesk + 1, udtStudRec lblDesk(intDesk).BackColor = vbWhite lblDesk(intDesk).Visible = True Next intDesk frmdesk.Caption = strFileName & " - Mr. Fletcher's Class"End Sub

219

Page 228: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub mnuFileOpen_Click() Dim intDesk As Integer, udtStudRec As StudStruc On Error GoTo OpenErrHandler dlgDesk.CancelError = True dlgDesk.Flags = cdlOFNFileMustExist dlgDesk.Filter = "Data (*.dat)|*.dat" dlgDesk.FileName = "" dlgDesk.ShowOpen Close #1 Open dlgDesk.FileName For Random As #1 Len = Len(udtStudRec) frmdesk.Caption = dlgDesk.FileName & " - Mr. Fletcher's Class" For intDesk = 0 To 19 lblDesk(intDesk).Visible = True Get #1, intDesk + 1, udtStudRec If udtStudRec.strName <> Space(20) Then Call AssignColor(udtStudRec, intDesk) lblDesk(intDesk).Caption = lblDesk(intDesk).Caption & " - " & udtStudRec.strGrade Else lblDesk(intDesk).BackColor = vbWhite End If Next intDesk Exit Sub OpenErrHandler:End Sub

lc3Stud.frmOption Explicit

Private Sub cmdEnter_Click() Dim intDesk As Integer, udtStudRec As StudStruc intDesk = lblNum.Caption udtStudRec.strName = txtName.Text udtStudRec.strGrade = txtGrade.Text Put #1, intDesk, udtStudRec Call AssignColor(udtStudRec, intDesk - 1) frmdesk.lblDesk(intDesk - 1).Caption = frmdesk.lblDesk(intDesk - 1).Caption & " - " _ & udtStudRec.strGrade frmStudent.HideEnd Sub

Private Sub cmdRemove_Click() Dim intDesk As Integer, udtStudRec As StudStruc intDesk = lblNum.Caption udtStudRec.strName = Space(20) udtStudRec.strGrade = Space(1) Put #1, intDesk, udtStudRec frmdesk.lblDesk(intDesk - 1).BackColor = vbWhite frmdesk.lblDesk(intDesk - 1).Caption = intDesk frmStudent.HideEnd Sub

Private Sub cmdReturn_Click() frmStudent.HideEnd Sub

220

Page 229: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub Form_Load() frmStudent.Top = (Screen.Height - frmStudent.Height) / 2 frmStudent.Left = (Screen.Width - frmStudent.Width) / 2End Sub

Private Sub txtGrade_GotFocus() txtGrade.SelStart = 0 txtGrade.SelLength = Len(txtGrade.Text)End Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

lc3Done.basOption ExplicitType StudStruc strName As String * 20 strGrade As String * 1End Type

Public Sub AssignColor(udtStudent As StudStruc, intDesk As Integer) Select Case UCase(udtStudent.strGrade) Case "A" frmdesk.lblDesk(intDesk).BackColor = vbMagenta Case "B" frmdesk.lblDesk(intDesk).BackColor = vbRed Case "C" frmdesk.lblDesk(intDesk).BackColor = vbYellow Case "D" frmdesk.lblDesk(intDesk).BackColor = vbGreen Case Else frmdesk.lblDesk(intDesk).BackColor = vbBlue End SelectEnd Sub

221

Page 230: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. (Discovery) lc4Done project – The student should submit the code for the frmPatron form only. The student is instructed to save the forms as lcPatron and lcSeat, and the project as lcCole. The student will need to set the cmdEnter button’s Enabled property to False in the Properties window. Changes to the original code are shaded.

Option Explicit

Private Sub cmdCancel_Click() Dim intSeat As Integer, udtPatronRec As PatronStruc intSeat = lblNum.Caption udtPatronRec.strName = Space(20) udtPatronRec.strPhone = Space(8) Put #1, intSeat, udtPatronRec frmSeat.lblSeat(intSeat - 1).BackColor = vbWhite frmPatron.Hide End Sub

Private Sub cmdEnter_Click() Dim intSeat As Integer, udtPatronRec As PatronStruc intSeat = lblNum.Caption udtPatronRec.strName = txtName.Text udtPatronRec.strPhone = txtPhone.Text Put #1, intSeat, udtPatronRec frmSeat.lblSeat(intSeat - 1).BackColor = vbRed frmPatron.Hide End Sub

Private Sub cmdReturn_Click() frmPatron.Hide End Sub

Private Sub Form_Load() frmPatron.Top = (Screen.Height - frmPatron.Height) / 2 frmPatron.Left = (Screen.Width - frmPatron.Width) / 2End Sub

Private Sub txtName_Change() If Trim(txtName.Text) = "" Then cmdEnter.Enabled = False Else cmdEnter.Enabled = True End IfEnd Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

Private Sub txtPhone_GotFocus() txtPhone.SelStart = 0 txtPhone.SelLength = Len(txtPhone.Text)End Sub

222

Page 231: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

5. (Discovery) The student should submit a user’s manual for the Cole Playhouse application. Below is a suggested user’s manual. The student’s manual should have a title page and a table of contents.

Cole’s Playhouse User Manual Page 1

I. Your first step in using the Cole’s Playhouse application is to either create a new file or open an existing file.

To create a new file:1. Click File on the menu bar, then click New.2. When the Open dialog box appears, enter the file name in the File name box. Select

the appropriate drive and folder, then click the OK button.3. If the file already exists, a dialog box will appear asking if you want to replace the

existing file.4. If you want to replace the existing file, click the Yes button. The seating chart will

appear. If you do not want to replace the existing file, click the No button. You then will need to use the File menu to either create a new file or open an existing file.

To open an existing file:1. Click File on the menu bar, then click Open.2. When the Open dialog box appears, enter the file name in the File name box. Select

the appropriate drive and folder, then click the OK button. The seating chart will appear.

II. After creating a new file or opening an existing file, you then can use the seating chart to reserve a seat, edit the patron information, or cancel a reservation.

To reserve a seat:1. Click the seat number corresponding to the seat to be reserved. A screen in which ou

can enter the patron’s name and phone number appears.2. Enter the patron’s name and phone number.3. Click the Enter Ticket button to enter the patron information, or click the Return to

Main button to return to the Cole’s Playhouse seating chart without entering the patron information. The Cole’s Playhouse seating chart appears.

To edit the patron information:1. Click the seat number corresponding to the seat whose patron information you want

to edit. A screen appears showing the patron’s current information.2. Edit the patron’s information.3. Click the Enter Ticket button to enter the edited patron information, or click the

Return to Main button to return to the Cole’s Playhouse seating chart without entering the edited patron information. The Cole’s Playhouse seating chart appears.

To cancel a reservation:1. Click the seat number corresponding to the reservation to be canceled. A screen

appears showing the patron’s information.2. Click the Cancel Ticket button to cancel the reservation, or click the Return to Main

button to return to the Cole’s Playhouse seating chart without canceling the reservation. The Cole’s Playhouse seating chart appears.

To exit the Cole’s Playhouse application:1. Click File on the menu bar, then click Exit. The Cole’s Playhouse application ends.

223

Page 232: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

6. (Discovery) lc6Done project – The student should submit two printouts of the price list, a printout of the user interface, and a printout of the code.

step d: original price listShirts Outlet Price List

Item Manufacturer Price444C Cody 15.75111A Adams 16.00222A Adams 24.30333D Dawn 21.56666D Dawn 34.57888A Adams 20.00777D Dawn 21.50555C Cody 45.00123C Cody 34.78345A Adams 10.00

End of report

step f: updated price listShirts Outlet Price List

Item Manufacturer Price444C Cody 15.75111A Adams 17.60222A Adams 26.73333D Dawn 21.56666D Dawn 34.57888A Adams 22.00777D Dawn 21.50555C Cody 45.00123C Cody 34.78345A Adams 11.00

End of report

lc6Done.basOption ExplicitType ItemStruc strNum As String * 4 sngPrice As SingleEnd Type

224

Page 233: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lc6Done.frmOption Explicit

Private Sub cmdExit_Click() Unload frmShirtsEnd Sub

Private Sub cmdPrint_Click() Dim ItemRec As ItemStruc, intX As Integer, strManuf As String Dim strPS1 As String * 5, strFont As String, sngSize As Single strFont = Printer.Font sngSize = Printer.FontSize Printer.Font = "courier new" Printer.FontSize = 10 intX = 1 Open "a:\tut08\lc6Done.dat" For Random As #1 Len = Len(ItemRec) Printer.Print Tab(10); "Shirts Outlet Price List" Printer.Print Printer.Print Tab(10); "Item"; Tab(20); "Manufacturer"; Tab(35); "Price" Get #1, intX, ItemRec Do While Not EOF(1) Select Case UCase(Right(ItemRec.strNum, 1)) Case "A" strManuf = "Adams" Case "C" strManuf = "Cody" Case "D" strManuf = "Dawn" Case Else strManuf = "?" End Select 'align price RSet strPS1 = Format(ItemRec.sngPrice, "standard") Printer.Print Tab(10); ItemRec.strNum; Tab(20); strManuf; Tab(35); strPS1 intX = intX + 1 Get #1, intX, ItemRec Loop Close #1 Printer.Print 'print two blank lines Printer.Print Printer.Print Tab(10); "End of report" 'print message Printer.EndDoc Printer.Font = strFont Printer.FontSize = sngSizeEnd Sub

225

Page 234: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdUpdate_Click() Dim ItemRec As ItemStruc, intX As Integer Dim sngIncrease As Single, strManuf As String sngIncrease = Val(Trim(txtIncrease.Text)) strManuf = UCase(Trim(txtManuf.Text)) intX = 1 Open "a:\tut08\lc6Done.dat" For Random As #1 Len = Len(ItemRec) Get #1, intX, ItemRec Do While Not EOF(1) If UCase(Right(ItemRec.strNum, 1)) = strManuf Then ItemRec.sngPrice = ItemRec.sngPrice * (1 + sngIncrease) Put #1, intX, ItemRec End If intX = intX + 1 Get #1, intX, ItemRec Loop Close #1End Sub

Private Sub Form_Load() frmShirts.Left = (Screen.Width - frmShirts.Width) / 2 frmShirts.Top = (Screen.Height - frmShirts.Height) / 2End Sub

Private Sub Form_Unload(Cancel As Integer) Close #1End Sub

Private Sub txtIncrease_Change() If Trim(txtIncrease.Text) = "" Then cmdUpdate.Enabled = False Else cmdUpdate.Enabled = True End IfEnd Sub

226

Page 235: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 8 – Debugging

TechniqueWhile you are testing an application with both valid and invalid data, it helps to include Visual Basic’s MsgBox statement in the application’s error handlers. The MsgBox statement will allow you to observe the types of errors that can occur in the various procedures; you need to know this information to code the error handlers appropriately. The MsgBox statement is similar to the MsgBox function; however, unlike the MsgBox function, the MsgBox statement does not return a value. The syntax of the MsgBox statement is MsgBox prompt, where prompt is the message you want displayed in the dialog box. If you use the Err object’s Description property as the prompt, the MsgBox statement will display a message indicating the error that occurred in the procedure.

Exercises1. The student is not instructed to submit anything for this exercise. 2. The student should submit two printouts of the code. Changes made to the original code are

shaded. On the printout from step a, the student should record the error message that appears in step c. The error message is “Bad record number”.

step a: original codedebug2.frm

Option Explicit

Private Sub cmdDisplay_Click() Dim intNumRec As Integer, udtItemRec As ItemStruc intNumRec = Val(txtNum.Text) If intNumRec > 0 And intNumRec < 11 Then Get #1, intNumRec, udtItemRec End If txtItem.Text = udtItemRec.strName txtPrice.Text = udtItemRec.sngPrice txtNum.SetFocusEnd Sub

Private Sub cmdEnter_Click() Dim intNumRec As Integer, udtItemRec As ItemStruc intNumRec = Val(txtNum.Text) udtItemRec.strName = txtItem.Text udtItemRec.sngPrice = Val(txtPrice.Text) If intNumRec > 0 And intNumRec < 11 Then Put #1, intNumRec, udtItemRec End If txtNum.SetFocusEnd Sub

Private Sub Form_Load() frmItem.Left = (Screen.Width - frmItem.Width) / 2 frmItem.Top = (Screen.Height - frmItem.Height) / 2End Sub

step c: debugged codedebug2.frm

Option Explicit

Private Sub cmdDisplay_Click() Dim intNumRec As Integer, udtItemRec As ItemStruc intNumRec = Val(txtNum.Text) If intNumRec > 0 And intNumRec < 11 Then Get #1, intNumRec, udtItemRec End If txtItem.Text = udtItemRec.strName txtPrice.Text = udtItemRec.sngPrice txtNum.SetFocusEnd Sub

Private Sub cmdEnter_Click() Dim intNumRec As Integer, udtItemRec As ItemStruc intNumRec = Val(txtNum.Text) udtItemRec.strName = txtItem.Text udtItemRec.sngPrice = Val(txtPrice.Text) If intNumRec > 0 And intNumRec < 11 Then Put #1, intNumRec, udtItemRec End If txtNum.SetFocusEnd Sub

Private Sub Form_Load() frmItem.Left = (Screen.Width - frmItem.Width) / 2 frmItem.Top = (Screen.Height - frmItem.Height) / 2

227

Page 236: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub

Private Sub Form_Unload(Cancel As Integer) Close #1End Sub

Private Sub mnuFileExit_Click() Unload frmItemEnd Sub

Private Sub mnuFileNew_Click() On Error GoTo NewErrHandler dlgItem.CancelError = True dlgItem.Flags = cdlOFNOverwritePrompt dlgItem.Filter = "Data (*.dat) | *.dat" dlgItem.ShowSave Call Initialize(dlgItem.FileName) cmdEnter.Enabled = True cmdDisplay.Enabled = True Exit Sub NewErrHandler:End Sub

Private Sub mnuFileOpen_Click() Dim intRecNum As Integer, udtItemRec As ItemStruc On Error GoTo OpenErrHandler dlgItem.CancelError = True dlgItem.Flags = cdlOFNFileMustExist dlgItem.Filter = "Data (*.dat) | *.dat" dlgItem.FileName = "" dlgItem.ShowOpen Close #1 Open dlgItem.FileName For Random As #1 Len = Len(udtItemRec) frmItem.Caption = dlgItem.FileName & " - Item Information" cmdEnter.Enabled = True cmdDisplay.Enabled = True Exit Sub OpenErrHandler:End Sub

Private Sub txtItem_GotFocus() txtItem.SelStart = 0 txtItem.SelLength = Len(txtItem.Text)End Sub

Private Sub txtNum_Change() txtItem.Text = "" txtPrice.Text = ""End Sub

Private Sub txtNum_GotFocus() txtNum.SelStart = 0 txtNum.SelLength = Len(txtNum.Text)

Private Sub Form_Unload(Cancel As Integer) Close #1End Sub

Private Sub mnuFileExit_Click() Unload frmItemEnd Sub

Private Sub mnuFileNew_Click() On Error GoTo NewErrHandler dlgItem.CancelError = True dlgItem.Flags = cdlOFNOverwritePrompt dlgItem.Filter = "Data (*.dat) | *.dat" dlgItem.ShowSave Call Initialize(dlgItem.FileName) cmdEnter.Enabled = True cmdDisplay.Enabled = True Exit Sub NewErrHandler:End Sub

Private Sub mnuFileOpen_Click() Dim intRecNum As Integer, udtItemRec As ItemStruc On Error GoTo OpenErrHandler dlgItem.CancelError = True dlgItem.Flags = cdlOFNFileMustExist dlgItem.Filter = "Data (*.dat) | *.dat" dlgItem.FileName = "" dlgItem.ShowOpen Close #1 Open dlgItem.FileName For Random As #1 Len = Len(udtItemRec) frmItem.Caption = dlgItem.FileName & " - Item Information" cmdEnter.Enabled = True cmdDisplay.Enabled = True Exit Sub OpenErrHandler:End Sub

Private Sub txtItem_GotFocus() txtItem.SelStart = 0 txtItem.SelLength = Len(txtItem.Text)End Sub

Private Sub txtNum_Change() txtItem.Text = "" txtPrice.Text = ""End Sub

Private Sub txtNum_GotFocus() txtNum.SelStart = 0 txtNum.SelLength = Len(txtNum.Text)

228

Page 237: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub End Sub

Private Sub txtPrice_GotFocus() txtPrice.SelStart = 0 txtPrice.SelLength = Len(txtPrice.Text)End Sub

Private Sub Initialize(strFileName As String) Dim intRecNum As Integer, udtItemRec As ItemStruc On Error GoTo InitErrHandler udtItemRec.strName = Space(20) 'initialize field variables udtItemRec.sngPrice = 0 Close #1 Open strFileName For Random As #1 Len = Len(udtItemRec) For intRecNum = 0 To 9 Put #1, intRecNum, udtItemRec 'initialize each record Next intRecNum frmItem.Caption = strFileName & " - Item Information" Exit Sub InitErrHandler:End Sub

debug2.basOption ExplicitType ItemStruc strName As String * 4 sngPrice As SingleEnd Type

Private Sub txtPrice_GotFocus() txtPrice.SelStart = 0 txtPrice.SelLength = Len(txtPrice.Text)End Sub

Private Sub Initialize(strFileName As String) Dim intRecNum As Integer, udtItemRec As ItemStruc On Error GoTo InitErrHandler udtItemRec.strName = Space(20) 'initialize field variables udtItemRec.sngPrice = 0 Close #1 Open strFileName For Random As #1 Len = Len(udtItemRec) For intRecNum = 1 To 10 Put #1, intRecNum, udtItemRec 'initialize each record Next intRecNum frmItem.Caption = strFileName & " - Item Information" Exit Sub InitErrHandler:End Sub

debug2.basOption ExplicitType ItemStruc strName As String * 4 sngPrice As SingleEnd Type

229

Page 238: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 9, Lesson AQuestions1. b database2. b relational3. d table4. d All of the above are true5. c index6. a index7. b pointer8. d It takes the computer much more time to search an index than it does to search the

database table itself.9. b Data validation10. d Visual Data Manager11. a only one12. c,d Each record in a table must have an entry in the primary index.

The entries in a primary index must be unique.13. d All of the above are true14. b eng*

230

Page 239: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1. la1Done.mdb – The student should submit the following answers along with a printout of

the database structure and a disk that contains the la1Done.mdb database.

How would you locate:Fields list box

Operators list box

Value or Expression text box

the Eng101 record fldID = Eng101all courses in which you earned an A

fldGrade = A

all Intro courses fldTitle Like Intro*the Biology course fldTitle = Biologyall courses whose ID begins with cis

fldID = CIS*

Table Definition For tblCourses

Fields: (Name – Type – Size)fldID – Text – 8fldTitle – Text – 30fldCredits – Integer – 2fldGrade – Text – 1

Indexes (Name – Fields – Unique)indID-+fldID-True

2. la2Done.mdb – The student should submit a disk that contains the la2Done.mdb database.3. la3Done.mdb – The student should submit a disk that contains the la3Done.mdb database.4. (Discovery) la4Done.mdb – The student should submit a disk that contains the

la4Done.mdb database.5. (Discovery) la5Done project and la5Done.mdb – The student should submit the

application’s code and the la5Done files.Option Explicit

Private Sub cmdAdd_Click() Data1.Recordset.AddNewEnd Sub

Private Sub cmdDelete_Click() 'this may produce an error if you delete the last 'record or the only record in the recordset Data1.Recordset.Delete Data1.Recordset.MoveNextEnd Sub

Private Sub cmdRefresh_Click() 'this is really only needed for multi user apps Data1.RefreshEnd Sub

Private Sub cmdUpdate_Click() Data1.UpdateRecord

231

Page 240: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Data1.Recordset.Bookmark = Data1.Recordset.LastModifiedEnd Sub

232

Page 241: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdClose_Click() Unload MeEnd Sub

Private Sub Data1_Error(DataErr As Integer, Response As Integer) 'This is where you would put error handling code 'If you want to ignore errors, comment out the next line 'If you want to trap them, add code here to handle them MsgBox "Data error event hit err:" & Error$(DataErr) Response = 0 'throw away the errorEnd Sub

Private Sub Data1_Reposition() Screen.MousePointer = vbDefault On Error Resume Next 'This will display the current record position 'for dynasets and snapshots Data1.Caption = "Record: " & (Data1.Recordset.AbsolutePosition + 1) 'for the table object you must set the index property when 'the recordset gets created and use the following line 'Data1.Caption = "Record: " & (Data1.Recordset.RecordCount * (Data1.Recordset.PercentPosition * 0.01)) + 1End Sub

Private Sub Data1_Validate(Action As Integer, Save As Integer) 'This is where you put validation code 'This event gets called when the following actions occur Select Case Action Case vbDataActionMoveFirst Case vbDataActionMovePrevious Case vbDataActionMoveNext Case vbDataActionMoveLast Case vbDataActionAddNew Case vbDataActionUpdate Case vbDataActionDelete Case vbDataActionFind Case vbDataActionBookmark Case vbDataActionClose End Select Screen.MousePointer = vbHourglassEnd Sub

233

Page 242: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 9, Lesson BQuestions1. c data-aware2. a ADO data3. b ConnectionString4. d RecordSource5. b bound6. e DataSource, DataField7. c SQL8. b select * from tblState9. c select * from tblState where fldState = “ny”10. b select * from tblState where fldPopulation > 1000000011. e select * from tblState where fldCapital like “S%”

Exercises1. lb1Done project – The student should submit a printout of the Form as Text along with the

following answers.VERSION 5.00Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"Begin VB.Form frmCollege BackColor = &H00C0C0C0& BorderStyle = 1 'Fixed Single Caption = "College Application" ClientHeight = 3000 ClientLeft = 1170 ClientTop = 1845 ClientWidth = 7260 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 3000 ScaleWidth = 7260 Begin VB.Frame Frame1 Height = 2415 Left = 360 TabIndex = 8 Top = 240 Width = 6495 Begin VB.TextBox txtTitle DataField = "fldTitle" DataSource = "adoCourses" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 720 MaxLength = 30 TabIndex = 1

Begin VB.TextBox txtCredits DataField = "fldCredits" DataSource = "adoCourses" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4440 MaxLength = 1 TabIndex = 3 Top = 960 Width = 495 End Begin VB.TextBox txtGrade DataField = "fldGrade" DataSource = "adoCourses" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 5880 MaxLength = 1 TabIndex = 5 Top = 960 Width = 495 End

234

Page 243: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Top = 960 Width = 2895 End

Begin MSAdodcLib.Adodc adoCourses Height = 375 Left = 120 Top = 1800 Width = 6255 _ExtentX = 11033 _ExtentY = 661 ConnectMode = 0 CursorLocation = 3 IsolationLevel = -1 ConnectionTimeout= 15 CommandTimeout = 30 CursorType = 3 LockType = 3 CommandType = 1 CursorOptions = 0 CacheSize = 50 MaxRecords = 0 BOFAction = 0 EOFAction = 0 ConnectStringType= 1 Appearance = 1 BackColor = -2147483643 ForeColor = -2147483640 Orientation = 0 Enabled = -1 Connect = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=A:\Tut09\la1Done.mdb" OLEDBString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=A:\Tut09\la1Done.mdb" OLEDBFile = "" DataSourceName = "" OtherAttributes = "" UserName = "" Password = "" RecordSource = "select * from tblCourses order by fldID" Caption = "Click the arrow buttons to display the database records." BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty _Version = 393216

Begin VB.Label Label5 Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single DataField = "fldID" DataSource = "adoCourses" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 495 Left = 720 TabIndex = 7 Top = 360 Width = 1695 End Begin VB.Label Label1 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "ID:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 120 TabIndex = 6 Top = 360 Width = 240 End

235

Page 244: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End

Begin VB.Label Label2 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Title:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 120 TabIndex = 0 Top = 960 Width = 435 End Begin VB.Label Label3 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Credits:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 3720 TabIndex = 2 Top = 960 Width = 675 End

Begin VB.Label Label4 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Grade:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 5160 TabIndex = 4 Top = 960 Width = 615 End End Begin VB.Menu mnuFile Caption = "&File" Begin VB.Menu mnuFileExit Caption = "E&xit" End EndEnd

To view all the fields for Use this Select commandonly the Eng101 record select * from tblCourses where fldID =

“Eng101”only courses in which you earned an A; order the records by course ID

select * from tblCourses where fldGrade = “A” order by fldID

all Intro courses; order the records by course title

select * from tblCourses where fldTitle Like “Intro%” order by fldTitle

only the Biology course select * from tblCourses where fldTitle = “Biology”

all courses whose ID begins with cis; order the records by course ID

select * from tblCourses where fldID Like “CIS%” order by fldID

236

Page 245: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

237

Page 246: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. lb2Done project – The student should submit a printout of the Form as Text along with the following answers.

VERSION 5.00Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"Begin VB.Form frmGames BackColor = &H00C0C0C0& BorderStyle = 1 'Fixed Single Caption = "Basketball Games" ClientHeight = 3450 ClientLeft = 1170 ClientTop = 1845 ClientWidth = 7275 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 3450 ScaleWidth = 7275 Begin VB.Frame Frame1 Height = 2535 Left = 360 TabIndex = 8 Top = 240 Width = 6495 Begin VB.TextBox txtDate DataField = "fldDate" DataSource = "adoGames" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1200 MaxLength = 30 TabIndex = 1 Top = 360 Width = 1575 End

Begin VB.TextBox txtOppScore DataField = "fldOppScore" DataSource = "adoGames" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2160 TabIndex = 3 Top = 1080 Width = 615 End Begin VB.TextBox txtHomeScore DataField = "fldTeamScore" DataSource = "adoGames" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2160 TabIndex = 5 Top = 1680 Width = 615 End

238

Page 247: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label Label5 Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single DataField = "fldOpposing" DataSource = "adoGames" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 495 Left = 4560 TabIndex = 7 Top = 360 Width = 1335 End Begin VB.Label Label1 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Game date:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 120 TabIndex = 0 Top = 360 Width = 1050 End

Begin VB.Label Label2 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Opposing team:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 3120 TabIndex = 6 Top = 360 Width = 1425 End Begin VB.Label Label3 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Home team score:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 120 TabIndex = 4 Top = 1680 Width = 1650 End Begin VB.Label Label4 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Opposing team score:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 120 TabIndex = 2 Top = 1080 Width = 1980 End End

239

Page 248: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin MSAdodcLib.Adodc adoGames Height = 330 Left = 360 Top = 2880 Width = 6495 _ExtentX = 11456 _ExtentY = 582 ConnectMode = 0 CursorLocation = 3 IsolationLevel = -1 ConnectionTimeout= 15 CommandTimeout = 30 CursorType = 3 LockType = 3 CommandType = 1 CursorOptions = 0 CacheSize = 50 MaxRecords = 0 BOFAction = 0 EOFAction = 0 ConnectStringType= 1 Appearance = 1 BackColor = -2147483643 ForeColor = -2147483640 Orientation = 0 Enabled = -1 Connect = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=A:\Tut09\la2Done.mdb" OLEDBString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=A:\Tut09\la2Done.mdb" OLEDBFile = "" DataSourceName = "" OtherAttributes = "" UserName = "" Password = "" RecordSource = "select * from tblScores order by fldOpposing" Caption = "Click the arrow buttons to view the database records." BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty _Version = 393216 End

Begin VB.Menu mnuFile Caption = "&File" Begin VB.Menu mnuFileExit Caption = "E&xit" End EndEnd

240

Page 249: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

To view all the fields for Use this Select commandonly games in which your team scored more than 80 points; order the records by date

select * from tblScores where fldTeamScore > 80 order by fldDate

only games in which your team scored more points than the opposing team; order the records by the opposing team’s name

select * from tblScores where fldTeamScore > fldOppScore order by fldOpposing

only games played against the Hornets; order the records by date

select * from tblScores where fldOpposing = “Hornets” order by fldDate

only games played in November; order the records by date

select * from tblScores where fldDate Like “11%” order by fldDate

3. lb3Done project – The student should submit a printout of the Form as Text along with the following answers.

VERSION 5.00Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"Begin VB.Form frmPhone BackColor = &H00C0C0C0& BorderStyle = 1 'Fixed Single Caption = "Phone Bills" ClientHeight = 3180 ClientLeft = 1170 ClientTop = 1845 ClientWidth = 5805 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False PaletteMode = 1 'UseZOrder ScaleHeight = 3180 ScaleWidth = 5805 Begin MSAdodcLib.Adodc adoPhone Height = 375 Left = 360 Top = 2400 Width = 5055 _ExtentX = 8916 _ExtentY = 661 ConnectMode = 0 CursorLocation = 3 IsolationLevel = -1 ConnectionTimeout= 15 CommandTimeout = 30 CursorType = 3 LockType = 3 CommandType = 1 CursorOptions = 0 CacheSize = 50

MaxRecords = 0 BOFAction = 0 EOFAction = 0 ConnectStringType= 1 Appearance = 1 BackColor = -2147483643 ForeColor = -2147483640 Orientation = 0 Enabled = -1 Connect = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=A:\Tut09\la3Done.mdb" OLEDBString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=A:\Tut09\la3Done.mdb" OLEDBFile = "" DataSourceName = "" OtherAttributes = "" UserName = "" Password = "" RecordSource = "select * from tblPhone order by fldMonth" Caption = "Click the arrow buttons to view the database records." BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty _Version = 393216

241

Page 250: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End

Begin VB.TextBox txtBill DataField = "fldTotal" DataSource = "adoPhone" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2280 TabIndex = 1 Top = 1680 Width = 2055 End Begin VB.Frame Frame1 Height = 2655 Left = 240 TabIndex = 6 Top = 240 Width = 5295 Begin VB.Label Label3 Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single DataField = "fldMonth" DataSource = "adoPhone" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 495 Left = 1800 TabIndex = 3 Top = 600 Width = 615 End Begin VB.Label Label5 Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent BorderStyle = 1 'Fixed Single DataField = "fldYear" DataSource = "adoPhone"

BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 495 Left = 3120 TabIndex = 5 Top = 600 Width = 855 End Begin VB.Label Label1 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Month:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 1080 TabIndex = 2 Top = 600 Width = 705 End Begin VB.Label Label2 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "Year:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 2520 TabIndex = 4 Top = 600 Width = 600 End

242

Page 251: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Begin VB.Label Label4 AutoSize = -1 'True BackStyle = 0 'Transparent Caption = "&Total bill:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 240 Left = 1080 TabIndex = 0 Top = 1440 Width = 930 End End

Begin VB.Menu mnuFile Caption = "&File" Begin VB.Menu mnuFileExit Caption = "E&xit" End EndEnd

To view all the fields for Use this Select commandonly phone bills that exceed $50; order the records by the total bill field

select * from tblPhone where fldTotal > 50 order by fldTotal

only phone bills for the year 2000; order the records by the month field

select * from tblPhone where fldYear = “2000” order by fldMonth

4. (Discovery) In this exercise, the student learns how to change the ADO data control’s color and font properties. The student is not instructed to submit anything for this exercise.

5. (Discovery) The student should submit the following Select commands.b. select * from tblCourses where fldID = “CIS100” Or fldID = “Eng101” order by fldIDc. select * from tblCourses where fldGrade = “A” Or fldGrade = “B”d. select * from tblCourses where fldID = “CIS141” Or fldCredits = 5

243

Page 252: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 9, Lesson CQuestions1. c Recordset2. a Delete3. d move the record pointer to another record4. c MoveNext5. d adoPay.Recordset.AddNew6. b adoPay.Recordset.CancelUpdate7. a adoPay.Recordset.Delete8. c adoPay.Recordset.Update9. b adoPay.Recordset.MoveFirst10. c EOF11. d Refresh

Exercises1. lc1Done project – The student should submit the application’s code and the answers to the

questions from step h. Changes to the code are shaded.step h: The form’s Activate event occurs when the form is displayed initially or when the user returns to the form from another form. The Load event occurs when the form is first loaded into memory; it does not occur again unless the form is unloaded and then reloaded. The Load event occurs before the Activate event when the form is loaded into memory.

lc1Pat.frmOption Explicit

Private Sub cmdCancel_Click() Dim intIndex As Integer, intUser As Integer Const conBtns As Integer = _ vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal intUser = MsgBox("Cancel reservation?", conBtns, "Cancel") If intUser = vbYes Then intIndex = Val(lblNum.Caption) – 1 frmSeat.lblSeat(intIndex).BackColor = vbWhite adoCole.Recordset.Delete adoCole.Recordset.MoveFirst End If frmPatron.HideEnd Sub

Private Sub cmdEnter_Click() Dim intIndex As Integer intIndex = Val(lblNum.Caption) – 1 frmSeat.lblSeat(intIndex).BackColor = vbRed adoCole.Recordset.Update frmPatron.HideEnd Sub

Private Sub cmdReturn_Click() adoCole.Recordset.CancelUpdate frmPatron.Hide End Sub

Private Sub Form_Activate() txtName.SetFocusEnd Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

Private Sub txtPhone_GotFocus() txtPhone.SelStart = 0 txtPhone.SelLength = Len(txtPhone.Text)End Sub

244

Page 253: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub Form_Load() frmPatron.Left = (Screen.Width – frmPatron.Width) / 2 frmPatron.Top = (Screen.Height – frmPatron.Height) / 2End Sub

Private Sub txtName_Change() If Trim(txtName.Text) = "" Then cmdEnter.Enabled = False Else cmdEnter.Enabled = True End IfEnd Sub

lc1Seat.frmOption Explicit

Private Sub Form_Load() Dim intIndex As Integer Do While Not frmPatron.adoCole.Recordset.EOF intIndex = frmPatron.adoCole.Recordset.Fields("fldSeat") – 1 lblSeat(intIndex).BackColor = vbRed frmPatron.adoCole.Recordset.MoveNext Loop End Sub

Private Sub Form_Unload(Cancel As Integer) Unload frmPatronEnd Sub

Private Sub lblSeat_Click(Index As Integer) If lblSeat(Index).BackColor <> vbRed Then 'unreserved seat frmPatron.adoCole.Recordset.AddNew frmPatron.lblNum.Caption = Index + 1 frmPatron.cmdCancel.Enabled = False Else 'reserved seat frmPatron.adoCole.RecordSource = _ "select * from tblPatron where fldSeat = " & Index + 1 frmPatron.adoCole.Refresh frmPatron.cmdCancel.Enabled = True End If frmPatron.Show 1End Sub

Private Sub mnuFileExit_Click() Unload frmSeatEnd Sub

245

Page 254: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. lc2Done project – The student should submit the application’s code.lc2Desk.frmOption Explicit

Private Sub Form_Load() Dim intIndex As Integer Do While Not frmStudent.adoStud.Recordset.EOF intIndex = frmStudent.adoStud.Recordset.Fields("flddesk") – 1 lblDesk(intIndex).BackColor = vbYellow frmStudent.adoStud.Recordset.MoveNext LoopEnd Sub

Private Sub Form_Unload(Cancel As Integer) Unload frmStudentEnd Sub

Private Sub lblDesk_Click(Index As Integer) If lblDesk(Index).BackColor <> vbYellow Then frmStudent.adoStud.Recordset.AddNew frmStudent.lblNum.Caption = Index + 1 frmStudent.cmdRemove.Enabled = False Else frmStudent.adoStud.RecordSource = _ "select * from tblStud where fldDesk = " & Index + 1 frmStudent.adoStud.Refresh frmStudent.cmdRemove.Enabled = True End If frmStudent.Show 1End Sub

Private Sub mnuFileExit_Click() Unload frmDeskEnd Sub

lc2Stud.frmOption Explicit

Private Sub cmdEnter_Click() Dim intIndex As Integer If Trim(txtName.Text) <> "" Then intIndex = Val(lblNum.Caption) - 1 frmDesk.lblDesk(intIndex).BackColor = vbYellow adoStud.Recordset.Update Else adoStud.Recordset.CancelUpdate End If frmStudent.HideEnd Sub

Private Sub cmdRemove_Click() Dim intIndex As Integer, intUser As Integer Const conBtns As Integer = _ vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal intUser = MsgBox("Remove student?", conBtns, "Remove") If intUser = vbYes Then intIndex = Val(lblNum.Caption) - 1

Private Sub txtName_Change() If Trim(txtName.Text) <> "" Then cmdEnter.Enabled = True

Else cmdEnter.Enabled = False End IfEnd Sub

Private Sub txtName_GotFocus() txtName.SelStart = 0 txtName.SelLength = Len(txtName.Text)End Sub

246

Page 255: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

frmDesk.lblDesk(intIndex).BackColor = vbWhite adoStud.Recordset.Delete adoStud.Recordset.MoveFirst End If frmStudent.HideEnd Sub

Private Sub cmdReturn_Click() adoStud.Recordset.CancelUpdate frmStudent.HideEnd Sub

Private Sub Form_Activate() txtName.SetFocusEnd Sub

Private Sub Form_Load() frmStudent.Left = (Screen.Width – frmStudent.Width) / 2 frmStudent.Top = (Screen.Height – frmStudent.Height) / 2End Sub

Private Sub txtGrade_GotFocus() txtGrade.SelStart = 0 txtGrade.SelLength = Len(txtGrade.Text)End Sub

247

Page 256: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

3. lc3Done project – The student should submit the application’s code.lc3Banq.frmOption Explicit

Private Sub Form_Load() Dim intIndex As Integer Do While Not frmGuest.adoBanq.Recordset.EOF intIndex = frmGuest.adoBanq.Recordset.Fields("fldSeat") - 1 imgSeat(intIndex).Picture = imgSmile.Picture frmGuest.adoBanq.Recordset.MoveNext LoopEnd Sub

Private Sub Form_Unload(Cancel As Integer) Unload frmGuestEnd Sub

Private Sub imgSeat_Click(Index As Integer) If imgSeat(Index).Picture = 0 Then frmGuest.adoBanq.Recordset.AddNew Select Case Index Case 0 To 9 frmGuest.lblTable.Caption = 1 Case 10 To 19 frmGuest.lblTable.Caption = 2 Case 20 To 29 frmGuest.lblTable.Caption = 3 Case 30 To 39 frmGuest.lblTable.Caption = 4 End Select frmGuest.lblSeatNum.Caption = Index + 1 frmGuest.cmdDelete.Enabled = False Else frmGuest.adoBanq.RecordSource = _ "select * from tblBanq where fldSeat = " & Index + 1 frmGuest.adoBanq.Refresh frmGuest.cmdDelete.Enabled = True End If frmGuest.Show 1End Sub

Private Sub mnuFileExit_Click() Unload frmBanquetEnd Sub

248

Page 257: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. (Discovery) lc4Done project – The student should submit the code for the Select Records button’s Click event.

Private Sub cmdSelect_Click()'(1) Display, in last name order, only the records for secretaries. 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldJobCode = 2 order by fldLast"'(2) Display, in employee number order, only the records' for employees whose hourly pay rate is greater then $15. 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldHourlyRate > 15 order by fldEmpNum"'(3) Display, in last name order, only the records' for employees whose last name begins with the letter I. (Hint: Use' single quotes around the comparison string.) 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldLast like 'I%' order by fldLast"'(4) Display, in employee number order, only the records' for full-time employees. 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldPartFull = 'F' order by fldEmpNum"'(5) Display only employee number 109's record. 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldEmpNum = 109"'(6) Display, in employee number order, only the records' for part-time accountants. (Hint: You can use the And and Or' logical operators in a Select command.) 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldPartFull = 'P' and fldJobCode = 3 order by fldEmpNum"'(7) Display, in employee number order, only the records' for office managers and accountants. (Hint: You can use the And' and Or logical operators in a Select command.) 'adoEmploy.RecordSource = _ "select * from tblEmploy where fldJobCode = 1 or fldJobCode = 3 order by fldEmpNum"'(8) Display, in last name order, only records with a hire date of' 12/4/98. (Hint: When making a comparison involving a field defined' as a Date, you must place a # sign both before and after the search' data--for example, #12/4/98#.) adoEmploy.RecordSource = _ "select * from tblEmploy where fldHireDate = #12/4/98# order by fldLast" adoEmploy.RefreshEnd Sub

5. (Discovery) lc5Done project – The student should submit the code for the lstNum control’s Click event.

Private Sub lstNum_Click() Dim intSeat As Integer intSeat = lstNum.Text adoPatron.RecordSource = _ "select * from tblPatron where fldSeat = " & intSeat adoPatron.RefreshEnd Sub

249

Page 258: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

6. (Discovery) lc6Done project – The student should submit the code for the Return to Main button’s Click event.

Private Sub cmdReturn_Click() Const conBtns As Integer = _ vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal Dim intUser As Integer If Trim(txtName.Text) = "" Then adoCole.Recordset.CancelUpdate Else If adoCole.Recordset.EditMode = adEditInProgress Or _ adoCole.Recordset.EditMode = adEditAdd Then intUser = MsgBox("Save changes to the record?", conBtns, "Save Changes") If intUser = vbNo Then adoCole.Recordset.CancelUpdate Else Call cmdEnter_Click End If End If End If frmPatron.HideEnd Sub

7. (Discovery) lc7Done project – The student should submit the code for the File menu’s Open command.

Private Sub mnuFileOpen_Click() On Error GoTo openErrHandler Dim intIndex As Integer 'set Open dialog box properties, then show dialog box dlgCole.Flags = cdlOFNFileMustExist dlgCole.Filter = "Access (*.mdb)|*.mdb" dlgCole.CancelError = True dlgCole.ShowOpen 'set ADO control's ConnectionString and RecordSource properties frmPatron.adoCole.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source = " & dlgCole.FileName frmPatron.adoCole.RecordSource = "select * from tblPatron order by fldSeat" 'reopen database using new RecordSource frmPatron.adoCole.Refresh For intIndex = 0 To 47 'initialize seats lblSeat(intIndex).Visible = True lblSeat(intIndex).BackColor = vbWhite Next intIndex 'color reserved seats Do While Not frmPatron.adoCole.Recordset.EOF intIndex = frmPatron.adoCole.Recordset.Fields("fldSeat") – 1 lblSeat(intIndex).BackColor = vbRed frmPatron.adoCole.Recordset.MoveNext Loop

openErrHandler:End Sub

250

Page 259: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 9 – Debugging

TechniqueYou can use the Debug menu’s commands to help debug your code. The Step Into command, for example, allows you to execute the application’s code one statement at a time. You also can use the Step Into button on the Debug toolbar to access the Step Into command; or you can press the F8 key on your keyboard.

Exercises1. deb1Done project – The student is not instructed to submit anything for this exercise.2. deb2Done project – The student should submit the application’s code. A suggested

correction made to the program is shaded. The problem occurs because the program uses the Val function on formatted text.

Option Explicit

Private Sub cmdCalc_Click() Dim sngOld As Single, sngRate As Single, sngNew As Single sngOld = Val(Format(txtOldSalary.Text, "general number")) If sngOld >= 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 frmSalaryEnd Sub

Private Sub Form_Load() frmSalary.Top = (Screen.Height - frmSalary.Height) / 2 frmSalary.Left = (Screen.Width - frmSalary.Width) / 2End Sub

Private Sub txtOldSalary_GotFocus() txtOldSalary.SelStart = 0 txtOldSalary.SelLength = Len(txtOldSalary.Text)End Sub

251

Page 260: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 10, Lesson AQuestions1. a,c,e are related in some way, have the same data type, have the same name2. e subscript3. d intStock sub 24. c Variable arrays use many more variable names.5. e Dim strItem(1 To 5) as String6. a You use the Dim statement to fill an array with data.7. b Mary

252

Page 261: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 51011. a replace the 500 amount with 1200012. a 2200013. e If intX >= 1 and intX <= 5 Then14. d For intX = 1 To 5 Step 1

curSales(intX) = curSales(intX) + 100Next intX

15. b 616. e For intX = 1 To 4 Step 1

intTotal = intTotal + intNum(intX)Next intXsngAvg = intTotal / (intX –1)Print sngAvg

17. a 018. c 4.819. a 020. b 3.821. e 622. a Dim strItem(1 To 3, 1 To 4) as String23. c Print intNum(2,2)24. b For intRow = 1 To 2 Step 1

For intCol = 1 To 3 Step 1 Input #1, intNum(intRow, intCol) Next intColNext intRow

25. a fill the array incorrectly10 50 25200 300 30

26. c fill the array correctly10 200 50300 25 30

27. b result in the “Subscript out of range.” message10 20050 300

28. b result in the “Subscript out of range.” message10200

253

Page 262: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Exercises1. a. Dim strMonth(1 To 6) as String

b. strMonth(1) = “January”strMonth(1) = “February”strMonth(1) = “March”strMonth(1) = “April”strMonth(1) = “May”strMonth(1) = “June”

c.January strMonth(1)February strMonth(2)March strMonth(3)April strMonth(4)May strMonth(5)June strMonth(6)

254

Page 263: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

2. a. Dim intScore(1 To 10) as Integerb. Dim intX as Integer

Open “a:\tut10\scores.dat” for Input As #1for intX = 1 To 10

Input #1, intScore(intX)Next intXClose #1

3. a. Dim strEmployee(1 To 3, 1 To 2) as Stringb. Dim intRow as Integer, intCol as Integer

Open “a:\tut10\employ.dat” for Input As #1For intRow = 1 To 3

For intCol = 1 To 2Input #1, strEmployee(intRow, intCol)

Next intColNext intRolClose #1

c. Dim intRow as Integer, intCol as IntegerOpen “a:\tut10\employ.dat” for Input As #1For intCol = 1 To 2

For intRow = 1 To 3Input #1, strEmployee(intRow, intCol)

Next intRowNext intColClose #1

4. la4Done project – The student should submit two printouts of the interface with the test data showing and a printout of the application’s code.

255

Page 264: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim strCapitals(1 To 50) As String

Private Sub cmdExit_Click() Unload frmStatesEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() Dim strState As String, strCapital As String, intX As Integer frmStates.Left = (Screen.Width - frmStates.Width) / 2 frmStates.Top = (Screen.Height - frmStates.Height) / 2 Open "a:\tut10\capital.dat" For Input As #1 Do While Not EOF(1) Input #1, strState, strCapital intX = intX + 1 lstState.AddItem strState strCapitals(intX) = strCapital Loop Close #1 lstState.ListIndex = 0End Sub

Private Sub lstState_Click() lblCapital.Caption = strCapitals(lstState.ListIndex + 1)End Sub

5. la5Done project – The student should submit two printouts of the interface with the test data showing, a printout of the application’s code, and the error message that appears when the application searches for employee number 2000. The error message may vary.

Error message: Incorrect employee number.

256

Page 265: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim strEmploy(1 To 20, 1 To 2) As String

Private Sub cmdExit_Click() Unload frmEmployEnd Sub

Private Sub cmdFind_Click() Dim intRow As Integer, intUser As Integer, strNum As String, strFound As String Const conBtns As String = _ vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal strNum = txtNum.Text strFound = "N" Do While intRow < 20 And strFound = "N" intRow = intRow + 1 If Trim(strEmploy(intRow, 1)) = Trim(strNum) Then lblName.Caption = strEmploy(intRow, 2) strFound = "Y" End If Loop If strFound = "N" Then intUser = MsgBox("Incorrect employee number.", conBtns, "Number Error") End If txtNum.SetFocusEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() Dim intRow As Integer frmEmploy.Left = (Screen.Width - frmEmploy.Width) / 2 frmEmploy.Top = (Screen.Height - frmEmploy.Height) / 2 Open "a:\tut10\employ.dat" For Input As #1 For intRow = 1 To 20 Input #1, strEmploy(intRow, 1), strEmploy(intRow, 2) Next intRow Close #1End Sub

Private Sub txtNum_GotFocus() txtNum.SelStart = 0 txtNum.SelLength = Len(txtNum.Text)End Sub

6. la6Done project – The student should submit a printout of the interface with the test data showing and a printout of the application’s code.

257

Page 266: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim intNums(1 To 20) As Integer

Private Sub cmdExit_Click() Unload frmPointsEnd Sub

Private Sub cmdFind_Click() Dim intLow As Integer, intStudents As Integer, intX As Integer intLow = intNums(1) intStudents = 1 For intX = 2 To 20 If intNums(intX) < intLow Then intLow = intNums(intX) intStudents = 1 Else If intNums(intX) = intLow Then intStudents = intStudents + 1 End If End If Next intX lblLowNum.Caption = intLow lblNumStud.Caption = intStudentsEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() Dim intX As Integer frmPoints.Top = (Screen.Height - frmPoints.Height) / 2 frmPoints.Left = (Screen.Width - frmPoints.Width) / 2 Open "a:\tut10\points.dat" For Input As #1 For intX = 1 To 20 Input #1, intNums(intX) Next intX Close #1End Sub

7. la7Done project – The student should submit two printouts of the interface with the test data showing and a printout of the application’s code.

258

Page 267: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim 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) <= 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.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmGradeEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmGrade.Top = (Screen.Height - frmGrade.Height) / 2 frmGrade.Left = (Screen.Width - frmGrade.Width) / 2 intPoints(1) = 0 intPoints(2) = 300 intPoints(3) = 350 intPoints(4) = 400 intPoints(5) = 450 strGrades(1) = "F" strGrades(2) = "D" strGrades(3) = "C" strGrades(4) = "B" strGrades(5) = "A"End Sub

Private Sub txtPoints_Change() lblGrade.Caption = ""End Sub

Private Sub txtPoints_GotFocus() txtPoints.SelStart = 0 txtPoints.SelLength = Len(txtPoints.Text)End Sub

259

Page 268: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

8. la8Done project – The student should submit two printouts of the interface with the test data showing and a printout of the application’s code.

Option ExplicitDim 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 = 1 Do While intX <= 5 And strFound = "N" If intpoints(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.SetFocusEnd Sub

Private Sub cmdExit_Click() Unload frmGradeEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub Form_Load() frmGrade.Top = (Screen.Height - frmGrade.Height) / 2 frmGrade.Left = (Screen.Width - frmGrade.Width) / 2 intpoints(1) = 299 intpoints(2) = 349 intpoints(3) = 399 intpoints(4) = 449 intpoints(5) = 500 strGrades(1) = "F" strGrades(2) = "D" strGrades(3) = "C" strGrades(4) = "B" strGrades(5) = "A"End Sub

Private Sub txtPoints_Change() lblGrade.Caption = ""End Sub

Private Sub txtPoints_GotFocus() txtPoints.SelStart = 0 txtPoints.SelLength = Len(txtPoints.Text)End Sub

260

Page 269: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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.

Option ExplicitDim 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) <= 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.SetFocusEnd Sub

Private Sub Form_Load() Dim intTotPoints As Integer frmGrade.Top = (Screen.Height – frmGrade.Height) / 2 frmGrade.Left = (Screen.Width – frmGrade.Width) / 2 intTotPoints = InputBox("Enter the total number of points possible.", _ "Input") intPoints(1) = 0 intPoints(2) = 0.6 * intTotPoints intPoints(3) = 0.7 * intTotPoints intPoints(4) = 0.8 * intTotPoints intPoints(5) = 0.9 * intTotPoints strGrades(1) = "F" strGrades(2) = "D" strGrades(3) = "C" strGrades(4) = "B" strGrades(5) = "A"End Sub

Private Sub cmdExit_Click() Unload frmGradeEnd Sub

Private Sub cmdPrint_Click() PrintForm

Private Sub txtPoints_Change() lblGrade.Caption = ""End Sub

Private Sub txtPoints_GotFocus() txtPoints.SelStart = 0 txtPoints.SelLength = Len(txtPoints.Text)

261

Page 270: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Sub End Sub

262

Page 271: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

10. la10Done project – The student should submit two printouts of the interface with the test data showing and a printout of the application’s code.

la10Done.frmOption ExplicitDim udtGrades(1 To 5) As Student

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 udtGrades(intX).intPoints <= intNum Then lblGrade.Caption = udtGrades(intX).strGrade strFound = "Y" Else intX = intX - 1 End If Loop Else intUser = MsgBox("Incorrect number of points.", conBtns, "Entry Error") End If txtPoints.SetFocusEnd Sub

Private Sub Form_Load() frmGrade.Top = (Screen.Height - frmGrade.Height) / 2 frmGrade.Left = (Screen.Width - frmGrade.Width) / 2 udtGrades(1).intPoints = 0 udtGrades(1).strGrade = "F" udtGrades(2).intPoints = 300 udtGrades(2).strGrade = "D" udtGrades(3).intPoints = 350 udtGrades(3).strGrade = "C" udtGrades(4).intPoints = 400 udtGrades(4).strGrade = "B" udtGrades(5).intPoints = 450 udtGrades(5).strGrade = "A"End Sub

Private Sub cmdExit_Click() Unload frmGradeEnd Sub

Private Sub cmdPrint_Click() PrintFormEnd Sub

Private Sub txtPoints_Change() lblGrade.Caption = ""End Sub

Private Sub txtPoints_GotFocus() txtPoints.SelStart = 0 txtPoints.SelLength = Len(txtPoints.Text)End Sub

la10Done.basOption ExplicitType Student intPoints As Integer strGrade As String

263

Page 272: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

End Type

11. la11Done project – The student should submit two printouts of the test11.dat and test11X.dat files and a printout of the application’s code.

test11.datstep a:858770761003078889592298865472099100327372

test11X.datstep a:858770769320

test11.datstep j:90927581105358393100973493705225104105377877

test11X.datstep j:9597808610330

Option ExplicitDim intScoreArray() As Integer, intRecCount As Integer

Private Sub cmdAvg_Click() Dim intNum As Integer, intTotal As Integer, sngAvg As Single For intNum = 1 To intRecCount intTotal = intTotal + intScoreArray(intNum) 'accumulate array scores Next intNum If intRecCount > 0 Then sngAvg = intTotal / intRecCount 'calculate average Else sngAvg = 0 End If lblMsg.Caption = "Average" 'display results lblAnswer.Caption = Format(sngAvg, "standard")End Sub

264

Page 273: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdExit_Click() Unload frmTestEnd Sub

Private Sub cmdHigh_Click() Dim intNum As Integer, intHigh As Integer intHigh = intScoreArray(1) 'initialize intHigh to first array element For intNum = 2 To intRecCount 'compare intHigh to remaining array elements If intScoreArray(intNum) > intHigh Then 'element is greater than intHigh intHigh = intScoreArray(intNum) End If Next intNum lblMsg.Caption = "Highest" 'display results lblAnswer.Caption = intHighEnd Sub

Private Sub cmdUpdate_Click() Dim intNum As Integer, intIncrease As Integer intIncrease = Val(InputBox("Enter the number of additional points:")) For intNum = 1 To intRecCount 'add additional points to each score in the array intScoreArray(intNum) = intScoreArray(intNum) + intIncrease Next intNum lblMsg.Caption = "Scores updated by" 'display message lblAnswer.Caption = intIncrease Open "a:\Tut10\Test11x.dat" For Output As #1 'open file For intNum = 1 To intRecCount 'write array contents to file Write #1, intScoreArray(intNum) Next intNum Close #1 'close fileEnd Sub

Private Sub Form_Load() frmTest.Left = (Screen.Width - frmTest.Width) / 2 frmTest.Top = (Screen.Height - frmTest.Height) / 2 Open "a:\Tut10\test11x.dat" For Input As #1 'open file Do While Not EOF(1) 'fill array with data intRecCount = intRecCount + 1 ReDim Preserve intScoreArray(intRecCount) Input #1, intScoreArray(intRecCount) Loop Close #1End Sub

265

Page 274: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

12. la12Done project – The student should submit two printouts of the sales12.dat file and a printout of the application’s code.

sales12.datstep a:1000050004000046000250008400750034503500057000230005555111122224500246701230050067872345

sales12.datstep e:1100055004400050600275009240825037953850062700253006110.51222.12444.249502.251371.125305507465.72579.5

Option ExplicitDim sngSales(1 To 10, 1 To 2) As Single

Private Sub cmdAvg_Click() Dim intRow As Integer, intCol As Integer, sngTotal As Single, sngAvg As Single For intRow = 1 To 10 For intCol = 1 To 2 sngTotal = sngTotal + sngSales(intRow, intCol) 'accumulate sales Next intCol Next intRow sngAvg = sngTotal / 20 'calculate average lblMsg.Caption = "Average" 'display results lblAnswer.Caption = Format(sngAvg, "standard")End Sub

Private Sub cmdExit_Click() Unload frmTestEnd Sub

Private Sub Form_Load() frmTest.Left = (Screen.Width - frmTest.Width) / 2 frmTest.Top = (Screen.Height - frmTest.Height) / 2 Dim intRow As Integer, intCol As Integer Open "a:\Tut10\sales12.dat" For Input As #1 'open file For intRow = 1 To 10 'fill array with data For intCol = 1 To 2 Input #1, sngSales(intRow, intCol) Next intCol Next intRow Close #1End Sub

266

Page 275: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdHigh_Click() Dim intRow As Integer, intCol As Integer, sngHigh As Single sngHigh = sngSales(1, 1) 'initialize sngHigh to first array element For intRow = 2 To 10 'compare sngHigh to remaining array elements For intCol = 1 To 2 If sngSales(intRow, intCol) > sngHigh Then 'element is greater than sngHigh sngHigh = sngSales(intRow, intCol) End If Next intCol Next intRow lblMsg.Caption = "Highest" 'display results lblAnswer.Caption = Format(sngHigh, "standard")End Sub

Private Sub cmdLow_Click() Dim intRow As Integer, intCol As Integer, sngLow As Single sngLow = sngSales(1, 1) 'initialize sngLow to first array element For intRow = 2 To 10 'compare sngLow to remaining array elements For intCol = 1 To 2 If sngSales(intRow, intCol) < sngLow Then 'element is less than sngLow sngLow = sngSales(intRow, intCol) End If Next intCol Next intRow lblMsg.Caption = "Lowest" 'display results lblAnswer.Caption = Format(sngLow, "standard")End Sub

Private Sub cmdUpdate_Click() Dim intRow As Integer, intCol As Integer, sngIncrease As Single sngIncrease = Val(InputBox("Enter the increase:")) For intRow = 1 To 10 'calculate following year's expected sales For intCol = 1 To 2 sngSales(intRow, intCol) = sngSales(intRow, intCol) * (1 + sngIncrease) Next intCol Next intRow lblMsg.Caption = "Sales updated by" 'display message lblAnswer.Caption = Format(sngIncrease, "percent") Open "a:\Tut10\sales12.dat" For Output As #1 'open file For intRow = 1 To 10 'write array contents to file For intCol = 1 To 2 Write #1, sngSales(intRow, intCol) Next intCol Next intRow Close #1 'close fileEnd Sub

267

Page 276: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

13. la13Done project – The student should submit a printout of the sales13.dat file, a printout of the report showing a 10% bonus, and a printout of the application’s code. The format of the report may vary.

sales13.dat 10000,5000,400040000,46000,1000025000,8400,250007500,3450,1500035000,57000,2500023000,5555,75001111,2222,500045002,46701,450002300,500,15006787,2345,3000

M & J Sales

Bonus percentage: 10.00%

Number Sales Bonus------ ------------ ------------1 19,000.00 1,900.002 96,000.00 9,600.003 58,400.00 5,840.004 25,950.00 2,595.005 117,000.00 11,700.006 36,055.00 3,605.507 8,333.00 833.308 136,703.00 13,670.309 4,300.00 430.0010 12,132.00 1,213.20

Total bonus paid: $51,387.30

End of report

Option ExplicitDim sngsales(1 To 10, 1 To 3) As Single

Private Sub cmdExit_Click() Unload frmSalesEnd Sub

268

Page 277: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdPrint_Click() Dim intRow As Integer, intCol As Integer, sngRate As Single Dim sngSalesmanTot As Single, sngBonus As Single, sngTotalBonus As Single Dim strFont As String, sngSize As Single Dim strPS1 As String * 12, strPS2 As String * 10 sngRate = Val(txtBonus.Text) strFont = Printer.Font 'save current printer settings sngSize = Printer.FontSize Printer.Font = "courier new" 'change printer settings Printer.FontSize = 12 'print title and headings Printer.Print Tab(30); "M & J Sales" Printer.Print Printer.Print Tab(5); "Bonus percentage: " & Format(sngRate, "percent") Printer.Print Printer.Print Printer.Print Tab(5); "Number"; Tab(18); "Sales"; Tab(33); "Bonus" Printer.Print Tab(5); "------"; Tab(15); "------------"; Tab(30); "------------" For intRow = 1 To 10 For intCol = 1 To 3 sngSalesmanTot = sngSalesmanTot + sngsales(intRow, intCol) Next intCol sngBonus = sngSalesmanTot * sngRate RSet strPS1 = Format(sngSalesmanTot, "standard") RSet strPS2 = Format(sngBonus, "standard") Printer.Print Tab(5); intRow; Tab(15); strPS1; Tab(30); strPS2 sngTotalBonus = sngTotalBonus + sngBonus sngSalesmanTot = 0 Next intRow Printer.Print 'print two blank lines Printer.Print 'print grand total RSet strPS2 = Format(sngTotalBonus, "currency") Printer.Print Tab(5); "Total bonus paid:"; Tab(30); strPS2 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 = sngSizeEnd Sub

269

Page 278: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub Form_Load() Dim intRow As Integer, intCol As Integer frmSales.Left = (Screen.Width - frmSales.Width) / 2 frmSales.Top = (Screen.Height - frmSales.Height) / 2 Open "a:\tut10\sales13.dat" For Input As #1 For intRow = 1 To 10 For intCol = 1 To 3 Input #1, sngsales(intRow, intCol) Next intCol Next intRowEnd Sub

Private Sub txtBonus_GotFocus() txtBonus.SelStart = 0 txtBonus.SelLength = Len(txtBonus.Text)End Sub

14. la14Done project – The student should submit two printouts or the test14.dat file and a printout of the Click event for the Update Scores button.

test14.datstep a:858770761003078889592298865472099100327372

test14.datstep e:858775761053078889592298865472099100327372

270

Page 279: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Sub cmdUpdate_Click() Dim strStudNum As String, intStudNum As Integer, intIncrease As Integer Dim intUser As Integer, intX As Integer Const conBtns As String = _ vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal 'get student number or letter A strStudNum = InputBox("Enter the student number (enter A to update all student scores):", "Student") intStudNum = Val(strStudNum) strStudNum = UCase(strStudNum) If strStudNum <> "A" And intStudNum < 1 Or intStudNum > 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 IfEnd Sub

15. la15Done project – The student should submit a printout of the application’s code.Option ExplicitDim intCounter(1 To 3, 1 To 4) As Integer

Private Sub Form_Load() frmPao.Top = (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

271

Page 280: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 intColEnd 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 frmPaoEnd Sub

272

Page 281: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 = sngSizeEnd Sub

273

Page 282: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 10, Lesson BQuestions1. a,e ConnectionString, RecordSource2. d DataSource3. b cell4. c right-click5. c AllowUpdate6. a Columns7. c Format8. d Locked9. e Layout10. d Edit, Edit11. a,b,d AfterColEdit, AfterColUpdate, BeforeColUpdate12. c,e AfterUpdate, BeforeUpdate13. e adoNum.Recordset.Fields(“fldTot”) = adoNum.Recorset.Fields(“fldNum1”) * 314. b Dim objFlds as Object15. e Set objFlds = adoNum.Recordset.Fields16. c objFlds(“fldTot”) + Round(objFlds(“fldNum1”) * .15, 3)

Exercises1. 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):

274

Page 283: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Printout #3 (step i):

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 frmSales.Top = (Screen.Height – frmSales.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmSalesEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd 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 frmSales.Top = (Screen.Height – frmSales.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmSalesEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

275

Page 284: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmSales.Top = (Screen.Height – frmSales.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmSalesEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd 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):

Printout #3 (step i):

276

Page 285: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmPrice.Top = (Screen.Height – frmPrice.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmPriceEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd 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 frmPrice.Top = (Screen.Height – frmPrice.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmPriceEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

277

Page 286: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmPrice.Top = (Screen.Height – frmPrice.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmPriceEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

3. lb3Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

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 frmBills.Top = (Screen.Height – frmBills.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmBillsEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

278

Page 287: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

4. lb4Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

Option ExplicitDim 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 <= 4 Then objFlds(“fldTitle”) = strTitles(intCode) Else objFlds(“fldTitle”) = “Unknown” End IfEnd Sub

Private Sub Form_Load() frmEmp.Left = (Screen.Width – frmEmp.Width) / 2 frmEmp.Top = (Screen.Height – frmEmp.Height) / 2 strTitles(1) = “Manager” strTitles(2) = “Secretary” strTitles(3) = “Payroll Clerk” strTitles(4) = “Security Guard”End Sub

Private Sub mnuFileExit_Click() Unload frmEmpEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub5. lb5Done project – The student should submit a printout of the interface and a printout of the

code.

279

Page 288: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim strTitles(1 To 4, 1 To 2) As String

Private Sub dgdEmp_AfterColUpdate(ByVal ColIndex As Integer) Dim objFlds As Object, strCode As String Dim intX As Integer, strFound As String Set objFlds = adoEmp.Recordset.Fields strCode = UCase(objFlds(“fldCode”)) intX = 1 ‘search first column of array strFound = “N” Do While intX <= 4 And strFound = “N” If strTitles(intX, 1) = strCode Then objFlds(“fldTitle”) = strTitles(intX, 2) strFound = “Y” Else intX = intX + 1 End If Loop If strFound = “N” Then ‘if code is not in the array objFlds(“fldTitle”) = “Unknown” End IfEnd Sub

Private Sub Form_Load() frmEmp.Left = (Screen.Width – frmEmp.Width) / 2 frmEmp.Top = (Screen.Height – frmEmp.Height) / 2 strTitles(1, 1) = “A” strTitles(1, 2) = “Manager” strTitles(2, 1) = “B” strTitles(2, 2) = “Secretary” strTitles(3, 1) = “C” strTitles(3, 2) = “Payroll Clerk” strTitles(4, 1) = “D” strTitles(4, 2) = “Security Guard”End Sub

Private Sub mnuFileExit_Click() Unload frmEmpEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

6. lb6Done project – The student should submit a printout of the Load event’s code.Private Sub Form_Load() frmColfax.Top = (Screen.Height – frmColfax.Height) / 2 frmColfax.Left = (Screen.Width – frmColfax.Width) / 2 dgdPay.Caption = dgdPay.Caption & “ - “ & DateEnd Sub

280

Page 289: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

7. lb7Done 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:

Option Explicit

Private Sub dgdInvoices_OnAddNew() Dim objFlds As Object Set objFlds = adoInvoices.Recordset.Fields objFlds(“fldDate”) = DateEnd Sub

Private Sub Form_Load() frmInvoices.Left = (Screen.Width – frmInvoices.Width) / 2 frmInvoices.Top = (Screen.Height – frmInvoices.Height) / 2End Sub

Private Sub mnuFileExit_Click() Unload frmInvoicesEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

8. lb8Done project – The student should submit two printouts of the interface and a printout of the code.

Printout #1: Printout #2:

281

Page 290: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

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 frmPrice.Top = (Screen.Height – frmPrice.Height) / 2End Sub

Private Sub Form_Unload(Cancel As Integer) Dim intX As Integer, objFlds As Object Set objFlds = adoPrice.Recordset.Fields adoPrice.Recordset.MoveFirst For intX = 1 To adoPrice.Recordset.RecordCount objFlds("fldCurPrice") = objFlds("fldNewPrice") objFlds("fldNewPrice") = 0 objFlds("fldIncrease") = 0 adoPrice.Recordset.MoveNext Next intXEnd Sub

Private Sub mnuFileExit_Click() Unload frmPriceEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

282

Page 291: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 10, Lesson CQuestions1. d Val and InputBox are examples of user-defined functions.2. a udfCalcNewPrice = sngNew3. b intBonus = udfCalcBonus(intSales)4. a Private Function udfSearch(sngNums() as Single) as Boolean5. c blnFound = udfSearch(sngData())

Exercises1. lc1Done project – The student should submit a printout of the interface with the test data

showing and a printout of the code.

283

Page 292: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim sngSingle(1 To 6, 1 To 4) As SingleDim sngMarried(1 To 6, 1 To 4) As Single

Private Sub dgdPay_AfterColUpdate(ByVal ColIndex As Integer) Dim objFlds As Object 'create object variable Set objFlds = adoPay.Recordset.Fields 'assign object reference 'calculate gross pay, taxes, and net pay If objFlds("fldHours") <= 40 Then objFlds("fldGross") = Round(objFlds("fldHours") * objFlds("fldRate"), 2) Else objFlds("fldGross") = Round(40 * objFlds("fldRate") + _ (objFlds("fldHours") - 40) * objFlds("fldRate") * 1.5, 2) End If If UCase(objFlds("fldStatus")) = "S" Then objFlds("fldFwt") = Round(udfCalcFwt(sngSingle(), objFlds), 2) Else objFlds("fldFwt") = Round(udfCalcFwt(sngMarried(), objFlds), 2) End If objFlds("fldFica") = Round(objFlds("fldGross") * 0.07655, 2) objFlds("fldNet") = Round(objFlds("fldGross") - objFlds("fldFica") _ - objFlds("fldFwt"), 2) End Sub

Private Sub Form_Load() Dim intRow As Integer, intCol As Integer frmColfax.Top = (Screen.Height – frmColfax.Height) / 2 frmColfax.Left = (Screen.Width – frmColfax.Width) / 2 Open "a:\tut10\taxtbls.txt" For Input As #1 'open file For intRow = 1 To 6 'fill sngSingle array For intCol = 1 To 4 Input #1, sngSingle(intRow, intCol) Next intCol Next intRow For intRow = 1 To 6 'fill sngMarried array For intCol = 1 To 4 Input #1, sngMarried(intRow, intCol) Next intCol Next intRow Close #1 'close file End Sub

Private Sub mnuFileExit_Click() Unload frmColfaxEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

284

Page 293: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Function udfCalcFwt(sngArray() As Single, objTemp As Object) As Single Dim intX As Integer, blnFound As Boolean Dim sngTaxable As Single, sngTax As Single intX = 1 'keeps track of array row blnFound = False 'indicates whether taxable wage range was found 'calculate taxable wages sngTaxable = objTemp("fldgross") - objTemp("fldallow") * 51.92 'search array for taxable wage range Do While intX <= 6 And blnFound = False If sngArray(intX, 1) >= sngTaxable Then 'taxable wages fall within range sngTax = sngArray(intX, 2) + sngArray(intX, 3) _ * (sngTaxable - sngArray(intX, 4)) blnFound = True Else intX = intX + 1 'continue search in next array row End If Loop udfCalcFwt = sngTax End Function

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

285

Page 294: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lc2Done.frm

Option ExplicitDim udtSingle(1 To 6) As TaxTableDim udtMarried(1 To 6) As TaxTable

Private Sub dgdPay_AfterColUpdate(ByVal ColIndex As Integer) Dim objFlds As Object 'create object variable Set objFlds = adoPay.Recordset.Fields 'assign object reference 'calculate gross pay, taxes, and net pay objFlds("fldGross") = Round(objFlds("fldHours") * objFlds("fldRate"), 2) If UCase(objFlds("fldStatus")) = "S" Then objFlds("fldFwt") = Round(udfCalcFwt(udtSingle(), objFlds), 2) Else objFlds("fldFwt") = Round(udfCalcFwt(udtMarried(), objFlds), 2) End If objFlds("fldFica") = Round(objFlds("fldGross") * 0.07655, 2) objFlds("fldNet") = Round(objFlds("fldGross") - objFlds("fldFica") _ - objFlds("fldFwt"), 2) End Sub

Private Sub Form_Load() Dim intRow As Integer frmColfax.Top = (Screen.Height - frmColfax.Height) / 2 frmColfax.Left = (Screen.Width - frmColfax.Width) / 2 Open "a:\tut10\taxtbls.txt" For Input As #1 'open file For intRow = 1 To 6 'fill Single array Input #1, udtSingle(intRow).sngMax, udtSingle(intRow).sngBase, _ udtSingle(intRow).sngPercent, udtSingle(intRow).sngExcess Next intRow For intRow = 1 To 6 'fill Married array Input #1, udtMarried(intRow).sngMax, udtMarried(intRow).sngBase, _ udtMarried(intRow).sngPercent, udtMarried(intRow).sngExcess Next intRow Close #1 'close fileEnd Sub

Private Sub mnuFileExit_Click() Unload frmColfaxEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

286

Page 295: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Function udfCalcFwt(udtArray() As TaxTable, objTemp As Object) As Single Dim intX As Integer, blnFound As Boolean Dim sngTaxable As Single, sngTax As Single intX = 1 'keeps track of array row blnFound = False 'indicates whether taxable wage range was found 'calculate taxable wages sngTaxable = objTemp("fldgross") - objTemp("fldallow") * 51.92 'search array for taxable wage range Do While intX <= 6 And blnFound = False If udtArray(intX).sngMax >= sngTaxable Then 'taxable wages fall within range sngTax = udtArray(intX).sngBase + udtArray(intX).sngPercent _ * (sngTaxable - udtArray(intX).sngExcess) blnFound = True Else intX = intX + 1 'continue search in next array row End If Loop udfCalcFwt = sngTaxEnd Function

lc2Done.basOption ExplicitType TaxTable sngMax As Single sngBase As Single sngPercent As Single sngExcess As SingleEnd Type

3. lc3Done project – The student should submit a printout of the interface with the test data showing and a printout of the code.

287

Page 296: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

lc3Done.frm

Option ExplicitDim udtTable(1 To 6, 1 To 2) As TaxTable

Private Sub dgdPay_AfterColUpdate(ByVal ColIndex As Integer) Dim objFlds As Object 'create object variable Set objFlds = adoPay.Recordset.Fields 'assign object reference 'calculate gross pay, taxes, and net pay objFlds("fldGross") = Round(objFlds("fldHours") * objFlds("fldRate"), 2) If UCase(objFlds("fldStatus")) = "S" Then objFlds("fldFwt") = Round(udfCalcFwt(1, objFlds), 2) Else objFlds("fldFwt") = Round(udfCalcFwt(2, objFlds), 2) End If objFlds("fldFica") = Round(objFlds("fldGross") * 0.07655, 2) objFlds("fldNet") = Round(objFlds("fldGross") - objFlds("fldFica") _ - objFlds("fldFwt"), 2) End Sub

Private Sub Form_Load() Dim intRow As Integer, intCol As Integer frmColfax.Top = (Screen.Height – frmColfax.Height) / 2 frmColfax.Left = (Screen.Width – frmColfax.Width) / 2 Open "a:\tut10\taxtbls.txt" For Input As #1 'open file For intCol = 1 To 2 'fill Single array, then Married array For intRow = 1 To 6 Input #1, udtTable(intRow, intCol).sngMax, _ udtTable(intRow, intCol).sngBase, _ udtTable(intRow, intCol).sngPercent, _ udtTable(intRow, intCol).sngExcess Next intRow Next intCol Close #1 'close fileEnd Sub

Private Sub mnuFileExit_Click() Unload frmColfaxEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

288

Page 297: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Function udfCalcFwt(intCol As Integer, objTemp As Object) As Single Dim intX As Integer, blnFound As Boolean Dim sngTaxable As Single, sngTax As Single intX = 1 'keeps track of array row blnFound = False 'indicates whether taxable wage range was found 'calculate taxable wages sngTaxable = objTemp("fldgross") - objTemp("fldallow") * 51.92 'search array for taxable wage range Do While intX <= 6 And blnFound = False If udtTable(intX, intCol).sngMax >= sngTaxable Then 'taxable wages fall within range sngTax = udtTable(intX, intCol).sngBase _ + udtTable(intX, intCol).sngPercent _ * (sngTaxable - udtTable(intX, intCol).sngExcess) blnFound = True Else intX = intX + 1 'continue search in next array row End If Loop udfCalcFwt = sngTaxEnd Function

lc3Done.basOption ExplicitType TaxTable sngMax As Single sngBase As Single sngPercent As Single sngExcess As SingleEnd Type

4. lc4Done project – The student should submit a printout of the interface with the test data showing, a printout of the code, and a printout of the taxtbls2.txt file.

289

Page 298: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Option ExplicitDim sngSingle(1 To 6, 1 To 4) As SingleDim sngMarried(1 To 6, 1 To 4) As Single

Private Sub dgdPay_AfterColUpdate(ByVal ColIndex As Integer) Dim objFlds As Object 'create object variable Set objFlds = adoPay.Recordset.Fields 'assign object reference 'calculate gross pay, taxes, and net pay objFlds("fldGross") = Round(objFlds("fldHours") * objFlds("fldRate"), 2) If UCase(objFlds("fldStatus")) = "S" Then objFlds("fldFwt") = Round(udfCalcFwt(sngSingle(), objFlds), 2) Else objFlds("fldFwt") = Round(udfCalcFwt(sngMarried(), objFlds), 2) End If objFlds("fldFica") = Round(objFlds("fldGross") * 0.07655, 2) objFlds("fldNet") = Round(objFlds("fldGross") - objFlds("fldFica") _ - objFlds("fldFwt"), 2) End Sub

Private Sub Form_Load() Dim intRow As Integer, intCol As Integer frmColfax.Top = (Screen.Height - frmColfax.Height) / 2 frmColfax.Left = (Screen.Width - frmColfax.Width) / 2 Open "a:\tut10\taxtbls2.txt" For Input As #1 'open file For intRow = 1 To 6 'fill sngSingle array For intCol = 1 To 4 Input #1, sngSingle(intRow, intCol) Next intCol Next intRow For intRow = 1 To 6 'fill sngMarried array For intCol = 1 To 4 Input #1, sngMarried(intRow, intCol) Next intCol Next intRow Close #1 'close file End Sub

Private Sub mnuFileExit_Click() Unload frmColfaxEnd Sub

Private Sub mnuFilePrint_Click() PrintFormEnd Sub

290

Page 299: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Private Function udfCalcFwt(sngArray() As Single, objTemp As Object) As Single Dim intX As Integer, blnFound As Boolean Dim sngTaxable As Single, sngTax As Single intX = 6 'keeps track of array row blnFound = False 'indicates whether taxable wage range was found 'calculate taxable wages sngTaxable = objTemp("fldgross") - objTemp("fldallow") * 51.92 'search array for taxable wage range Do While intX >= 1 And blnFound = False If sngArray(intX, 1) < sngTaxable Then 'taxable wages fall within range sngTax = sngArray(intX, 2) + sngArray(intX, 3) _ * (sngTaxable - sngArray(intX, 4)) blnFound = True Else intX = intX - 1 'continue search in next array row End If Loop udfCalcFwt = sngTax End Function

taxtbls2.txt-99999,0,0,051,0,.15,51517,69.9,.28,5171105,234.54,.31,11052493,664.82,.36,24935385,1705.94,.396,5385-99999,0,0,0124,0,.15,124899,116.25,.28,8991855,383.93,.31,18553084,764.92,.36,30845439,1612.72,.396,5439

291

Page 300: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

292Tutorial 10 – Debugging

TechniqueYou can use the Debug menu’s Toggle Breakpoint and Add Watch commands to help you debug an application.

Exercises1. Option Explicit

Private Sub cmdCalc_Click() Dim intX As Integer, intNumber As Integer Dim intTotNum As Integer, sngAverage As Single Cls 'clears text printed by the Print method For intX = 1 To 2 Step 1 intNumber = Val(InputBox("Enter a number", "Number Entry")) Print intNumber intTotNum = intTotNum + intNumber Next intX

sngAverage = intTotNum / (intX - 1) Print "The average number is: "; sngAverageEnd Sub

Private Sub cmdExit_Click() Unload frmDebug3End Sub

Private Sub Form_Load() frmDebug3.Left = (Screen.Width - frmDebug3.Width) / 2 frmDebug3.Top = (Screen.Height - frmDebug3.Height) / 2End Sub

292

Page 301: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Tutorial 11, Lesson A

Questions

1. C

2. D

3. D

4. D

5. A

6. A

7. C

8. A

9. B

10. C

Exercises

1. You can use the new keyword sequence Inherits to create a new class based on an existing class. Derived classes inherit, and can extend, the properties, methods, events, data members, and event handlers defined in the base class.

Visual Basic.Net introduces the following statements and modifiers to support inheritance.

Inherits statement — Specifies the class (also known as the base class) from which the current class inherits. The Inherits keyword is only allowed in classes.

NotInheritable modifier — Prevents programmers from using the class as a base class.

MustInherit modifier — Specifies that instances of the given class cannot be created. The only way to use the class is to inherit from it.

Derived classes can override inherited methods with new implementations. Visual Basic.NET introduces the following modifiers for controlling property and method overriding.

Overridable — Allows a property or method to be overridden in an inheriting class. Public methods are NotOverridable by default.

Overrides — Allows you to override a property or method that is defined in the base class.

NotOverridable (default) — Prevents a property or method from being overridden in an inheriting class.

MustOverride — Requires the inheriting class to override the property or method. When the MustOverride keyword is used, the method definition consists of just the Sub, Function, or Property statement. No other statements are allowed and

293

Page 302: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

specifically there is no End Sub or End Function statement. Classes with MustOverride methods must be declared as MustInherit. Public methods are NotOverridable by default.

The following rules apply for inheritance:

Although derived classes can inherit from only one base class, they can implement an unlimited number of interfaces.

A public class cannot inherit a friend or a private class and a friend class cannot inherit a private class.

2. Follow the steps in the exercise to join on online newsgroup community. Student essays will vary. Some possible points of discussion can include: 1) Memory footprints of VB.NET applications, 2) VB.NET IDE problem: BUG or by design, or 3) defense of GOSUB as part of VB.NET.

3. Follow the steps in the exercise to practice working with the Auto Hide feature.

4. Follow the steps in the exercise and copy the macro file from your A: directory to MyMacros.

5. Follow the steps in the exercise to upgrade a Visual Basic 6.0 to VB.NET. The VB 6.0 project is provided in the Tut11 folder on the Student Disk.

Tutorial 11, Lesson B

Questions

1. C

2. A

3. D

4. C

5. B

6. A

7. C

8. B

9. A

10. D

Exercises

1.

294

Page 303: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

Task Visual Basic 6.0 Forms Windows FormsSet the Tab Indexing for all the controls on a form.

Select each control on the form and set its TabIndex property to the next number in the tab order for your form.

From the View menu choose Tab Order. The form displays a box next to each control that represents the control's TabIndex property setting. Click on each control in the order you want for the control's tab order defined. For more information, see Setting the Tab Order on Windows Forms.

Determine the modifier key (Alt, Shift, Ctrl) pressed during Keyboard and Mouse Events.

Use the parameters provided by the mouse event handler.

Compare the Form class's ModifierKeys method against the modifier key value, found in Keys enumeration.

Align or size controls based on the location and size of a single control.

Click on each control to align or size. The last control selected is used to determine the location and size of all controls selected.

Click on each control that to align or size. The first control selected is used to determine the location and size of all controls selected. For more information, see Aligning Multiple Controls on Windows Forms

Create an event handler. Use the drop-down lists in the Code Editor to select an object and the event that you want to create an event handler for.

From the Properties window, select the Events tab. Double-click on the event that you want to handle or enter a custom event handler name next to the event. For more information, see Creating Event Handlers on the Windows Forms Designer.

Change the name of a form.

Change the name specified in the Name property of the form in the Properties window.

Click on the form's class file in the Solution Explorer and then change the Filename property in the Properties window.

Change the run-time display position of a form.

Use the Form Layout window to position the form or set its Startup position.

With the form selected in the Windows Forms Designer, set the StartPosition property in the Properties window.

Display a form as a dialog box.

In code, use the Show method and specify that the

In code, use the ShowDialog method of the

295

Page 304: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

form be displayed modally using the vbModal value.

form. For details, see Displaying Dialog Boxes for Windows Forms.

Group/layer controls on a form.

Layer the controls within the GroupBox control. To move the controls as a group, select them all.

Place the controls within a GroupBox control. Moving the group box moves the controls as well.

Iterate through the controls on a form.

Use a control array Use the Controls collection. For details, see Collections in Visual Basic.

2. No answer necessary

3. Follow the steps indicated.

Note: you can also add code to initialize other properties of control.

4. ‘Visual Basic

Private Sub CreateShortcut()

‘Set the Text property and create an access key shortcut.

Button1.Text = “&Print”

End Sub

Note: To include an ampersand in a caption without creating an access key, include two ampersands (&&). A single ampersand is displayed in the caption and no characters are underlined.

5.

a. ALT + * = VB 6.0 and VB.NET: Highlights the next statement to be executed.

b. Alt + Backspace (also Ctrl + Z) = VB 6.0 and VB.NET: Reverses the last editing action.

c. Alt + F3 + B = VB 6.0: Selects or clears the Search Up option for find and replace operations.

d. Alt + F3 + C = VB 6.0: Selects or clears the Match Case option for find and replace operations.

e. Alt + F3 + N = VB 6.0: Clears the Find what and Replace with boxes and all options, and creates a new search request.

f. Ctrl + R = VB.NET: Database.Run

g. Alt + F10 = VB.NET: Debug.ApplyCodeChanges

h. Ctrl + Shift + F5 = VB.NET: Debug.RuntoCursor: Terminates a debugging session, rebuilds, and then starts running the application from the beginning again. Available in break and run modes.

6. Follow the steps indicated.

296

Page 305: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________Tutorial 12, Lesson A

Questions

11. D

12. D

13. A

14. B

15. C

16. C

17. D

18. C

19. C

20. A

Exercises

1. Windows Forms should be used to develop applications where the client is expected to shoulder a significant amount of the processing burden in an application. These include Win32 desktop applications, the kind that were traditionally developed in previous versions of VB. Examples include drawing or graphics applications, data-entry systems, point-of-sale systems, and games.

ASP.NET Web Forms are used to create applications in which they primary user interface is a browser. This includes applications intended to be available publicly via the World Wide Web, such as e-commerce applications.

2. The student will have met the requirements as long as the project has a background color on the Web Forms page and has one of each type of control: HTML and ASP.NET.

3. Follow the steps for compiling and running the Web Forms page created in Exercise 2.

4. The student may choose any number of HTML controls. An example of how to declare an HtmlInputText control would be:

<input id="Name" type=text size=40 runat="server">

An example of how to declare an HtmlInputButton control would be:

297

Page 306: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________<input type=submit value="Enter" runat="server">

An example of how to declare an HtmlAnchor control would be:

click <a id="Anchor1" runat="server">More </a> to see the next page

5. A new control will be added programmatically to the Web Forms page created in Exercise 2.

[BEGIN CODE]

Dim Label1 as Label

Label1 = New Label

Label1.Text = “Sample Label"

Panel1.Controls.Add(myLabel)

Sub Page_Load(ByVal Sender As Object, ByVal e as EventArgs)

Dim i as Integer

Dim numlabels As Integer

numlabels = DropDown1.SelectedItem.Value

For I = 1 to numlabels

myLabel = New Label

myLabel.Text = "Label" & I

myLabel.ID = "Label" & I

Panel1.Controls.Add(myLabel)

Dim 1 As LiteralControl = “<br>"

Panel1.Controls.Add(1)

Next

End Sub

[END CODE]

6. The student will follow the steps and customize his toolbox.

298

Page 307: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________Tutorial 12, Lesson B

Questions

1. A

2. D

3. A

4. B

5. C

6. B

7. C

8. A

9. D

10. C

Exercises

1. Have students share their designs with the class. Have a vote for most creative and most user friendly. Encourage students to modify the forms as constructive is given during the demonstration. Modifying the form in front of the class reinforces the learning objectives of the lesson.

2. Questions 2-5 have students create another Web Applications project bound to data. Have them print a screen of their project running or verify individually with them that the program updates the data.

3. See above.

4. See above.

5. See above.

6. Students have the flexibility of creating controls to bind as appropriate to their project.

299

Page 308: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________Code Solutions to Lesson B Project:

Code for Component1.vb:

Created by Anne NelsonHigh Point University, High Point, NCImports System.ComponentModel

Public Class Component1 Inherits System.ComponentModel.Component

Public Sub New() MyBase.New

'This call is required by the Component Designer. InitializeComponent

' TODO: Add any initialization after the InitializeComponent() call

End Sub

#Region " Component Designer generated code "

'Required by the Component Designer Private components As Container Private WithEvents ADOConnection1 As System.Data.ADO.ADOConnection Private WithEvents ADODataSetCommand1 As System.Data.ADO.ADODataSetCommand

'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Me.ADOConnection1 = New System.Data.ADO.ADOConnection() Me.ADODataSetCommand1 = New System.Data.ADO.ADODataSetCommand() '@design Me.TrayLargeIcon = False '@design Me.TrayAutoArrange = True '@design ADOConnection1.SetLocation(New System.Drawing.Point(167, 7))

300

Page 309: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ ADOConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Publishing\PublisherWork\Coursetech\VBNet\Tut12\PETS.mdb;Persist Security Info=False" '@design ADODataSetCommand1.SetLocation(New System.Drawing.Point(7, 7)) Dim a__1(6) As System.Data.ADO.ADOParameter a__1(0) = New System.Data.ADO.ADOParameter("birthdate", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "birthdate", System.Data.DataRowVersion.Current, Nothing) a__1(1) = New System.Data.ADO.ADOParameter("name", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "name", System.Data.DataRowVersion.Current, Nothing) a__1(2) = New System.Data.ADO.ADOParameter("notes", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "notes", System.Data.DataRowVersion.Current, Nothing) a__1(3) = New System.Data.ADO.ADOParameter("species", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "species", System.Data.DataRowVersion.Current, Nothing) a__1(4) = New System.Data.ADO.ADOParameter("vacc_id", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "vacc_id", System.Data.DataRowVersion.Current, Nothing) a__1(5) = New System.Data.ADO.ADOParameter("Original_vacc_id", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "vacc_id", System.Data.DataRowVersion.Original, Nothing) ADODataSetCommand1.UpdateCommand = New System.Data.ADO.ADOCommand(ADOConnection1, "UPDATE Main SET vacc_id = ?, name = ?, species = ?, birthdate = ?, notes = ? WHERE (vacc_id = ?) ", System.Data.CommandType.Text, False, a__1, System.Data.UpdateRowSource.Both) Dim a__2(1) As System.Data.ADO.ADOParameter a__2(0) = New System.Data.ADO.ADOParameter("vacc_id", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "vacc_id", System.Data.DataRowVersion.Current, Nothing)

301

Page 310: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ ADODataSetCommand1.DeleteCommand = New System.Data.ADO.ADOCommand(ADOConnection1, "DELETE FROM Main WHERE (vacc_id = ?) ", System.Data.CommandType.Text, False, a__2, System.Data.UpdateRowSource.Both) Dim a__3(5) As System.Data.ADO.ADOParameter a__3(0) = New System.Data.ADO.ADOParameter("birthdate", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "birthdate", System.Data.DataRowVersion.Current, Nothing) a__3(1) = New System.Data.ADO.ADOParameter("name", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "name", System.Data.DataRowVersion.Current, Nothing) a__3(2) = New System.Data.ADO.ADOParameter("notes", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "notes", System.Data.DataRowVersion.Current, Nothing) a__3(3) = New System.Data.ADO.ADOParameter("species", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "species", System.Data.DataRowVersion.Current, Nothing) a__3(4) = New System.Data.ADO.ADOParameter("vacc_id", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, False, 255, 255, "vacc_id", System.Data.DataRowVersion.Current, Nothing) ADODataSetCommand1.InsertCommand = New System.Data.ADO.ADOCommand(ADOConnection1, "INSERT INTO Main( vacc_id, name, species, birthdate, notes ) VALUES( ?, ?, ?, ?, ? ) ", System.Data.CommandType.Text, False, a__3, System.Data.UpdateRowSource.Both) Dim a__4() As System.Data.ADO.ADOParameter ADODataSetCommand1.SelectCommand = New System.Data.ADO.ADOCommand(ADOConnection1, "SELECT vacc_id, name, species, birthdate, notes FROM Main ", System.Data.CommandType.Text, False, a__4, System.Data.UpdateRowSource.Both) Dim a__5(5) As System.Data.Internal.DataColumnMapping a__5(0) = New System.Data.Internal.DataColumnMapping("birthdate", "birthdate") a__5(1) = New System.Data.Internal.DataColumnMapping("name", "name") a__5(2) = New System.Data.Internal.DataColumnMapping("notes", "notes")

302

Page 311: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ a__5(3) = New System.Data.Internal.DataColumnMapping("species", "species") a__5(4) = New System.Data.Internal.DataColumnMapping("vacc_id", "vacc_id") Dim a__6(1) As System.Data.Internal.DataTableMapping a__6(0) = New System.Data.Internal.DataTableMapping("Table", "Main", a__5) ADODataSetCommand1.TableMappings.All = a__6 End Sub #End Region Private Function ADODataSetCommand1FillDataSet(ByVal dataSet As System.Data.DataSet) As Integer Dim RowsAffected As Integer 'Create an error handling block in case filldataset throws an exception Try 'Load the dataset from the DataSetCommand RowsAffected = Me.ADODataSetCommand1.FillDataSet(dataSet) Catch eFillException As System.Exception 'TODO: Handle errors here Throw eFillException End Try Return RowsAffected End Function Private Function ADODataSetCommand1UpdateDataSource(ByVal updatedDataSet As System.Data.DataSet) As Integer Dim DeletedRows As System.Data.DataSet Dim UpdatedRows As System.Data.DataSet Dim InsertedRows As System.Data.DataSet Dim RowsAffected As Integer = 0 Try

303

Page 312: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ 'Get all of the deleted rows and update the datastore DeletedRows = updatedDataSet.GetChanges(System.Data.DataRowState.Deleted) If (Not (DeletedRows) Is Nothing) Then RowsAffected = Me.ADODataSetCommand1.Update(DeletedRows) End If 'Get all of the updated rows and update the datastore UpdatedRows = updatedDataSet.GetChanges(System.Data.DataRowState.Modified) If (Not (UpdatedRows) Is Nothing) Then RowsAffected = ((RowsAffected) + (Me.ADODataSetCommand1.Update(UpdatedRows))) End If 'Get all of the inserted rows and update the datastore InsertedRows = updatedDataSet.GetChanges(System.Data.DataRowState.New) If (Not (InsertedRows) Is Nothing) Then RowsAffected = ((RowsAffected) + (Me.ADODataSetCommand1.Update(InsertedRows))) End If Return RowsAffected Catch eUpdateException As System.Exception 'TODO: Handle errors here Throw eUpdateException End Try End Function Public Sub FillDataSet(ByVal dataSet As System.Data.DataSet) 'Open connections for ADO and SQLServer DataSetCommands Me.ADOConnection1.Open() 'Turn off constraint checking in the DataSet while retrieving data from datasource dataSet.EnforceConstraints = False 'Fill DataSet with data from all DataSetCommands Me.ADODataSetCommand1FillDataSet(dataSet)

304

Page 313: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ 'Turn on constraint checking in the DataSet dataSet.EnforceConstraints = True 'Close connections for ADO and SQLServer DataSetCommands Me.ADOConnection1.Close() End Sub Public Function UpdateDataSource(ByVal updatedDataSet As System.Data.DataSet) As System.Data.DataSet 'Update DataSet with data from all DataSetCommands Me.ADODataSetCommand1UpdateDataSource(updatedDataSet) Return updatedDataSet End Function End Class

Code for WebForm1.vb:

'Created by Anne Nelson'High Point University, High Point, NCImports SystemImports System.ComponentModel.DesignImports System.DataImports System.DrawingImports System.WebImports System.Web.SessionStateImports System.Web.UIImports System.Web.UI.WebControlsImports System.Web.UI.HtmlControlsImports Microsoft.VisualBasic

Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents Label4 As System.Web.UI.WebControls.Label Protected WithEvents Label3 As System.Web.UI.WebControls.Label

305

Page 314: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ Protected WithEvents Label2 As System.Web.UI.WebControls.Label Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents DataView2 As System.Data.DataView Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Protected WithEvents DataView1 As System.Data.DataView Protected WithEvents myDataSet1 As PetProj.myDataSet Protected myComponent As New Component1() #Region " Web Forms Designer Generated Code "

Dim WithEvents WebForm1 As System.Web.UI.Page Sub New() WebForm1 = Me End Sub

'CODEGEN: This procedure is required by the Web Form Designer 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.DataView2 = New System.Data.DataView() Me.DataView1 = New System.Data.DataView() Me.myDataSet1 = New PetProj.myDataSet() '@design DataView2.SetLocation(New System.Drawing.Point(201, 7)) DataView2.Table = myDataSet1.Main DataView2.Sort = "" '@design DataView1.SetLocation(New System.Drawing.Point(108, 7)) DataView1.Table = myDataSet1.Main DataView1.Sort = "" '@design myDataSet1.SetLocation(New System.Drawing.Point(7, 7)) myDataSet1.Prefix = "" myDataSet1.DataSetName = "myDataSet" myDataSet1.Locale = New System.Globalization.CultureInfo("en-US")

306

Page 315: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________ myDataSet1.Namespace = "http://www.tempuri.org/myDataSet.xsd" myDataSet1.Main.Prefix = "" myDataSet1.Main.TableName = "Main" End Sub #End Region Public Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) MyComponent.FillDataSet(myDataSet1) Dim index As Integer Dim key As String index = DataGrid1.SelectedIndex key = DataGrid1.DataKeys(index).ToString() dataView2.RowFilter = DataGrid1.DataKeyField & "='" & key & "'" Label1.DataBind() Label2.DataBind() Label3.DataBind() Label4.DataBind() End Sub Protected Sub WebForm1_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) If Not IsPostback Then ' Evals true first time browser hits the page MyComponent.FillDataSet(myDataSet1) DataGrid1.DataBind() End If End Sub Protected Sub WebForm1_Init(ByVal Sender As System.Object, ByVal e As System.EventArgs) 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub End Class

307

Page 316: Tutorial 1, Lesson A - The Resource Center * t…  · Web view2007-10-09 · Tutorial 1, Lesson A Page 1. Tutorial 1, Lesson B Page 4. Tutorial 1, Lesson C Page 7. Tutorial 1

_______________________________________________________________________________

308