1 / 37

Clearly Visual Basic: Programming with Visual Basic 2008

Clearly Visual Basic: Programming with Visual Basic 2008. Chapter 12 Testing, Testing …1, 2, 3. Objectives. Select appropriate test data for an application Prevent the entry of unwanted characters in a text box Create a message box with the MessageBox.Show method

jgunn
Download Presentation

Clearly Visual Basic: Programming with Visual Basic 2008

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 12 Testing, Testing …1, 2, 3

  2. Objectives • Select appropriate test data for an application • Prevent the entry of unwanted characters in a text box • Create a message box with the MessageBox.Show method • Trim leading and trailing spaces from a string Clearly Visual Basic: Programming with Visual Basic 2008

  3. Will Your Application Pass the Test? • Invalid data • Data that the program is not expecting the user to enter • The result of the user making: • A typing error, entering the data in an incorrect format, or neglecting to make a required entry • Test with invalid data • To ensure that the program does not display erroneous results or end abruptly because of an input error Clearly Visual Basic: Programming with Visual Basic 2008

  4. Clearly Visual Basic: Programming with Visual Basic 2008

  5. The Only Cookies – Version 1 Application • Figure 12-2 • Shows the interface for the Only Cookies-Version 1 application • The Only Cookies-Version 1 application • Expects the user to enter a number in the Pounds ordered text box • Figure 12-5 • Shows the application’s testing chart Clearly Visual Basic: Programming with Visual Basic 2008

  6. Const intPRICE As Integer = 5 Dim decOrdered As Decimal Dim decTotalPrice As Decimal Decimal.TryParse(txtOrdered.Text, decOrdered) ' calculate and display total price decTotalPrice = decOrdered * intPRICE lblTotalPrice.Text = decTotalPrice.ToString("C2")

  7. Clearly Visual Basic: Programming with Visual Basic 2008

  8. Clearly Visual Basic: Programming with Visual Basic 2008

  9. Clearly Visual Basic: Programming with Visual Basic 2008

  10. Clearly Visual Basic: Programming with Visual Basic 2008

  11. The Only Cookies – Version 2 Application Figure 12-7 Shows the interface for the Only Cookies-Version 2 application Figure 12-8 Shows the Calculate button’s Click event procedure Figure 12-9 Shows the testing chart for the Only Cookies-Version 2 application Clearly Visual Basic: Programming with Visual Basic 2008

  12. Clearly Visual Basic: Programming with Visual Basic 2008

  13. Can only put in IntegersTry some of the Invalid one listed below Clearly Visual Basic: Programming with Visual Basic 2008

  14. Stop! This is a Restricted Area! • KeyPress event • Occurs each time the user presses a key while the control has the focus • When the KeyPress event occurs: • A character corresponding to the pressed key is sent to the KeyPress event’s e parameter • To prevent a text box from accepting an inappropriate character: • First use the eparameter’s KeyChar property to determine the pressed key Clearly Visual Basic: Programming with Visual Basic 2008

  15. Stop! This is a Restricted Area! (continued) • e parameter’s Handled property • Used to cancel the pressed key if it is an inappropriate one • ControlChars.Back constant • Used to refer to the Backspace key • Backspace key • Necessary for editing the text box entry Clearly Visual Basic: Programming with Visual Basic 2008

  16. Clearly Visual Basic: Programming with Visual Basic 2008

  17. Clearly Visual Basic: Programming with Visual Basic 2008

  18. The Shady Hollow Hotel – Version 1 Application- Case Statement • Figure 12-13 • Shows the interface for the Shady Hollow Hotel-Version 1 application • Figure 12-14 • Shows the Click event procedure • Figure 12-15 • Shows the application’s testing chart Clearly Visual Basic: Programming with Visual Basic 2008

  19. Clearly Visual Basic: Programming with Visual Basic 2008

  20. The Shady Hollow Hotel – Version 2 Application- If-Then Else Statement • Figure 12-17 • Shows the interface for the Shady Hollow Hotel-Version 2 application • Interface uses a text box for the room type selection • Figure 12-18 • Shows the Click event procedure • In this application: • User will be entering a string in the txtType control • According to third guideline: • You need to test each path in the selection structure Clearly Visual Basic: Programming with Visual Basic 2008

  21. Clearly Visual Basic: Programming with Visual Basic 2008

  22. I Need To Tell You Something • Messages can be displayed • Either in a label control in the interface or in a message box • Figure 12-20 • Shows the basic syntax of the MessageBox.Show method Clearly Visual Basic: Programming with Visual Basic 2008

  23. Clearly Visual Basic: Programming with Visual Basic 2008

  24. Clearly Visual Basic: Programming with Visual Basic 2008

  25. Just When You Thought It was Safe (continued) • Trim method • Used to remove leading and trailing spaces • Figure 12-26 • Shows the basic syntax of the Trim method • Includes examples of using the method Clearly Visual Basic: Programming with Visual Basic 2008

  26. Clearly Visual Basic: Programming with Visual Basic 2008

  27. strType = txtType.Text.ToUpper.Trim If strType = "S" Then intDailyRate = 90 ElseIf strType = "D" Then intDailyRate = 115 Else MessageBox.Show("Please enter a valid room type", "Shady Hollow Hotel“, MessageBox.Buttons.OK, MessageBoxIcon.Information) txtType.Text = "" txtType.Focus() End If

  28. Clearly Visual Basic: Programming with Visual Basic 2008

  29. Const intGOLD_CLUB As Integer = 10 Select Case True Case radStandard.Checked intDailyRate = 90 Case radDeluxe.Checked intDailyRate = 115 Case Else intDailyRate = 130 End Select ' subtract Gold Club discount If chkGoldClub.Checked = True Then intDailyRate = intDailyRate - intGOLD_CLUB End If

  30. The only thing you can put in the textbox is an s, S, d, D or a Backspace Private Sub txtType_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtType.KeyPress ' allows the text box to accept only the letters ' S, s, D, and d and the Backspace key for editing If e.KeyChar <> "S" AndAlso e.KeyChar <> "s" _ AndAlso e.KeyChar <> "D" AndAlso e.KeyChar <> "d" _ AndAlso e.KeyChar <> ControlChars.Back Then e.Handled = True End If End Sub

  31. Can’t put anything in except S, s, D, d and the backspace Key Private Sub txtType_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtType.KeyPress ' allows the text box to accept only the letters ' S, s, D, and d and the Backspace key for editing If e.KeyChar <> "S" AndAlso e.KeyChar <> "s" _ AndAlso e.KeyChar <> "D" AndAlso e.KeyChar <> "d" _ AndAlso e.KeyChar <> ControlChars.Back Then e.Handled = True End If End Sub

  32. Just When You Thought It Was Safe • Bugs • Errors in the application • Number of bugs • Directly related to the size and complexity of the application • Beta testers • Encouraged to use the application as often as possible, because some bugs surface only after months of use Clearly Visual Basic: Programming with Visual Basic 2008

  33. Summary • Thoroughly test programs • Before releasing them to the public • Figure 12-1 • Lists the guidelines for selecting test data • You can use a testing chart to: • Record the test data and the expected results • To prevent a text box from accepting a character: • Code the text box’sKeyPress event procedure Clearly Visual Basic: Programming with Visual Basic 2008

  34. Summary (continued) • Whenever you make a change to an application’s code: • Retest the application using the data listed in its testing chart • You can use the MessageBox.Show method to: • Display a message to the user while an application is running • Trim method • Makes a temporary copy of a string • Then performs the necessary trimming on the copy only Clearly Visual Basic: Programming with Visual Basic 2008

More Related