home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / vbof / demophon.cls < prev    next >
Encoding:
Text File  |  1996-11-20  |  5.9 KB  |  228 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Phone"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. ' the following pertain to being supported by
  11. '   VBOFCollection, VBOFObjectManager and
  12. '   VBOFEventManager
  13. Public ObjectID As Long
  14. Public ObjectChanged As Long
  15. Public ObjectAdded As Long
  16. Public ObjectDeleted As Long
  17. Public ObjectParentCount As Long
  18. Public ObjectManager As VBOFObjectManager
  19.  
  20. ' the following code pertains to the business
  21. '   of the Phone object
  22. Private pvtPhoneNumber As String
  23. Private pvtUsage As String
  24.  
  25. Public Function ObjectDBGridUnboundReadData(Optional DBGrid As Variant, Optional RowBuf As Variant, Optional RowNumber As Variant) As Boolean
  26. ' Populate the DBGrid RowBuf with values from
  27. '   variables within this object
  28. '   (in support of VBOFCollection)
  29. ' Parameter Description:
  30. '   DBGrid:= the DBGrid which is being
  31. '       populated
  32. '   RowBuf:= the current DBGrid RowBuf object
  33. '   RowNumber:= the row number being processed
  34.  
  35.     Dim I As Long
  36.     
  37.     For I = 0 To RowBuf.ColumnCount - 1
  38.         Select Case RowBuf.ColumnName(I)
  39.             Case "PhoneNumber"
  40.                 RowBuf.Value(RowNumber, I) = PhoneNumber
  41.             Case "Usage"
  42.                 RowBuf.Value(RowNumber, I) = Usage
  43.             Case "ObjectID"
  44.                 RowBuf.Value(RowNumber, I) = ObjectID
  45.         End Select
  46.     Next I
  47.  
  48. End Function
  49.  
  50. Public Function ObjectDBGridUnboundAddData(Optional DBGrid As Variant, Optional RowBuf As Variant, Optional NewRowBookmark As Variant) As Boolean
  51. ' Populate the object variables with the values
  52. '   provided by the user in the new row of the
  53. '   DBGrid
  54. '   (in support of VBOFCollection)
  55. '
  56. ' Parameter Description:
  57. '   DBGrid:= the DBGrid which is being
  58. '       populated
  59. '   RowBuf:= the current DBGrid RowBuf object
  60. '   NewRowBookmark:= the row number being processed
  61.  
  62.     Dim I As Long
  63.     
  64.     For I = 0 To RowBuf.ColumnCount - 1
  65.         If Not IsNull(RowBuf.Value(0, I)) Then
  66.             Select Case RowBuf.ColumnName(I)
  67.                 Case "PhoneNumber"
  68.                     PhoneNumber = RowBuf.Value(0, I)
  69.                 Case "Usage"
  70.                     Usage = RowBuf.Value(0, I)
  71.     
  72. ' Note:  Do not initialize the ObjectID.
  73.         
  74.             End Select
  75.         End If
  76.     Next I
  77.     
  78. ' return "OK" status
  79.     ObjectDBGridUnboundAddData = True
  80. End Function
  81.  
  82.  
  83. Public Function ObjectListBoxValue() As String
  84. ' Return a String will represent this object
  85. '   in a ListBox
  86. '   (in support of VBOFCollection)
  87.  
  88.     ObjectListBoxValue = _
  89.         FormattedPhoneNumber
  90.  
  91. End Function
  92.  
  93.  
  94. Private Sub Class_Terminate()
  95.     If Not ObjectManager Is Nothing Then
  96.         ObjectManager.TerminateObject _
  97.             Object:=Me
  98.     End If
  99. End Sub
  100.  
  101.  
  102.  
  103. Public Function ObjectHasChanged()
  104. ' Mark this object as "Changed" and trigger the
  105. '   "Changed" event
  106.  
  107.     ObjectChanged = True
  108.     
  109. #If NoEventMgr = False Then
  110.     If Not ObjectManager Is Nothing Then
  111.         ObjectManager. _
  112.             TriggerObjectEvent _
  113.                 Event:="Changed", _
  114.                 Object:=Me
  115.     End If
  116. #End If
  117.  
  118. End Function
  119.  
  120. Public Function FormattedPhoneNumber() As String
  121. ' Return a displayable, fully formatted
  122. '   version of Me
  123.  
  124.     If Len(PhoneNumber) <= 7 Then
  125.         FormattedPhoneNumber = Format$(PhoneNumber, "000-0000")
  126.     ElseIf Len(PhoneNumber) <= 10 Then
  127.         FormattedPhoneNumber = Format$(PhoneNumber, "(000) 000-0000")
  128.     ElseIf Len(PhoneNumber) = 11 Then
  129.         FormattedPhoneNumber = Format$(PhoneNumber, "0 (000) 000-0000")
  130.     Else
  131.         FormattedPhoneNumber = PhoneNumber
  132.     End If
  133.  
  134. End Function
  135.  
  136.  
  137. Public Function ObjectInitializeFromRecordSet(Optional RecordSet As Variant) As Phone
  138. ' Populate my variables from the RecordSet
  139. '   (in support of VBOFCollection)
  140.  
  141.     On Local Error Resume Next
  142.     
  143.     PhoneNumber = RecordSet("PhoneNumber")
  144.     Usage = RecordSet("Usage")
  145.     
  146.     ObjectID = RecordSet("ObjectID")
  147.  
  148.     Set ObjectInitializeFromRecordSet = Me
  149. End Function
  150.  
  151.  
  152. Public Function ObjectInitializeRecordSet(Optional RecordSet As Variant) As Long
  153. ' Populate the RecordSet with my variables.
  154. '   Do not initialize the ObjectID column.
  155. '   Return any error code encountered.
  156. '   (in support of VBOFCollection)
  157.  
  158.     On Local Error GoTo InitializeRecordSet_SetError
  159.     Err = 0
  160.     
  161.     RecordSet("PhoneNumber") = PhoneNumber
  162.     RecordSet("Usage") = Usage
  163.         
  164. ' Note:  Do not initialize the ObjectID column.
  165.  
  166.     GoTo InitializeRecordSet_SetError
  167.  
  168. InitializeRecordSet_SetError:
  169.     ObjectInitializeRecordSet = Err
  170.     Exit Function
  171. End Function
  172.  
  173.  
  174. Public Function ObjectNewInstanceOfMyClass() As Phone
  175. ' Return a new instance of this class
  176. '   (in support of VBOFCollection)
  177.  
  178.     Set ObjectNewInstanceOfMyClass = New Phone
  179. End Function
  180.  
  181.  
  182. Public Function ObjectEventCallBack(Optional Event As Variant, Optional Object As Variant) As Long
  183. ' Receive the Trigger notification and process
  184. '   accordingly
  185. '
  186. ' Parameters:
  187. '   Event
  188. '       a string which identifies the Event
  189. '       Example: "Changed", "Created", "Deleted"
  190. '   Object
  191. '       the object originating the Event.
  192. '       responds to:
  193. '           TypeName(TriggerObject)
  194. '           TriggerObject.ObjectID
  195. ' (supported by VBOFEventManager)
  196.  
  197. End Function
  198.  
  199.  
  200.  
  201.  
  202.  
  203. Public Function ObjectDataSource() As String
  204. ' Return the Data Source with which this Class is associated
  205. '   (in support of VBOFCollection)
  206.     
  207.     ObjectDataSource = "Phones"
  208. End Function
  209.  
  210.  
  211. Public Property Get PhoneNumber() As String
  212.     PhoneNumber = pvtPhoneNumber
  213. End Property
  214.  
  215. Public Property Let PhoneNumber(aString As String)
  216.     pvtPhoneNumber = aString
  217. '    ObjectHasChanged
  218. End Property
  219.  
  220. Public Property Get Usage() As String
  221.     Usage = pvtUsage
  222. End Property
  223.  
  224. Public Property Let Usage(aString As String)
  225.     pvtUsage = aString
  226. '    ObjectHasChanged
  227. End Property
  228.