Overview

Questions 1. d a program 2. c machine code 3. a Assembly 4. b High-level 5. d All of the above. 6. b JIT compiler 7. c class 8. d talk 9. c instance 10. b encapsulation 11. a abstraction 12. d Polymorphism 13. a base, derived 14. d inheritance 15. a) head, body, legs, heart, lungs b) eat, run, play, walk, bark c) three

Programming with VB 2005 3E 1 0-4188-3674-5 Chapter 1 – Lesson A

Questions 1. c Properties 2. d Solution Explorer 3. b .sln 4. d All of the above. 5. b Text 6. c Name 7. d StartPosition 8. The Text property controls the text that appears in the Windows form’s title bar, and on the application’s button on the Windows taskbar while the application is running. The Name property assigns a name to the Windows Form object; you use the name to refer to the form in code. The programmer uses the Name property. The user reads the Text property. 9. A Windows Form object is the form itself. A Windows Form object can be viewed in the designer window and appears on the screen when the application is run. The form file object is the disk file that contains the code associated with the Windows Form object. 10. The dot member access operator indicates that the Label class is a member of the Forms namespace, which is a member of the Windows namespace, which is a member of the System namespace.

Exercises 1. See the VB2005\Chap01\laCharities Solution files on the Solutions Disk. 2. See the VB2005\Chap01\laPhoto Solution files on the Solutions Disk. 3. See the VB2005\Chap01\laYorktown Solution files on the Solutions Disk. 4. (Discovery) See the VB2005\Chap01\laGreenwood Solution files on the Solutions Disk. d. The ControlBox property determines whether a form has a Control/System menu box in the title bar. e. Setting the ControlBox property to False removes the icon and the Minimize, Maximize, and Close buttons from the form’s title bar. g. The MaximizeBox property determines whether a form has a Maximize button in the title bar. h. Setting the MaximizeBox property to False dims (grays-out) the Maximize button in the form’s title bar. j. The MinimizeBox property determines whether a form has a Minimize button in the title bar. k. Setting the MinimizeBox property to False dims (grays-out) the Minimize button in the form’s title bar. 5. (Discovery) See the VB2005\Chap01\laGreenwood Solution files on the Solutions Disk. d. The ShowIcon property determines whether an icon appears in the form’s title bar. e. The ShowInTaskbar property determines whether the value stored in the form’s Text property appears on the Windows taskbar when the application is running. Chapter 1 – Lesson B

Questions 1. c Label 2. d Text 3. d All of the above. 4. d All of the above. 5. a System.Windows.Forms 6. b The executable file that Visual Basic automatically creates when you start an application has the same name as the solution, but with an .exe extension. 7. a Me.Close 8. Syntax refers to the rules of a programming language. 9. You use the Class Name list box to select the object you want to code. You use the Method Name list box to select the event you want to code. 10. A keyword is a word that has a special meaning in a programming language.

Programming with VB 2005 3E 2 0-4188-3674-5 Exercises 1. See the VB2005\Chap01\lbMechanics Solution files on the Solutions Disk. 2. See the VB2005\Chap01\lbCostello Solution files on the Solutions Disk. 3. See the VB2005\Chap01\lbTabatha Solution files on the Solutions Disk. 4. (Discovery) See the VB2005\Chap01\lbJerrods Solution files on the Solutions Disk. Chapter 1 – Lesson C

Questions 1. c timer 2. a Enabled 3. b Tick 4. c 10,000 5. b The user can see a timer control while the application is running. 6. c MinimizeBox 7. d FormBorderStyle 8. a ControlBox 9. To print a project’s code, open the Code Editor window. Click File on the menu bar, and then click Print. Click the OK button in the Print dialog box. 10. Delete the control from the form. Open the Code Editor window and delete the code contained in the control’s event procedures.

Exercises 1. See the VB2005\Chap01\lcJefferson Solution files on the Solutions Disk. 2. See the VB2005\Chap01\lcSplash Solution files on the Solutions Disk. The student is instructed to create his or her own splash screen. 3. (Discovery) See the VB2005\Chap01\lcOnOff Solution files on the Solutions Disk. (This solution also is used in Discovery Exercise 4, which teaches the student to display a graphic on each button’s face.) 4. (Discovery) See the VB2005\Chap01\lcModified OnOff Solution files on the Solutions Disk. 5. (Discovery) See the VB2005\Chap01\lcTooltip Solution files on the Solutions Disk. 6. (Debugging) See the VB2005\Chap01\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must remove the label control’s Click event procedure from the Code Editor window, and then enter the Me.Close() statement in the xExitButton’s Click event procedure.

Programming with VB 2005 3E 3 0-4188-3674-5 Chapter 2 – Lesson A

Questions 1. b label 2. c text box 3. d TOE 4. c upper-left corner 5. a first 6. a book title capitalization 7. c Identifying labels should be entered using book title capitalization. 8. b Sentence capitalization 9. 2 Identify the objects to which you will assign the 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. 10. 5 Test and debug the application. 3 Build the user interface. 4 Code the application. 6 Assemble the documentation. 2 Plan the application. 1 Meet with the client.

Exercises 1. TOE charts and sketches may vary.

Task Object Event Get the following from the user: name xNameTextBox None sales xSalesTextBox None commission rate xRateTextBox None Calculate the commission xCalcButton Click Display the following: name xNameTextBox None sales xSalesTexBox None commission rate xRateTextBox None commission xCalcButton, Click, None xCommissionLabel End the application xExitButton Click Clear the screen xClearButton Click

Programming with VB 2005 3E 4 0-4188-3674-5 Task Object Event 1. Calculate the commission xCalcButton Click 2. Display the commission in the xCommissionLabel control Clear the screen xClearButton Click End the application xExitButton Click Display the commission (from xCommissionLabel None xCalcButton) Get and display the name, sales, xNameTextBox, None and rate xSalesTextBox, xRateTextBox

Sample of a vertical arrangement:

Sample of a horizontal arrangement:

2. TOE charts and sketches may vary.

Task Object Event Get the following from the user: current year’s sales for each region xNorthSalesTextBox, None projected increase % for each region xSouthSalesTextBox, xEastSalesTextBox, xWestSalesTextBox xNorthIncreaseTextBox, xSouthIncreaseTextBox, xEastIncreaseTextBox, xWestIncreaseTextBox Calculate the projected sales for each xCalcButton Click region Programming with VB 2005 3E 5 0-4188-3674-5 Display the following: current year’s sales for each region xNorthSalesTextBox, None xSouthSalesTextBox, xEastSalesTextBox, xWestSalesTextBox

projected increase % for each region xNorthIncreaseTextBox, None xSouthIncreaseTextBox, xEastIncreaseTextBox, xWestIncreaseTextBox

projected sales for each region xCalcButton Click xNorthSalesLabel, xSouthSalesLabel, None xEastSalesLabel, xWestSalesLabel End the application xExitButton Click Clear the screen xClearButton Click

Task Object Event 1. Calculate the projected sales xCalcButton Click for each region 2. Display the projected sales in the xNorthSalesLabel, xSouthSalesLabel, xEastSalesLabel, and xWestSalesLabel controls Clear the screen xClearButton Click End the application xExitButton Click Display the projected sales (from xNorthSalesLabel, None xCalcButton) xSouthSalesLabel, xEastSalesLabel, xWestSalesLabel Get and display the projected xNorthIncreaseTextBox, None increase % for each region xSouthIncreaseTextBox, xEastIncreaseTextBox, xWestIncreaseTextBox Get and display the current year’s xNorthSalesTextBox, None sales for each region xSouthSalesTextBox, xEastSalesTextBox, xWestSalesTextBox

Sample of a vertical arrangement:

Programming with VB 2005 3E 6 0-4188-3674-5 Sample of a horizontal arrangement:

3. See the VB2005\Chap02\laTime Solution files on the Solutions Disk. Answers may vary.

Programming with VB 2005 3E 7 0-4188-3674-5 Chapter 2 – Lesson B

Questions 1. b TabIndex 2. d both b and c 3. a dark text on a light background 4. b x 5. a sans serif 6. d BorderStyle 7. a & 8. d Text 9. The first choice for an access key is the first letter of the caption or identifying label, 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 or label. The last choices are a vowel or number in the caption or label. 10. To give keyboard access to a text box, assign an access key to its identifying label control. Then set the label control’s TabIndex property to a value that is one number less than the text box’s TabIndex value.

Exercises 1. See the VB2005\Chap02\lbPaper Solution files on the Solutions Disk. 2. See the VB2005\Chap02\lbRMSales Solution files on the Solutions Disk. 3. See the VB2005\Chap02\lbTime Solution files on the Solutions Disk.

