GetNextReceipt Method, Step7 (Visual Basic)
Public Function GetNextReceipt() As Long
On Error GoTo ErrorHandler
' If Shared property does not already exist
' it will be initialized
Dim spmMgr As SharedPropertyGroupManager
Set spmMgr = CreateObject("MTxSpm.SharedPropertyGroupManager.1")
Dim spmGroup As SharedPropertyGroup
Dim bResult As Boolean
Set spmGroup = _
spmMgr.CreatePropertyGroup("Receipt", _
LockMethod, Process, bResult)
Dim spmPropNextReceipt As SharedProperty
Set spmPropNextReceipt = _
spmGroup.CreateProperty("Next", bResult)
' Set the initial value of the Shared Property to
' 0 if the Shared Property didn’t already exist.
' This is not entirely necessary but demonstrates
' how to initialize a value.
If bResult = False Then
spmPropNextReceipt.Value = 0
End If
Dim spmPropMaxNum As SharedProperty
Set spmPropMaxNum = spmGroup.CreateProperty("MaxNum", bResult)
Dim objReceiptUpdate As Bank.UpdateReceipt
If spmPropNextReceipt.Value >= spmPropMaxNum.Value Then
Set objReceiptUpdate = GetObjectContext.CreateInstance("Bank.UpdateReceipt")
spmPropNextReceipt.Value = objReceiptUpdate.Update
spmPropMaxNum.Value = spmPropNextReceipt.Value + 100
End If
' Get the next receipt number and update property
spmPropNextReceipt.Value = spmPropNextReceipt.Value + 1
' we are finished and happy
GetObjectContext.SetComplete
GetNextReceipt = spmPropNextReceipt.Value
Exit Function
ErrorHandler:
GetObjectContext.SetAbort ' we are unhappy
' indicate that an error occured
GetNextReceipt = -1
Err.Raise Err.Number, "Bank.GetReceipt.GetNextReceipt", Err.Description
End Function