[ Pobierz całość w formacie PDF ]
.3.Save the project. Module 5: Object-Oriented Programming in Visual Basic.NET 27Exercise 2Testing the LogOn ProcedureIn this exercise, you will test the LogOn procedure from a simple form.To create the Logon button code1.Open frmLogOn in the Code Editor and locate the btnLogOn_Click eventprocedure.2.Declare and instantiate a Customer variable called cusCustomer.3.Call the LogOn method of the cusCustomer object, passing in the textproperties of txtEmail and txtPassword as parameters.4.Display the properties of the cusCustomer object in the appropriate textboxes.Use the information in the following table:Text box Property of cusCustomertxtID CStr(CustomerID)txtFName FirstNametxtLName LastNametxtAddress AddresstxtCompany Company5.Set cusCustomer to Nothing.6.Save the project.28 Module 5: Object-Oriented Programming in Visual Basic.NETTo test the LogOn code1.Set a breakpoint on the first line of the btnLogOn_Click procedure.2.On the Debug menu, click Start.On the menu form, click Test Logon todisplay the test form, and then type the following values in the appropriatetext boxes.Text box ValueE-mail karen@wingtiptoys.msn.comPassword password3.Click the Logon button, and step through the procedure.4.Confirm that your code retrieves the customer information and displays itcorrectly in the text boxes.Close the form.5.Reopen the LogOn form and enter the following incorrect values in theappropriate text boxes.Textbox ValueE-mail john@tailspintoys.msn.comPassword john6.Click the Logon button, and step through the procedure.7.Confirm that your code causes an exception to be generated and handled bythe form.8.Click the Close button to quit the application.Remove the breakpoint onbtnLogOn_Click. Module 5: Object-Oriented Programming in Visual Basic.NET 29Exercise 3Testing Customer RetrievalIn this exercise, you will test the parameterized constructor that retrieves thecustomer details from a simple form.A sales agent who needs full access to thecustomer s information could use this type of form.To create the Retrieve button code1.Open frmRetrieve in the Code Editor, and locate the btnRetrieve_Clickevent procedure.2.Declare and instantiate a Customer variable called cusCustomer.Use theparameterized constructor to pass in the existing customer ID from the txtIDtext box.(Use the CInt function to convert it to an integer value.)3.Display the properties of the cusCustomer object in the appropriate textboxes.Use the information in the following table:Textbox Property of cusCustomertxtEmail EmailtxtPassword PasswordtxtFName FirstNametxtLName LastNametxtAddress AddresstxtCompany Company4.Save the project.To test the Retrieve code1.Set a breakpoint on the first line of the btnRetrieve_Click procedure.2.On the Debug menu, click Start.On the menu form, click Test GetDetails to display the test form, and then type the value 1119 in theCustomerID text box.3.Click the Retrieve button, and step through the procedure.4.Confirm that your code retrieves the customer information and displays itcorrectly in the text boxes.5.Click the Clear Data button to reset the information, and type the value1100 in the CustomerID text box.6.Click the Retrieve button, and step through the procedure.7.Confirm that your code causes an exception to be generated and handled bythe form.8.Click the Close button to quit the application.Remove the breakpoint onbtnRetrieve_Click.30 Module 5: Object-Oriented Programming in Visual Basic.NETExercise 4Testing the AddCustomer ProcedureIn this exercise, you will test the AddCustomer procedure from a simple form.To create the Add Customer button code1.Open frmNew in the Code Editor, and locate the btnNew_Click eventprocedure.2.Declare and instantiate a Customer variable called cusCustomer.3.Call the AddCustomer function of the cusCustomer object, passing in theappropriate values and displaying the return value in a message box.Use theCStr function to convert the integer value to a string.Use the information inthe following table:Parameter name ValuestrEmail txtEmail.TextstrPassword txtPassword.TextstrFName txtFName.TextstrLName txtLName.TextstrCompany txtCompany.TextstrAddress txtAddress.Text4.Save the project.To test the Add Customer code1.Set a breakpoint on the first line of the btnNew_Click procedure.2.On the Debug menu, click Start.On the menu form, click Test NewCustomerto display the test form.3.Enter values in all text boxes.4.Click the New Customer button, and step through the procedure.5
[ Pobierz całość w formacie PDF ]