Chapter 2 – Lesson C

Questions 1. a Me.xNameTextBox.Text = ‘’ 2. b Me.xTotalLabel.Text = Val(Me.xSales1Label.Text + Me.xSales2Label.Text) 3. b Format 4. d Val 5. d rectangle 6. a a logic error 7. b a syntax error 8. 2.92 9. 2 10. 23

Exercises 1. See the VB2005\Chap02\lcPaper Solution files on the Solutions Disk. Answer using valid test data: $200.00 commission 2. See the VB2005\Chap02\lcRMSales Solution files on the Solutions Disk. Answers using valid test data: North projected sales are 27,500.00; South projected sales are 10,500.00; East projected sales are 10,400.00; West projected sales are 16,650.00 3. See the VB2005\Chap02\lcTime Solution files on the Solutions Disk. Answers using valid test data: 30 weekday hours and 2 weekend hours 4. See the VB2005\Chap02\lcJohnLee Solution files on the Solutions Disk. (The interface might not contain a Clear button.) Answer using first set of test data: 4500 ending balance Answer using second set of test data: 0 ending balance

Task Object Event 1. Calculate ending balance xCalcButton Click

Programming with VB 2005 3E 8 0-4188-3674-5 2. Display ending balance in xEndLabel control Clear the screen xClearButton Click End the application xExitButton Click Display the ending balance (from xCalcButton) xEndLabel None Get and display the beginning balance, monthly xBeginTextBox, None earnings, monthly expenses xEarnTextBox, xExpTextBox

Pseudocode: xCalcButton: Calculate ending balance = beginning balance + monthly earnings – monthly expenses Display ending balance in xEndLabel control xClearButton: Clear the Text property of the xBeginTextBox, xEarnTextBox, xExpTextBox controls Clear the Text property of the xEndLabel control Send the focus to the xBeginTextBox control xExitButton: End the application

5. See the VB2005\Chap02\lcLanaJones Solution files on the Solutions Disk. (The interface might not contain a Clear button.) Answer using first set of test data: 18 average Answer using second set of test data: 0 average

Task Object Event 1. Calculate average of three numbers xCalcButton Click 2. Display average in xAvgLabel control Clear the screen xClearButton Click End the application xExitButton Click Display the average (from xCalcButton) xAvgLabel None Get and display the first number, second xNum1TextBox, None number, and third number xNum2TextBox, xNum3TextBox

Pseudocode: xCalcButton: Calculate average = (first number + second number + third number) / 3 Display average in xAvgLabel control xClearButton: Clear the Text property of the xNum1TextBox, xNum2TextBox, xNum3TextBox controls Clear the Text property of the xAvgLabel control Send the focus to the xNum1TextBox control xExitButton: End the application

6. See the VB2005\Chap02\lcBookworms Solution files on the Solutions Disk. (The interface might not contain a Clear button.) Answers using first set of test data: $4,000.00 paperback value, $3,750.00 hardcover value, 150 total versions, $7,750.00 total value Answers using second set of test data: $0.00 paperback value, $0.00 hardcover value, 0 total versions, $0.00 total value

Task Object Event 1. Calculate the paperback value, hardcover xCalcButton Click value, total number of paperback and hardcover versions, and total value of the paperback and hardcover versions Programming with VB 2005 3E 9 0-4188-3674-5 2. Display the calculated amounts in the xPaperValLabel, xHardValLabel, xTotalNumLabel, and xTotalValLabel controls Clear the screen xClearButton Click End the application xExitButton Click Display the paperback value, hardcover value, xPaperValLabel, None total number of paperbacks and hardcover xHardValLabel, versions, and total value of paperback and xTotalNumLabel, hardcover versions (from xCalcButton) xTotalValLabel Get and display the title, number of paperback xTitleTextBox, None versions, number of hardcover versions, cost of xNumPaperTextBox, paperback version, cost of hardcover version xNumHardTextBox, xCostPaperTextBox, xCostHardTextBox

Programming with VB 2005 3E 10 0-4188-3674-5 Pseudocode: xCalcButton: Calculate paperback value = number of paperback versions * paperback cost Calculate hardcover value = number of hardcover versions * hardcover cost Calculate total number of paperback and hardcover versions = number of paperback versions + number of hardcover versions Calculate total value of paperback and hardcover versions = paperback value + hardcover value Display paperback value, hardcover value, total number of paperback and hardcover versions, and total value of paperback and hardcover versions in xPaperValLabel, xHardValLabel, xTotalNumLabel, and xTotalValLabel controls xClearButton: Clear the Text property of the xTitleTextBox, xNumPaperTextBox, xNumHardTextBox, xCostPaperTextBox, and xCostHardTextBox controls Clear the Text property of the xPaperValLabel, xHardValLabel, xTotalNumLabel, and xTotalValLabel controls Send the focus to the xTitleTextBox control xExitButton: End the application

7. See the VB2005\Chap02\lcJackets Solution files on the Solutions Disk. (The interface might contain a Clear button.) Answers using first set of test data: 12.50 discount and 37.50 new price Answers using second set of test data: 0.00 discount and 0.00 new price

Task Object Event 1. Calculate the discount and the new price xCalcButton Click 2. Display the discount and the new price in the xDiscountLabel and xNewPriceLabel controls End the application xExitButton Click Display the discount and new price (from xDiscountLabel, None xCalcButton) xNewPriceLabel Get and display the original price xOrigPriceTextBox None

Pseudocode: xCalcButton: Calculate discount = original price * 25% Calculate new price = original price – discount Display the discount in the xDiscountLabel control Display the new price in the xNewPriceLabel control Send the focus to the xOrigPriceTextBox control xExitButton: End the application

8. See the VB2005\Chap02\lcTypingSalon Solution files on the Solutions Disk. (The interface might not contain a Clear button.) Answers using first set of test data: $75.00 total due Answers using second set of test data: $0.00 total due

Task Object Event 1. Calculate the total due xCalcButton Click 2. Display the total due in the xTotalLabel control Clear the screen xClearButton Click End the application xExitButton Click Display the total due (from xCalcButton) xTotalLabel None Get and display the name, number of typed xNameTextBox, None envelopes, and number of typed pages xEnvelopesTextBox, Programming with VB 2005 3E 11 0-4188-3674-5 xPagesTextBox

Programming with VB 2005 3E 12 0-4188-3674-5 Pseudocode: xCalcButton: Calculate total due = number of typed envelopes * .10 + number of typed pages * .25 Display the total due in the xTotalLabel control xClearButton: Clear the Text property of the xNameTextBox, xEnvelopesTextBox, and xPagesTextBox controls Clear the Text property of the xTotalLabel control Send the focus to the xNameTextBox control xExitButton: End the application

Programming with VB 2005 3E 13 0-4188-3674-5 9. See the VB2005\Chap02\lcSun Solution files on the Solutions Disk. (The interface might not contain a Clear button.) Answers using first set of test data: 480.00 gross, 96.00 FWT, 38.40 FICA, 9.60 state tax, 336.00 net Answers using second set of test data: 0.00 gross, 0.00 FWT, 0.00 FICA, 0.00 state tax, 0.00 net

Task Object Event 1. Calculate gross pay, FWT, FICA, state tax, xCalcButton Click and net pay 2. Display the calculated amounts in the xGrossLabel, xFwtLabel, xFicaLabel, xStateLabel, and xNetLabel controls Clear the screen xClearButton Click End the application xExitButton Click Display the gross pay, FWT, FICA, state tax, and xGrossLabel, None net pay (from xCalcButton) xFwtLabel, xFicaLabel, xStateLabel, xNetLabel Get and display the name, hours worked, and rate xNameTextBox, None of pay xHoursTextBox, xRateTextBox

Pseudocode: xCalcButton: Calculate the gross pay = hours worked * rate of pay Calculate the FWT = gross pay * 20% Calculate the FICA = gross pay * 8% Calculate the state tax = gross pay * 2% Calculate the net pay = gross pay – FWT – FICA – state tax Display the gross pay in the xGrossLabel control Display the FWT in the xFwtLabel control Display the FICA in the xFicaLabel control Display the state tax in the xStateLabel control Display the net pay in the xNetLabel control

xClearButton: Clear the Text property of the xNameTextBox, xHoursTextBox, and xRateTextBox controls Clear the Text property of the xGrossLabel, xFwtLabel, xFicaLabel, xStateLabel, and xNetLabel controls Send the focus to the xNameTextBox control

xExitButton: End the application

