home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / mts4.cab / Account.VB_Step5_MoveMoney.cls < prev    next >
Text File  |  1997-11-14  |  3KB  |  107 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "MoveMoney"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. ' Filename: Account.vbp
  11. '
  12. ' Description:  MoveMoney Class
  13. '
  14. ' This file is provided as part of the Microsoft Transaction Server Samples
  15. '
  16. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
  17. ' WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  18. ' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  19. ' OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
  20. ' PURPOSE.
  21. '
  22. ' Copyright (C) 1997 Microsoft Corporation, All rights reserved
  23.  
  24. Option Explicit
  25.  
  26. Public PrimeAccount As Long
  27. Public SecondAccount As Long
  28.  
  29. Private Const ERROR_NUMBER = vbObjectError + 0
  30. Private Const APP_ERROR = -2147467008
  31.  
  32. Public Function Perform(ByVal lngPrimeAccount As Long, ByVal lngSecondAccount As Long, ByVal lngAmount As Long, ByVal lngTranType As Long) As String
  33.  
  34.     Dim strResult As String
  35.     
  36.     On Error GoTo ErrorHandler
  37.     
  38.     ' create the account object using our context
  39.     Dim objAccount As Bank.Account
  40.     Set objAccount = GetObjectContext.CreateInstance("Bank.Account")
  41.     
  42.     If objAccount Is Nothing Then
  43.         Err.Raise ERROR_NUMBER, Description:="Could not create account object"
  44.     End If
  45.  
  46.     ' call the post function based on the transaction type
  47.     Select Case lngTranType
  48.         
  49.         Case 1
  50.             strResult = objAccount.Post(lngPrimeAccount, 0 - lngAmount)
  51.             If strResult = "" Then
  52.                 Err.Raise ERROR_NUMBER, Description:=strResult
  53.             End If
  54.     
  55.         Case 2
  56.             strResult = objAccount.Post(lngPrimeAccount, lngAmount)
  57.                 If strResult = "" Then
  58.                     Err.Raise ERROR_NUMBER, Description:=strResult
  59.             End If
  60.             
  61.         Case 3
  62.             Dim strResult1 As String, strResult2 As String
  63.             ' do the credit
  64.             strResult1 = objAccount.Post(lngSecondAccount, lngAmount)
  65.             If strResult1 = "" Then
  66.                 Err.Raise ERROR_NUMBER, Description:=strResult1
  67.             Else
  68.                 ' then do the debit
  69.                 strResult2 = objAccount.Post(lngPrimeAccount, 0 - lngAmount)
  70.                 If strResult2 = "" Then
  71.                     Err.Raise ERROR_NUMBER, Description:=strResult2    ' debit failed
  72.                 Else
  73.                     strResult = strResult1 + "  " + strResult2
  74.                 End If
  75.             End If
  76.             
  77.         Case Else
  78.             Err.Raise ERROR_NUMBER, Description:="Invalid Transaction Type"
  79.     
  80.     End Select
  81.     
  82.     ' Get Receipt Number for the transaction
  83.     Dim objReceiptNo As Bank.GetReceipt
  84.     Dim lngReceiptNo As Long
  85.   
  86.     Set objReceiptNo = GetObjectContext.CreateInstance("Bank.GetReceipt")
  87.     lngReceiptNo = objReceiptNo.GetNextReceipt
  88.     If lngReceiptNo > 0 Then
  89.         strResult = strResult & "; Receipt No: " & Str$(lngReceiptNo)
  90.     End If
  91.   
  92.     GetObjectContext.SetComplete                  ' we are finished and happy
  93.     
  94.     Perform = strResult
  95.      
  96.     Exit Function
  97.  
  98. ErrorHandler:
  99.  
  100.     GetObjectContext.SetAbort                      ' we are unhappy
  101.     
  102.     Perform = ""                            ' indicate that an error occured
  103.     
  104.     Err.Raise Err.Number, "Bank.MoveMoney.Perform", Err.Description
  105.     
  106. End Function
  107.