In this exercise, you will add code that uses the CAccount class you've created. This class will be used when a student attempts to buy a book from the State University Bookstore.

Add code to handle buying a book

  1. In the code for the frmStateUMain form, add a new procedure called PurchaseBook.

  2. In the click event for the cmdBuyBook button, call the PurchaseBook procedure.

  3. In the double click event of the DataRepeater control, call the PurchaseBook procedure.

Authorize the book purchase

  1. In the general declaration section of the main form module, declare a CAccount object called actCurrent using the WithEvents keyword.

  2. In the PurchaseBook procedure, create a new instance of the CAccount class.

  3. Declare a Boolean variable called bAuth to handle the return value from the Authorize method.

  4. Set the Price property of the actCurrent object using the price of the book currently selected in the DataRepeater control. Your code should resemble the following:
  5. 
    actCurrent.Price = drClassBookList.RepeatedControl.Price
  6. Call the Authorize method of the actCurrent object and set the return value equal to bAuth.

  7. If the Authorize method returned False, display a message box that the student is not authorized to buy the book.

  8. If the Authorize method returned True, implement the following:
    1. Declare a boolean variable called bDebit to handle the return value from the Debit method.

    2. Set the Memo property of the actCurrent object to some useful information about the purchase. For example:
    3. actCurrent.Memo = "Book Purchase: " & _
      RTrim(drClassBookList.RepeatedControl.BookName)

    4. Call the Debit method and set the return value equal to bDebit.

    5. Display a message box stating the results of the Debit method. If it returns True, the account was increased by the book amount, if it returns False, the purchase did not occur.

Handle the Warning event

  1. Add the event handler for the Warning event of the actCurrent object.

  2. In the event handler, add code to display the message passed into the event.

  3. Save your work.