10. See the VB2005\Chap02\lcModified Skate Away Solution files on the Solutions Disk. 11. (Discovery) See the VB2005\Chap02\lcDiscovery Skate Away Solution files on the Solutions Disk. 12. (Discovery) See the VB2005\Chap02\lcColfax Solution files on the Solutions Disk. (The interface might contain a Clear button.) Answer using test data: 7 full boxes and 3 remaining

Task Object Event 1. Calculate the number of full boxes and the xCalcButton Click number remaining 2. Display the number of full boxes and the number remaining in the xFullLabel and xRemainLabel controls End the application xExitButton Click Display the number of full boxes and the number xFullLabel, None remaining (from xCalcButton) xRemainLabel Get and display the inventory quantity and the xQuantityTextBox, None number that can be packed in a box xBoxTextBox

Programming with VB 2005 3E 14 0-4188-3674-5 Pseudocode: xCalcButton: Calculate the number of full boxes = inventory quantity \ number that can be packed in a box Calculate the number remaining = inventory quantity Mod number that can be packed in a box (Note: the student also could use the following equation: inventory quantity – number of full boxes * number that can be packed in a box) Display the number of full boxes in the xFullLabel control Display the number remaining in the xRemainLabel control Send the focus to the xQuantityTextBox control xExitButton: End the application

13. (Debugging) See the VB2005\Chap02\lcDebug Skate Away Solution files on the Solutions Disk.

Programming with VB 2005 3E 15 0-4188-3674-5 Chapter 3 – Lesson A

Questions 1. d Both b and c. 2. a literal constant 3. c Object 4. d Private 5. d Static score As Integer 6. b Dim city As String 7. d Double.TryParse(Me.xSalesTextBox.Text, sales) 8. a Const Rate As Double = .09 9. d None of the above. 10. b Option Strict On

Exercises In Exercises 1 through 4, the variable’s name and data type may vary. 1. Dim itemName As String Dim price As Decimal 2. Dim item As String Dim height As Decimal Dim weight As Integer 3. Dim item As String Dim beginStock As Integer Dim purchased As Integer Dim sold As Integer Dim endStock As Integer 4. Private partNumber As String Private cost As Decimal 5. city = “Miami” 6. itemName = “Desk” quantityInStock = 40 quantityOnOrder = 20 7. totalSales = northSales + southSales 8. salary = salary * 1.5D 9. Private employeeName As String The statement should be entered in the form’s Declarations section. The variable is a module-level variable. 10. Const TaxRate As Decimal = .05D 11. Integer.TryParse(Me.xUnitsTextBox.Text, numberOfUnits) 12. Me.xUnitsLabel.Text = Convert.ToString(numberOfUnits) 13. totalSales = Convert.ToString(westSales + eastSales) 14. (Discovery) See the VB2005\Chap03\laScope Solution files on the Solutions Disk. c. The number 500 appears in the xSalesLabel control. The procedure-level sales variable is removed from memory. h. The number zero appears because the assignment statement in the xComm5Button’s Click event procedure multiplies the contents of the sales variable (0) by .05, and then displays the result (0) in the xCommissionLabel control. When the xComm5Button’s Click event procedure ends, the sales variable declared in the procedure is removed from memory. q. When the application ends, the module-level sales variable is removed from memory. 15. (Debugging) See the VB2005\Chap03\laCount Solution files on the Solutions Disk. f. You can use either a module-level variable or a static variable. The static variable is the preferred way.

Programming with VB 2005 3E 16 0-4188-3674-5 Chapter 3 – Lesson B

Questions 1. d All of the above. 2. d & 3. a Me.xRegionLabel.Text = region1 & region2 4. c Me.xAddressLabel.Text = cityName & “, ” & stateName 5. c ControlChars.NewLine 6. a AcceptButton 7. a Double.TryParse(InputBox(“Enter a number:”, “Number”), number) 8. c cityName = Inputbox(“Enter the city:”, “City”) 9. b sentence capitalization 10. b Me.xSalesLabel.Text = sales.ToString(“N2”)

Exercises 1. See the VB2005\Chap03\lbModified Skate Away Solution files on the Solutions Disk. 2. See the VB2005\Chap03\lbCommission Solution files on the Solutions Disk. 3. See the VB2005\Chap03\lbMingo Solution files on the Solutions Disk. 4. See the VB2005\Chap03\lbModified Mingo Solution files on the Solutions Disk. 5. See the VB2005\Chap03\lbIMY Solution files on the Solutions Disk. 6. See the VB2005\Chap03\lbModified IMY Solution files on the Solutions Disk. 7. Me.xAddressLabel.Text = cityName & “, ” & stateName 8. Me.xAddressLabel.Text = Message & “ ” & stateName & “ is ” & cityName & “.” 9. Me.xAddressLabel.Text = “My ZIP code is ” & zipCode & “.” 10. (Discovery) See the VB2005\Chap03\lbCancel Solution files on the Solutions Disk.

Chapter 3 – Lesson C

Questions 1. b static 2. d Static counter as Integer 3. d TextChanged 4. a Private Sub GetNumber(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNum1TextBox.Click, xNum2TextBox.Click

Exercises 1. See the VB2005\Chap03\lcName Solution files on the Solutions Disk. 2. See the VB2005\Chap03\lcPennies Solution files on the Solutions Disk. 3. See the VB2005\Chap03\lcChange Solution files on the Solutions Disk. 4. See the VB2005\Chap03\lcCurrency Calculator Solution files on the Solutions Disk. 5. (Discovery) See the VB2005\Chap03\lcConversion Functions Solution files on the Solutions Disk. The TryParse method can handle invalid data (such as a letter), whereas the conversion functions cannot. 6. (Debugging) See the VB2005\Chap03\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must include parentheses around the test1 + test2 + test3 expression.

Programming with VB 2005 3E 17 0-4188-3674-5 Chapter 4 – Lesson A

Questions 1. d only the false path in the If…Then…Else statement 2. b cost > 100 AndAlso cost <= 1000 3. d Me.xNameTextBox.Text.ToUpper = “BOB” 4. 4 Xor 2 And 1 Not 3 Or 2 AndAlso 3 OrElse 5. 1 Arithmetic 3 Logical 2 Comparison 6. b False 7. a True 8. b False 9. b False 10. a True 11. a True 12. c 180 13. d 3000 14. b True 15. b True

Programming with VB 2005 3E 18 0-4188-3674-5 Exercises 1.

start

F T if hours > 40

display display “Regular pay” “Overtime pay”

stop

2. If Me.xCarTextBox.Text.ToUpper = “GRAND AM” Then Me.xCarMakeLabel.Text = “Pontiac” End If 3. If String.IsNullOrEmpty(Me.xZipTextBox.Text) Then Me.xMsgLabel.Text = “Please enter your ZIP code” End If 4. If isSalesOk Then Me.xMsgLabel.Text = Convert.ToString(sales * .1) Else Me.xMsgLabel.Text = “Please enter a number” End If 5. If units < 0 Then Me.xMessageLabel.Text = “Entry error” Else Me.xMessageLabel.Text = “Valid Number” End If 6. If quantity < 10 Then Me.xMessageLabel.Text = “Reorder” Else Me.xMessageLabel.Text = “OK” End If 7. If sales <= 250 Then bonus = 10 Else bonus = 15 End If 8. If state.ToUpper = “HAWAII” Then Me.xShippingLabel.Text = “25” Else Me.xShippingLabel.Text = “50” Programming with VB 2005 3E 19 0-4188-3674-5 End If

Programming with VB 2005 3E 20 0-4188-3674-5 9.

start

F T if state is Colora do

display sales * . display sales * . 04 03

stop

If state.ToUpper = “COLORADO” Then Me.xSalesTaxLabel.Text = Convert.ToString(.03 * sales) Else Me.xSalesTaxLabel.Text = Convert.ToString(.04 * sales) End If 10. if the hours worked are greater than 40 calculate gross pay = hours worked * pay rate + (hours worked - 40) * pay rate/2 else calculate gross pay = hours worked * pay rate end if display the gross pay If hours > 40D Then gross = hours * hourRate + (hours – 40D) * hourRate/2D Else gross = hours * hourRate End If Me.xGrossLabel.Text = Convert.ToString(gross)

Programming with VB 2005 3E 21 0-4188-3674-5 11.

start

F T if animal is “D”

display “Cat” display “Dog”

stop

If animal.ToUpper = “D” Then Me.xAnimalLabel.Text = “Dog” Else Me.xAnimalLabel.Text = “Cat” End If 12. if the item is a desk and the state is Colorado calculate discount = sales * .1 display discount end if

If item.ToUpper = “DESK” AndAlso state.ToUpper = “COLORADO” Then discount = sales * .1 Me.xDiscountLabel.Text = discount.ToString(“C2”) End If 13. If itemColor.ToUpper = “RED” AndAlso item.ToUpper = “SHIRT” Then increase = .02D * origPrice Else increase = .01D * origPrice End If newPrice = origPrice + increase Me.xOriginalLabel.Text = origPrice.ToString(“N2”) Me.xIncreaseLabel.Text = increase.ToString(“N2”) Me.xNewLabel.Text = newPrice.ToString(“N2”) 14. If marySales < jeffSales Then Dim temp As Decimal temp = marySales marySales = jeffSales jeffSales = temp End If 15. See the VB2005\Chap04\laModified AddSub Solution files on the Solutions Disk. Programming with VB 2005 3E 22 0-4188-3674-5 16. See the VB2005\Chap04\laBonus Solution files on the Solutions Disk. 17. See the VB2005\Chap04\laSum Solution files on the Solutions Disk. 18. (Discovery) See the VB2005\Chap04\laCharCase Solution files on the Solutions Disk. Chapter 4 – Lesson B

Questions 1. a When you delete a group box, the controls contained within the group box remain on the form. 2. c 5.0 3. d All of the above. 4. b Financial.Pmt(.09/4, 3 * 4, 6000, 0, DueDate.BegOfPeriod) 5. b -Financial.Pmt(.03/12, 120, 0, 50000, DueDate.BegOfPeriod) 6. c icon 7. c MessageBoxIcon.Exclamation 8. a an OK button and the Information Message icon 9. d None of the above. 10. a Windows.Forms.DialogResult.OK

Exercises 1. See the VB2005\Chap04\lbWeekly Savings Solution files on the Solutions Disk. 2. See the VB2005\Chap04\lbMingo Solution files on the Solutions Disk. 3. (Discovery) c. In addition to the MessageBoxIcon.Exclamation constant, the MessageBoxIcon.Warning constant displays the Warning Message icon. d. The MessageBoxIcon.Asterisk and MessageBoxIcon.Information constants display the Information Message icon. e. The MessageBoxIcon.Error, MessageBoxIcon.Hand, and MessageBoxIcon.Stop constants display the Stop Message icon. f. The MessageBoxIcon.Question constant displays a symbol consisting of a question mark in a circle. Chapter 4 – Lesson C

Questions 1. b KeyPress 2. c e.Handled = True 3. d If e.KeyChar = ControlChars.Back Then 4. b If e.KeyChar = “$” Then 5. b Enter 6. a Me.xCityTextBox.SelectAll()

Exercises 1. See the VB2005\Chap04\lcMicro Solution files on the Solutions Disk. 2. See the VB2005\Chap04\lcState ID Solution files on the Solutions Disk. 3. See the VB2005\Chap04\lcAllenton Solution files on the Solutions Disk. 4. See the VB2005\Chap04\lcSkate Away Solution – Ex4 files on the Solutions Disk. 5. See the VB2005\Chap04\lcSkate Away Solution – Ex5 files on the Solutions Disk. 6. See the VB2005\Chap04\lcMessageBox Value Solution files on the Solutions Disk. 7. (Discovery) See the VB2005\Chap04\lcDiscovery Bonus Solution files on the Solutions Disk. 8. (Discovery) See the VB2005\Chap04\lcZip Solution files on the Solutions Disk. (The student will need to set the text box control’s MaxLength property.) 9. (Debugging) See the VB2005\Chap04\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must include parentheses around e.KeyChar < "0" OrElse e.KeyChar > "9" in the

Programming with VB 2005 3E 23 0-4188-3674-5 CancelKeys procedure, and also around code = “1” OrElse code = “2” in the xCalcButton Click event procedure.

Programming with VB 2005 3E 24 0-4188-3674-5 Chapter 5 – Lesson A

Questions 1. c 180 2. d 3000 3. b 200 4. c Mark 5. b Jerry 6. c Mark 7. d Sue 8. c either the true path or the false path 9. d All of the above. 10. b Mark 11. b Mark 12. d Sue 13. a If sender Is Me.xNameTextBox Then 14. d If TypeOf sender Is Label Then 15. a If partNum Like “??#” Then 16. a If item.ToUpper = “SHIRT” OrElse item.ToUpper = “SKIRT” Then 17. c If Me.xRateTextBox.Text Like “*%” Then 18. The decision regarding the member status is the primary decision. The decision regarding the day of the week is the secondary decision, because whether it needs to be made depends on the result of the member status decision. 19. The three errors commonly made when writing selection structures are: 1. Using a logical operator when a nested selection structure is needed 2. Reversing the primary and secondary decisions 3. Using an unnecessary nested selection structure The “Using an unnecessary nested selection structure” error makes the selection structure inefficient, but not incorrect. 20. Desk-checking, also called hand-tracing, means that you use sample data to walk through each of the steps in the algorithm manually, just as though you were the computer.

Programming with VB 2005 3E 25 0-4188-3674-5 Exercises 1. Dim code As String Dim sales As Decimal Dim bonus As Decimal code = Me.xCodeTextBox.Text Decimal.TryParse(Me.xSalesTextBox.Text, sales) bonus = sales * .08D If code.ToUpper = “X” Then If sales >= 10000 Then bonus = bonus + 150D Else bonus = bonus + 125D End If End If Me.xMsgLabel.Text = bonus.ToString(“N2”) 2. If score >= 90 Then Me.xMsgLabel.Text = "Highest honors" ElseIf score >= 70 Then Me.xMsgLabel.Text = “Good job” Else Me.xMsgLabel.Text = "Retake the test" End If 3. If quantity = 10 Then Me.xMsgLabel.Text = “Equal” ElseIf quantity > 10 Then Me.xMsgLabel.Text = “Over 10” Else Me.xMsgLabel.Text = “Not over 10” End If 4. Integer.TryParse(Me.xCodeTextBox.Text, code) Decimal.TryParse(Me.xSalesTextBox.Text, sales) If code = 1 OrElse code = 2 Then Me.xMsgLabel.Text = Convert.ToString(sales * .12D) ElseIf code = 3 Then Me.xMsgLabel.Text = Convert.ToString(sales * .15D) ElseIf code = 4 Then Me.xMsgLabel.Text = Convert.ToString(sales * .2D) Else Me.xMsgLabel.Text = “Error” End If 5. Integer.TryParse(Me.xCodeTextBox.Text, code) Decimal.TryParse(Me.xSalesTextBox.Text, sales) Select Case code Case 1 Me.xMsgLabel.Text = Convert.ToString(sales * .02D) Case 2 To 4 Me.xMsgLabel.Text = Convert.ToString(sales * .05D) Case 5 Me.xMsgLabel.Text = Convert.ToString(sales * .1D) Case 6 To 7 Me.xMsgLabel.Text = Convert.ToString(sales * .15D) Case Else Me.xMsgLabel.Text = “Error” End Select 6. Select Case state Case “HAWAII” shipCharge = 25.0

Programming with VB 2005 3E 26 0-4188-3674-5 Case “OREGON” shipCharge = 30.0 Case “CALIFORNIA” shipCharge = 32.5 Case Else shipCharge = 0.0 Me.xMsgLabel.Text = “Incorrect state” End Select 7. If state = “HAWAII” Then shipCharge = 25.0 ElseIf state = “OREGON” Then shipCharge = 30.0 ElseIf state = “CALIFORNIA” Then shipCharge = 32.5 Else shipCharge = 0.0 Me.xMsgLabel.Text = “Incorrect state” End If 8. Select Case seatLoc Case “BOX” Me.xPriceLabel.Text = “$75.00” Case “PAVILION” Me.xPriceLabel.Text = “$30.00” Case “LAWN” Me.xPriceLabel.Text = “$21.00” Case Else Me.xPriceLabel.Text = “Incorrect seat location” End Select 9. If seatLoc = “BOX” Then Me.xPriceLabel.Text = “$75.00” ElseIf seatLoc = “PAVILION” Then Me.xPriceLabel.Text = “$30.00” ElseIf seatLoc = “LAWN” Then Me.xPriceLabel.Text = “$21.00” Else Me.xPriceLabel.Text = “Incorrect seat location” End If 10. If zipCode Like “605##” Then shipCharge = 25.0 ElseIf zipCode Like “606##” Then shipCharge = 30.0 Else shipCharge = 35.0 End If 11. Select Case True Case zipCode Like “605##” shipCharge = 25.0 Case zipCode Like “606##” shipCharge = 30.0 Case Else shipCharge = 35.0 End Select 12. If sender Is xAlabamaButton Then Me.xCapitalLabel.Text = “Montgomery” ElseIf sender Is xArizonaButton Then Me.xCapitalLabel.Text = “Phoenix” ElseIf sender Is xIllinoisButton Then Me.xCapitalLabel.Text = “Springfield” Else Programming with VB 2005 3E 27 0-4188-3674-5 Me.xCapitalLabel.Text = “Salem” End If 13. Select Case True Case sender Is xAlabamaButton Me.xCapitalLabel.Text = “Montgomery” Case sender Is xArizonaButton Me.xCapitalLabel.Text = “Phoenix” Case sender Is xIllinoisButton Me.xCapitalLabel.Text = “Springfield” Case Else Me.xCapitalLabel.Text = “Salem” End Select 14. See the VB2005\Chap05\laAnimal Solution files on the Solutions Disk. 15. See the VB2005\Chap05\laMonth Solution files on the Solutions Disk. 16. See the VB2005\Chap05\laBonus Solution files on the Solutions Disk. 17. See the VB2005\Chap05\laSeminar Solution files on the Solutions Disk. Chapter 5 – Lesson B

Questions 1. b two 2. b sentence capitalization 3. b False 4. b two 5. d six 6. a Checked 7. c Dim numberRandom As New Random 8. b number = randomGenerator.Next(1, 26) 9. a Call 10. d Me.xAlaskaRadioButton.PerformClick()

Exercises 1. See the VB2005\Chap05\lbMath Solution-PerformClick files on the Solutions Disk. 2. See the VB2005\Chap05\lbCapitals Solution files on the Solutions Disk. 3. See the VB2005\Chap05\lbJuarez Solution files on the Solutions Disk. 4. See the VB2005\Chap05\lbFat Calculator Solution files on the Solutions Disk. 5. (Discovery) See the VB2005\Chap05\lbRandom Float Solution files on the Solutions Disk. Chapter 5 – Lesson C

Questions 1. d None of the above. 2. a Checked 3. a True 4. b False

Exercises 1. See the VB2005\Chap05\lcModified Math Solution files on the Solutions Disk. 2. See the VB2005\Chap05\lcHealth Solution files on the Solutions Disk. 3. See the VB2005\Chap05\lcWashington Solution files on the Solutions Disk. 4. See the VB2005\Chap05\lcBarren Solution files on the Solutions Disk. 5. See the VB2005\Chap05\lcGolf Pro Solution files on the Solutions Disk. 6. See the VB2005\Chap05\lcMarshall Solution files on the Solutions Disk.

Programming with VB 2005 3E 28 0-4188-3674-5 7. See the VB2005\Chap05\lcWillow Solution files on the Solutions Disk. 8. See the VB2005\Chap05\lcJohnson Solution files on the Solutions Disk. 9. See the VB2005\Chap05\lcLottery Solution files on the Solutions Disk. 10. See the VB2005\Chap05\lcFerris Solution files on the Solutions Disk. 11. (Debugging) See the VB2005\Chap05\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must modify the Select Case statement as follows: Select Case total Case Is < 100.0 shipping = 0 Case Is < 501.0 shipping = 10 Case Is < 1001.0 shipping = 7 Case Else shipping = 5 End Select

Programming with VB 2005 3E 29 0-4188-3674-5 Chapter 6 – Lesson A

Questions 1. b 4 2. c 12 3. c either a or b 4. a posttest, pretest 5. d All of the above. 6. a 0 7. b 1 8. a (sequence) and b (selection) 9. a (sequence) and c (repetition) 10. a (sequence) and b (selection) 11. a (sequence) and b (selection) and c (repetition) 12. c priming

Exercises 1. Do While quantity > 0 2. Do Until quantity <= 0 3. Do Until inStock <= reorder 4. Do While inStock > reorder 5. Do While letter.ToUpper = “Y” 6. Do Until letter.ToUpper <> “Y” 7. Do While empName.ToUpper <> “DONE” 8. Do Until empName.ToUpper = “DONE” 9. quantity = quantity + 2 10. total = total – 3 11. totalPurchases = totalPurchases + purchases 12. sales = sales – salesReturns 13. For evenNum = 2 To 8 Step 2 Me.xNumbersLabel.Text = _ Me.xNumbersLabel.Text & Convert.ToString(evenNum) & _ ControlChars.NewLine Next evenNum 14. Dim evenNum As Integer = 2 Do While evenNum <= 8 Me.xNumbersLabel.Text = _ Me.xNumbersLabel.Text & Convert.ToString(evenNum) & _ ControlChars.NewLine evenNum = evenNum + 2 Loop 15. Dim evenNum As Integer = 2 Do Me.xNumbersLabel.Text = _ Me.xNumbersLabel.Text & Convert.ToString(evenNum) & _ ControlChars.NewLine evenNum = evenNum + 2 Loop While evenNum <= 8 16. Dim count As Integer = 10 Do While count < 100 Me.xCountLabel.Text = _ Me.xCountLabel.Text & Convert.ToString(count * 2) & _ ControlChars.NewLine count = count + 10 Loop Programming with VB 2005 3E 30 0-4188-3674-5 17. For x = 0 To 117 Step 9 Me.xNumbersLabel.Text = _ Me.xNumbersLabel.Text & Convert.ToString(x) & _ ControlChars.NewLine Next x 18. For x = 2 To 12 Step 2 Me.xiNumbersLabel.Text = _ Me.xNumbersLabel.Text & Convert.ToString(x * x) & _ ControlChars.NewLine Next x 19. 0, 1,2, 3, 4 20. 0, 1, 2, 3, 4, 5 21. The number = number + 1 instruction is missing and should be entered after the MessageBox.Show instruction. 22. The number = number - 1 instruction is missing and should be entered after the MessageBox.Show instruction. 23. 0, 2, 4 24. 1 25. See the VB2005\Chap06\laModified Payment Calculator Solution files on the Solutions Disk. 26. See the VB2005\Chap06\laModified Sales Express Solution files on the Solutions Disk. 27. (Debugging) The salesInput = InputBox(“Enter a sales amount”, “Sales) instruction is missing and should be entered after the MessageBox.Show instruction. 28. (Debugging) The MessageBox.Show instruction should be entered after the Do instruction. Chapter 6 – Lesson B

Questions 1. a *** *** 2. d 30

Exercises 1. See the VB2005\Chap06\lbNested Payment Solution-Ex1 files on the Solutions Disk. 2. See the VB2005\Chap06\lbNested Payment Solution-Ex2 files on the Solutions Disk. 3. See the VB2005\Chap06\lbGrade Calculator Solution files on the Solutions Disk.

Chapter 6 – Lesson C

Questions 1. a Add 2. a Items 3. b SelectedIndex 4. d both a and c 5. c SelectedValueChanged

Exercises 1. See the VB2005\Chap06\lcModified Shoppers Haven Solution files on the Solutions Disk. 2. See the VB2005\Chap06\lcPowder Solution files on the Solutions Disk. 3. See the VB2005\Chap06\lcRandom Solution files on the Solutions Disk. 4. See the VB2005\Chap06\lcPhone Solution files on the Solutions Disk. 5. See the VB2005\Chap06\lcModified Phone Solution files on the Solutions Disk. 6. See the VB2005\Chap06\lcFibonacci Solution files on the Solutions Disk.

Programming with VB 2005 3E 31 0-4188-3674-5 7. See the VB2005\Chap06\lcMultiplication Solution files on the Solutions Disk. 8. See the VB2005\Chap06\lcGPA Solution files on the Solutions Disk. 9. (Discovery) See the VB2005\Chap06\lcMulti Solution files on the Solutions Disk. 10. (Discovery) See the VB2005\Chap06\lcItems Solution files on the Solutions Disk. 11. (Discovery) See the VB2005\Chap06\lcListBox Solution files on the Solutions Disk. 12. (Discovery) See the VB2005\Chap06\lcSonheim Solution files on the Solutions Disk. 13. (Debugging) See the VB2005\Chap06\lcDebug Solution files on the Solutions Disk. Modifications are shaded in the following code. Private Sub xEnterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xEnterButton.Click ' displays the number of positive integers, the number of negative integers, ' and the number of zeros entered

Dim inputNumber As String Dim number As Integer Dim positiveCounter As Integer Dim negativeCounter As Integer Dim zeroCounter As Integer Dim isConverted As Boolean inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _ "Number Entry", "0") Do While inputNumber <> String.Empty isConverted = Integer.TryParse(inputNumber, number) If isConverted Then ' update appropriate counter If number > 0 Then positiveCounter = positiveCounter + 1 ElseIf number < 0 Then negativeCounter = negativeCounter + 1 Else zeroCounter = zeroCounter + 1 End If Else MessageBox.Show("Please enter a number", "Number Entry", _ MessageBoxButtons.OK, MessageBoxIcon.Information) End If inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _ "Number Entry", "0") Loop

' display counters Me.xPositiveLabel.Text = Convert.ToString(positiveCounter) Me.xNegativeLabel.Text = Convert.ToString(negativeCounter) Me.xZeroLabel.Text = Convert.ToString(zeroCounter) End Sub

Programming with VB 2005 3E 32 0-4188-3674-5 Chapter 7 – Lesson A

Questions 1. a A Function procedure can return one or more values to the statement that called it. 2. a arguments 3. c a parameter 4. b the procedure header 5. a Call CalcArea(length, width) 6. d None of the above. 7. c Private Sub CalcFee(ByVal base As Integer, ByVal rate As Decimal) 8. a one value only 9. d All of the above. 10. c The name of each argument in the Call statement should be identical to the name of its corresponding parameter in the procedure header. 11. a Return stateTax 12. c Private Sub CalcFee(ByVal base As Integer, ByRef rate As Decimal) 13. d Both a and c. 14. c by reference 15. d To pass a variable by reference in Visual Basic, you include the ByRef keyword before the variable’s name in the Call statement. 16. a Private Sub CalcEndingInventory(ByVal b As Integer, ByVal s As Integer, ByVal p As Integer, ByRef final As Integer) 17. a Call CalcEndingInventory(begin, sales, purchases, ending) 18. a True 19. d All of the above. 20. c grossPay = Calculate(hours, rate) 21. Unlike a Sub procedure, a Function procedure returns a value when it has completed its task. 22. When you pass a variable by value, you are passing only the contents of the variable; the receiving procedure cannot access the variable and cannot change its contents. When you pass a variable by reference, you are passing the address of the variable in the computer’s internal memory; the receiving procedure can access the variable and can change its contents. To pass a variable by value, you include the keyword ByVal before the variable’s name in the procedure header. To pass a variable by reference, you include the keyword ByRef before the variable’s name in the procedure header.

Exercises 1. Private Sub HalveNumber(ByVal num As Integer) Me.xNumLabel.Text = Convert.ToString(num / 2) End Sub 2. Call HalveNumber(87) 3. Private Sub GetCity(ByRef cityName As String) cityName = InputBox(“Enter the city name:”, “City Name”) End Sub 4. Call GetCity(city) 5. Private Sub CalcSumAndDiff(ByVal num1 As Integer, ByVal num2 As Integer, ByRef sum As Integer, ByRef diff As Integer) sum = num1 + num2 diff = num1 – num2 End Sub 6. Call CalcSumAndDiff(firstNum, secondNum, sum, difference) 7. Private Sub CalcQuotient(ByVal num1 As Decimal, ByVal num2 As Decimal, ByRef quotient As Decimal) quotient = num1 / num2 End Sub Programming with VB 2005 3E 33 0-4188-3674-5 8. Private Function DivideNumber(ByVal num As Integer) As Double Return num / 2 End Function 9. answer = DivideNumber(number) 10. Private Function GetState() As String Dim state As String state = InputBox(“State name:”, “State Name”) Return state End Function 11. MessageBox.Show(GetState()) 12. Private Function CalcAverage(ByVal number1 As Integer, ByVal number2 As Integer, ByVal number3 As Integer, ByVal number4 As Integer) As Decimal Return (number1 + number2 + number3 + number4) / 4 End Function 13. average = CalcAverage(num1, num2, num3, num4) 14. See the VB2005\Chap07\laPassing Solution files on the Solutions Disk. In Step c, the xDisplayButton’s Click event procedure does not display your name because the myName variable was passed by value. In Step e, the xDisplayButton’s Click event procedure displays your name because the myName variable was passed by reference. 15. See the VB2005\Chap07\laRainfall Solution files on the Solutions Disk. 16. See the VB2005\Chap07\laModified Gross Pay Solution files on the Solutions Disk. 17. See the VB2005\Chap07\laModified Pine Lodge Solution files on the Solutions Disk. 18. See the VB2005\Chap07\laModified Rainfall Solution files on the Solutions Disk. 19. See the VB2005\Chap07\laTemperature Solution files on the Solutions Disk. 20. See the VB2005\Chap07\laModified Temperature Solution files on the Solutions Disk. 21. (Discovery) See the VB2005\Chap07\laOptional Solution files on the Solutions Disk. Chapter 7 – Lesson B

Questions 1. a Add 2. b DropDownStyle 3. a Items 4. d All of the above. 5. c Text 6. b Math.Round(number, 3) 7. d Sorted 8. d TextChanged

Exercises 1. See the VB2005\Chap07\lbSub Harvey Industries Solution files on the Solutions Disk. 2. See the VB2005\Chap07\lbModified Harvey Industries Solution files on the Solutions Disk. 3. See the VB2005\Chap07\lbNo Rounding Harvey Industries Solution files on the Solutions Disk. Chapter 7 – Lesson C

Questions 1. d FormClosing 2. d FormClosing 3. c e.Cancel = True

Exercises 1. See the VB2005\Chap07\lcFormClosing Gross Pay Solution.

Programming with VB 2005 3E 34 0-4188-3674-5 2. See the VB2005\Chap07\lcFormClosing Pine Lodge Solution files on the Solutions Disk. 3. (Debugging) See the VB2005\Chap07\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must add the statement Return result to the GetArea function.

Programming with VB 2005 3E 35 0-4188-3674-5 Chapter 8 – Lesson A

Questions 1. d Both b and c 2. a state = state.Remove(2, 3) 3. a amount = amount.Trim(“$”c, “%”c) 4. c partNum.StartsWith(“A”) 5. d partNum.ToUpper.EndsWith(“B”) 6. c code = partNum.Substring(0, 3) 7. d All of the above. 8. c zip = zip.Replace(“1”, “3”) 9. d All of the above. 10. d None of the above. 11. b word = word.Insert(2, “a”) 12. c 10 13. d None of the above. 14. d newMessage = message.PadRight(13, “!”c) 15. c 0

Exercises 1. a. Me.xSizeLabel.Text = Convert.ToString(message.Length) b. city = city.TrimStart c. number = number.Trim d. amount = amount.TrimEnd(“ ”c, “,”c, “.”c) e. fullName = fullName.Remove(0, 2) f. Mid(word, 4) = “th” g. word = word.Insert(0, “a”) h. pay = pay.PadLeft(10, “*”c) 2. If inputRate.EndsWith(“%”) Then inputRate = inputRate.TrimEnd(“%”c) End If 3. code = part.Substring(4, 2) 4. amount = amount.Replace(“,”, “”) 5. indexNum = address.ToUpper.IndexOf(“ELM STREET”) 6. isContained = address.ToUpper().Contains(“ELM STREET”) 7. result = String.Compare(item, itemOrdered) 8. See the VB2005\Chap08\laCity Names Solution files on the Solutions Disk. 9. See the VB2005\Chap08\laSocial Security Solution files on the Solutions Disk. 10. See the VB2005\Chap08\laModified Social Security Solution files on the Solutions Disk. 11. See the VB2005\Chap08\laPhone Solution files on the Solutions Disk. 12. See the VB2005\Chap08\laItem Prices Solution files on the Solutions Disk. 13. See the VB2005\Chap08\laDate Solution files on the Solutions Disk. 14. See the VB2005\Chap08\laSales Tax Solution files on the Solutions Disk. 15. See the VB2005\Chap08\laPart Number Solution files on the Solutions Disk. 16. See the VB2005\Chap08\laCount Solution files on the Solutions Disk. 17. See the VB2005\Chap08\laName Solution files on the Solutions Disk. 18. See the VB2005\Chap08\laAlphabet Solution files on the Solutions Disk. Chapter 8 – Lesson B

Programming with VB 2005 3E 36 0-4188-3674-5 Questions 1. b a separator bar 2. a an access key 3. c A shortcut key 4. c You should assign a shortcut key to commonly used menu titles. 5. A menu item’s access key can be used only when the menu is open. A menu item’s shortcut key can be used only when the menu is closed.

Exercises 1. See the VB2005\Chap08\lbCommission Solution files on the Solutions Disk. Chapter 8 – Lesson C

Questions 1. b For indexNum As Integer = 0 To name.Length - 1 2. d Mid(name, 1) = “C” 3. a True

Exercises 1. See the VB2005\Chap08\lcHangman Game Solution-Ex1 files on the Solutions Disk. 2. See the VB2005\Chap08\lcHangman Game Solution-Ex2 files on the Solutions Disk. 3. See the VB2005\Chap08\lcPig Latin Solution files on the Solutions Disk. 4. See the VB2005\Chap08\lcGeorgetown Solution files on the Solutions Disk. 5. See the VB2005\Chap08\lcJacobson Solution files on the Solutions Disk. 6. See the VB2005\Chap08\lcBobCat Motors Solution files on the Solutions Disk. 7. (Debugging) See the VB2005\Chap08\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must modify the Remove method in the xDisplayButton’s Click event procedure, as shown here: city = address.Remove(indexNum)

Programming with VB 2005 3E 37 0-4188-3674-5 Chapter 9 – Lesson A

Questions 1. a Dim amounts(4) As Double 2. d Do While x <= 20 3. b replace the 500 amount with 510 4. d If x >= 0 AndAlso x <= 4 Then 5. d None of the above. 6. a Array.Sort(sales) 7. b Do While x < 4 total = total + numbers(x) x = x + 1 Loop avg = Convert.ToDecimal(total / x) 8. a 0 9. c 6 10. b 5 11. d 8 12. d elements = numbers.Length

Exercises 1. Dim numbers(19) As Integer numbers(1) = 7 2. Private products(9) As String products(2) = “Paper” 3. Dim rates As Double = {6.5, 8.3, 4, 2, 10.5} 4. For x As Integer = 0 To 4 Me.xRatesLabel.Text = Me.xRatesLabel.Text & _ Convert.ToString(rates(x)) & ControlChars.NewLine Next x

Dim x As Integer Do While x <= 4 Me.xRatesLabel.Text = Me.xRatesLabel.Text & _ Convert.ToString(rates(x)) & ControlChars.NewLine x = x + 1 Loop

For Each x As Integer in rates Me.xRatesLabel.Text = Me.xRatesLabel.Text & _ Convert.ToString(x) & ControlChars.NewLine Next x 5. Array.Sort(rates) 6. Array.Reverse(rates) 7. For x As Integer = 0 To 4 total = total + rates(x) Next x Me.xAverageLabel.Text = Convert.ToString(total / x)

Dim x As Integer Do While x <= 4 total = total + rates(x) x = x + 1 Loop Me.xAverageLabel.Text = Convert.ToString(total / x)

Programming with VB 2005 3E 38 0-4188-3674-5 For Each x As Integer in rates total = total + x Next x Me.xAverageLabel.Text = Convert.ToString(total / rates.length) 8. Dim x As Integer Do While x <= 4 rates(x) = rates(x) - 1 x = x + 1 Loop

For x As Integer = 0 To 4 rates(x) = rates(x) - 1 Next x

For Each x As Integer in rates x = x - 1 Next x 9. See the VB2005\Chap09\laLowest Solution-ForNext, laLowest Solution-ForEachNext, laLowest Solution- DoLoop files on the Solutions Disk. 10. See the VB2005\Chap09\laUpdate Prices Solution files on the Solutions Disk. 11. See the VB2005\Chap09\laModified Update Prices Solution files on the Solutions Disk. 12. See the VB2005\Chap09\laScores Solution files on the Solutions Disk. d. 3 students earned a score of 72 4 students earned a score of 88 1 student earned a score of 20 2 students earned a score of 99 13. See the VB2005\Chap09\laModified Scores Solution files on the Solutions Disk. d. 6 students earned a score between 70 and 79, inclusive 8 students earned a score between 65 and 85, inclusive 2 students earned a score between 0 and 50, inclusive 14. See the VB2005\Chap09\laLottery Game Solution files on the Solutions Disk. 15. (Discovery) See the VB2005\Chap09\laReDim Solution files on the Solutions Disk a. The ReDim statement allows you to reallocate storage space for an array variable. In other words, it allows you to dynamically change the size of an array. The Preserve keyword allows you to preserve the data in the existing array when you change the size of only the last dimension. Chapter 9 – Lesson B

Questions 1. a True 2. a capital(1)

Exercises 1. See the VB2005\Chap09\lbCarver Solution files on the Solutions Disk. 2. See the VB2005\Chap09\lbModified Carver Solution files on the Solutions Disk. 3. See the VB2005\Chap09\lbLaury Solution files on the Solutions Disk. Chapter 9 – Lesson C

Questions 1. b Dim letters(3, 1) As String 2. d replace the 800 amount with 810 3. b replace the 2000 amount with 900

Programming with VB 2005 3E 39 0-4188-3674-5 4. d If row >= 0 AndAlso row < 2 AndAlso col >= 0 AndAlso col < 5 Then 5. d states(4, 2) = “California” 6. d All of the above.

Exercises 1. Dim balances(3, 5) As Decimal For row As Integer = 0 To 3 For col As Integer = 0 To 5 balances(row, col) = 10D Next col Next row 2. Dim row As Integer Dim Col As Integer Do While row <= 3 Do While col <= 5 balances(row, col) = 10D col = col + 1 Loop row = row + 1 Loop 3. For Each element As Decimal In balances element = 10D Next element 4. answers(2, 0) = True 5. See the VB2005\Chap09\lcInventory Solution files on the Solutions Disk. 6. See the VB2005\Chap09\lcConway Solution files on the Solutions Disk. 7. See the VB2005\Chap09\lcCount Solution files on the Solutions Disk. 8. See the VB2005\Chap09\lcHighest Solution files on the Solutions Disk. 9. (Debugging) See the VB2005\Chap09\lcDebug Solution files on the Solutions Disk. To debug this solution, the student must insert a comma within the parentheses in the Dim statement that declares the names array. The student also must change the For clause in the For…Next statement to For row As Integer = 0 to 4.

Programming with VB 2005 3E 40 0-4188-3674-5 Chapter 10 – Lesson A

Questions 1. c Structure 2. a Declarations section 3. b address.street = “Maple” 4. d None of the above. 5. a Dim workers(4) As Employee

Exercises 1. Structure Book Public title As String Public author As String Public cost As Decimal End Structure Private fiction As Book 2. Structure Tape Public name As String Public artist As String Public songLength As String Public songNum As Integer End Structure Dim blues As Tape 3. a. Dim homeUse As Computer b. homeUse.model = “IB-50” c. homeUse.cost = 2400D d. Private business(9) As Computer e. business(0).model = “HPP405” f. business(0).cost = 3600D 4. a. Dim school As Friend b. school.first = Me.xFirstTextBox.Text c. school.last = Me.xLastTextBox.Text d. Me.xLastLabel.Text = school.last e. Me.xFirstLabel.Text = school.first f. Private home(4) As Friend g. home(4).first = Me.xFirstTextBox.Text h. home(4).last = Me.xLastTextBox.Text 5. See the VB2005\Chap10\laModified Price List Solution-Structure files on the Solutions Disk. 6. See the VB2005\Chap10\laCarver Solution files on the Solutions Disk. Chapter 10 – Lesson B

Questions 1. b My.Computer.FileSystem.WriteAllText(“address.txt”, Me.xAddressTextBox.Text, False) 2. d fileContents = My.Computer.FileSystem.ReadAllText(“address.txt”) 3. c If My.Computer.FileSystem.FileExists(“address.txt”) Then 4. d All of the above. 5. c My.Computer.FileSystem.WriteAllText(“msg.txt”, Strings.Space(15), True)

Programming with VB 2005 3E 41 0-4188-3674-5 Exercises 1. My.Computer.FileSystem.WriteAllText(“report.txt”, “Employee” & ControlChars.NewLine & “Name” & ControlChars.NewLine”, False) 2. My.Computer.FileSystem.WriteAllText(“geography.txt”, capital & Strings.Space(20) & state & ControlChars.NewLine, False) 3. text = My.Computer.FileSystem.ReadAllText(“report.txt”) 4. Me.xReportLabel.Text = My.Computer.FileSystem.ReadAllText(“report.txt”) 5. If My.Computer.FileSystem.FileExists(“jansales.txt”) Then Me.xMessageLabel.Text = “File exists” Else Me.xMessageLabel.Text = “File does not exist” End If 6. See the VB2005\Chap10\lbEmployee List Solution files on the Solutions Disk. 7. See the VB2005\Chap10\lbMemo Solution files on the Solutions Disk. 8. See the VB2005\Chap10\lbReport Solution files on the Solutions Disk. 9. (Discovery) See the VB2005\Chap10\lbPay Solution files on the Solutions Disk. Chapter 10 – Lesson C

Questions 1. a My.Computer.FileSystem.WriteAllText(“cities.txt”, city & ControlChars.NewLine, True) 2. b Me.xCitiesComboBox.Items.Remove(“Paris”) 3. b My.Computer.FileSystem.DeleteFile(“cities.txt”)

Exercises 1. See the VB2005\Chap10\lcFriends Solution-Erase files on the Solutions Disk. 2. See the VB2005\Chap10\lcFriends Solution-ListBox files on the Solutions Disk. 3. See the VB2005\Chap10\lcGlovers Solution files on the Solutions Disk. 4. See the VB2005\Chap10\lcFriends Solution-Ignore Case files on the Solutions Disk. 5. See the VB2005\Chap10\lcFriends Solution-Modified Add files on the Solutions Disk. 6. See the VB2005\Chap10\lcWKRK Solution files on the Solutions Disk. 7. (Discovery) See the VB2005\Chap10\lcGlovers Solution-Discovery files on the Solutions Disk. 8. (Debugging) See the VB2005\Chap10\lcDebug Solution files on the Solutions Disk. To debug this solution, the student will need to change the For clause in the Click event procedures for the xLastButton, xFirstButton, and xFullButton as follows: For row As Integer = 0 To names.length -1

Programming with VB 2005 3E 42 0-4188-3674-5 Chapter 11 – Lesson A

Questions 1. d A class is considered an object. 2. a class file whose filename ends with .vb 3. d variables 4. a True 5. b False 6. c SetDate 7. c FirstName 8. a default 9. d item.Price = 45 10. c newPrice = item.CalculateNewPrice() 11. a True 12. b using properties created by Property procedures 13. c Public 14. d None of the above. 15. c signature 16. c a Sub procedure 17. d Both b and c. 18. d Call dog.DisplayBreed() 19. c Set 20. a Get

Exercises 1. Public Class Book Public Title As String Public Author As String Public Cost As Decimal End Class 2. Public Class Tape Public Name As String Public Artist As String Public SongNumber As String Public Length As String End Class 3. Private fiction As Book fiction = New Book 4. Dim blues As New Tape 5. a. Dim homeUse As New Computer b. homeUse.Model = “IB-50” c. homeUse.Cost = 2400D d. newPrice = homeUse.IncreasePrice() e. Dim companyUse As New Computer(“IBM”, 1236.99D) 6. Public Class Employee Private _name As String Private _salary As Decimal

Public Property EmpName() As String Get Return _name End Get Set(ByVal value As String) _name = value

Programming with VB 2005 3E 43 0-4188-3674-5 End Set End Property

Public Property Salary() As Decimal Get Return _salary End Get Set(ByVal value As Decimal) _salary = value End Set End Property

Public Sub New() _name = String.Empty _salary = 0D End Sub

Public Sub New(ByVal n As String, ByVal s As Decimal) EmpName = n Salary = s End Sub End Class 7. Public Class Employee Private _name As String Private _salary As Decimal

Public Property EmpName() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property

Public Property Salary() As Decimal Get Return _salary End Get Set(ByVal value As Decimal) _salary = value End Set End Property

Public Sub New() _name = String.Empty _salary = 0D End Sub

Public Sub New(ByVal n As String, ByVal s As Decimal) EmpName = n Salary = s End Sub

Public Function CalculateNewSalary(ByVal percent As Decimal) As Decimal Dim newSalary As Decimal If percent >= 0 Then newSalary = _salary + _salary _ * (percent / 100D) Programming with VB 2005 3E 44 0-4188-3674-5 Else newSalary = 0D End If Return newSalary End Function End Class 8. Public ReadOnly Property BonusRate() As Decimal Get Return _bonusRate End Get End Property 9. See the VB2005\Chap11\laModified Area Solution files on the Solutions Disk. 10. See the VB2005\Chap11\laModified Grade Solution files on the Solutions Disk. 11. See the VB2005\Chap11\laModified Personnel Solution files on the Solutions Disk. 12. See the VB2005\Chap11\laModified Salary Solution files on the Solutions Disk. 13. See the VB2005\Chap11\laModified Sweets Solution files on the Solutions Disk. Chapter 11 – Lesson B

Questions 1. b overloaded 2. c Overloads 3. a Inherits Animal 4. c Public Overridable Sub CalcBonus() 5. d Public Overrides Sub CalcBonus()

Exercises 1. See the VB2005\Chap11\lbModified ABC Solution-Inheritance files on the Solutions Disk. 2. See the VB2005\Chap11\lbArea Solution-Overloads files on the Solutions Disk. Chapter 11 – Lesson C

Questions 1. b False 2. a _location = “Unknown” 3. b Capital = capName

Exercises 1. See the VB2005\Chap11\lcModified Kessler Solution files on the Solutions Disk. 2. See the VB2005\Chap11\lcFence Solution files on the Solutions Disk. 3. See the VB2005\Chap11\lcPool Solution files on the Solutions Disk. 4. See the VB2005\Chap11\lcMath Solution files on the Solutions Disk. 5. See the VB2005\Chap11\lcMayflower Solution files on the Solutions Disk. 6. See the VB2005\Chap11\lcModified Mayflower Solution files on the Solutions Disk. 7. See the VB2005\Chap11\lcFranklin Calendars Solution files on the Solutions Disk. 8. (Discovery) See the VB2005\Chap11\lcModified Pool Solution files on the Solutions Disk. 9. (Discovery) See the VB2005\Chap11\lcPennington Solution files on the Solutions Disk. 10. See the VB2005\Chap11\lcDebug Solution files on the Solutions Disk. To debug the solution, the student will need to add the Set block in the Id and Price Property procedures. The student will also need to make three changes in the xCalcButton’s Click event procedure. First, the student will need to change Computer.Price to computerPurchased.Price. Second, the student will need to change Computer.Id to computerPurchased.Id. Third, the student will need to change Computer.CalcNewPrice(rate) to computerPurchased.CalcNewPrice(rate). Programming with VB 2005 3E 45 0-4188-3674-5 Programming with VB 2005 3E 46 0-4188-3674-5 Chapter 12 – Lesson A

Questions 1. a foreign key in the child table 2. b binding 3. d TableAdapter 4. b BindingSource object’s Position 5. c MovePrevious() 6. d All of the above are true. 7. b BindingSource 8. d All of the above.

Exercises 1. See the VB2005\Chap12\laModified Morgan Industries Solution-Labels files on the Solutions Disk. 2. See the VB2005\Chap12\laCartwright Solution files on the Solutions Disk. 3. See the VB2005\Chap12\laAddison Playhouse Solution files on the Solutions Disk. 4. See the VB2005\Chap12\laMorgan Industries Solution-ListBox files on the Solutions Disk. 5. (Discovery) See the VB2005\Chap12\laMorgan Industries Solution-NoCopy files on the Solutions Disk. Chapter 12 – Lesson B

Questions 1. d All of the above. 2. d Structured Query Language 3. c SELECT First, Middle, Last FROM dbo.tblNames 4. b SELECT SocialNum FROM dbo.tblPensionInfo ORDER BY SocialNum DESC 5. a SELECT Id, Name, Status FROM dbo.Worker WHERE Status = ‘A’ 6. b SELECT State, Capital, Population FROM dbo.tblState 7. d None of the above. 8. d None of the above. 9. b used in a WHERE clause in a SELECT statement 10. b False

Exercises 1. See the VB2005\Chap12\lbModified Morgan Industries Solution-DataGrid-Query files on the Solutions Disk. 2. See the VB2005\Chap12\lbCartwright Solution-Query files on the Solutions Disk. 3. See the VB2005\Chap12\lbCollege Courses Solution files on the Solutions Disk. 4. (Discovery) See the VB2005\Chap12\lbMorgan Industries Solution-DataGrid-ToolStrip files on the Solutions Disk. Chapter 12 – Lesson C

Questions 1. a recordPtr = Me.tblStateBindingSource.Position 2. a numRecords = Me.ProductDataSet.Products.Count

Exercises 1. See the VB2005\Chap12\lcTrivia Game Solution-Ex1 files on the Solutions Disk. 2. See the VB2005\Chap12\lcTrivia Game Solution-Ex2 files on the Solutions Disk. 3. See the VB2005\Chap12\lcSports Action Solution files on the Solutions Disk. 4. (Discovery) See the VB2005\Chap12\lcTrivia Game Solution-Disc files on the Solutions Disk. Programming with VB 2005 3E 47 0-4188-3674-5 5. (Discovery) See the VB2005\Chap12\lcFiction Bookstore Solution files on the Solutions Disk. 6. (Debugging) See the VB2005\Chap12\lcDebug Solution files on the Solutions Disk. To debug this solution, the student will need to change Me.FriendsDataSet to Me.FriendsDataSet.tblFriends in the xFillButton’s Click event procedure. The student will also need to change Me.TblFriendsBindingSource.MoveLast() to Me.TblFriendsBindingSource.MoveNext() in the xNextButton’s Click event procedure.

Programming with VB 2005 3E 48 0-4188-3674-5