home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / dbawarco / address.cls next >
Encoding:
Text File  |  1996-11-20  |  5.2 KB  |  203 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Address"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. Public Line1 As String
  11. Public Line2 As String
  12. Public Line3 As String
  13. Public City As String
  14. Public StateCode As String
  15. Public ZipCode As Long
  16. Public ZipSupplement As Integer
  17. Public ZipExtension As Integer
  18. Public ForeignZipCode As String
  19. Public Status As String
  20. Public Usage As String
  21. Public ObjectID As Long
  22.  
  23.  
  24. Public Function TableName() As String
  25. ' Return the Table with which this Class is associated
  26. '   (in support of DBAwareCollection)
  27.     
  28.     TableName = "Addresses"
  29. End Function
  30.  
  31. Public Function FormattedAddress() As String
  32. ' Return a displayable, fully formatted
  33. '   version of Me
  34.  
  35.     Dim ReturnString As String
  36.     
  37.     If Line1 > "" Then
  38.         ReturnString = pvtContatenateWithCRLF( _
  39.                         String1:=ReturnString, _
  40.                         String2:=Line1)
  41.     End If
  42.     
  43.     If Line2 > "" Then
  44.         ReturnString = pvtContatenateWithCRLF( _
  45.                         String1:=ReturnString, _
  46.                         String2:=Line2)
  47.     End If
  48.     
  49.     If Line3 > "" Then
  50.         ReturnString = pvtContatenateWithCRLF( _
  51.                         String1:=ReturnString, _
  52.                         String2:=Line3)
  53.     End If
  54.     
  55.     If City > "" Then
  56.         ReturnString = pvtContatenateWithCRLF( _
  57.                         String1:=ReturnString, _
  58.                         String2:=City) _
  59.                         & ", "
  60.     End If
  61.     
  62.     If StateCode > "" Then
  63.         ReturnString = ReturnString & StateCode
  64.     End If
  65.     
  66.     If ZipCode >= 0 Then
  67.         ReturnString = ReturnString & " " & FormattedZip
  68.     End If
  69.     
  70.     FormattedAddress = ReturnString
  71. End Function
  72.  
  73. Private Function pvtContatenateWithCRLF(Optional String1 As Variant, Optional String2 As Variant) As String
  74.  
  75.     Dim ReturnString As String
  76.     
  77.     ReturnString = ""
  78.     
  79.     If Not IsMissing(String1) Then
  80.         ReturnString = String1
  81.         If String1 > "" Then
  82.             ReturnString = ReturnString & vbCrLf
  83.         End If
  84.     End If
  85.     
  86.     If Not IsMissing(String2) Then
  87.         If String2 > "" Then
  88.             ReturnString = ReturnString & String2
  89.         End If
  90.     End If
  91.  
  92.     pvtContatenateWithCRLF = ReturnString
  93. End Function
  94. Public Function FormattedZip() As String
  95.  
  96.     Dim ReturnString As String
  97.     
  98.     ReturnString = ""
  99.     
  100.     If ZipCode >= 0 Then
  101.         ReturnString = ReturnString & Format$(ZipCode, "#####")
  102.     End If
  103.     
  104.     If ZipSupplement >= 0 Then
  105.         If ReturnString = "" Then
  106.             ReturnString = Format$(ZipSupplement, "####")
  107.         Else
  108.             ReturnString = ReturnString & "-" & Format$(ZipSupplement, "####")
  109.         End If
  110.     End If
  111.     
  112.     If ZipExtension >= 0 Then
  113.         If ReturnString = "" Then
  114.             ReturnString = Format$(ZipExtension, "##")
  115.         Else
  116.             ReturnString = ReturnString & "-" & Format$(ZipExtension, "##")
  117.         End If
  118.     End If
  119.  
  120.     FormattedZip = ReturnString
  121. End Function
  122.  
  123.  
  124. Private Sub Class_Initialize()
  125.     
  126.     ZipCode = -1
  127.     ZipSupplement = -1
  128.     ZipExtension = -1
  129.     ForeignZipCode = ""
  130.     Status = "Current"
  131.     Usage = "Primary"
  132.  
  133. End Sub
  134.  
  135.  
  136.  
  137. Public Function ObjectType() As String
  138. ' Return the type of this Class
  139. '   (in support of DBAwareCollection)
  140.     
  141.     ObjectType = "Address"
  142. End Function
  143. Public Function InitializeFromRecordSet(Optional ByVal RecordSet As Variant) As Address
  144. ' Populate my variables from the RecordSet
  145. '   (in support of DBAwareCollection)
  146.  
  147.     On Local Error Resume Next
  148.     
  149.     Line1 = RecordSet("Line1")
  150.     Line2 = RecordSet("Line2")
  151.     Line3 = RecordSet("Line3")
  152.     City = RecordSet("City")
  153.     StateCode = RecordSet("StateCode")
  154.     ZipCode = RecordSet("ZipCode")
  155.     ZipSupplement = RecordSet("ZipSupplement")
  156.     ZipExtension = RecordSet("ZipExtension")
  157.     ForeignZipCode = RecordSet("ForeignZipCode")
  158.     Status = RecordSet("Status")
  159.     Usage = RecordSet("Usage")
  160.     ObjectID = RecordSet("ObjectID")
  161.  
  162.     Set InitializeFromRecordSet = Me
  163. End Function
  164.  
  165. Public Function NewInstanceOfMyClass() As Address
  166. ' Return a new instance of this class
  167. '   (in support of DBAwareCollection)
  168.  
  169.     Set NewInstanceOfMyClass = New Address
  170. End Function
  171.  
  172.  
  173.  
  174. Public Function InitializeRecordSet(Optional ByVal RecordSet As Variant) As Long
  175. ' Populate the RecordSet with my variables.
  176. '   Do not initialize the ObjectID column.
  177. '   Return any error code encountered.
  178. '   (in support of DBAwareCollection)
  179.  
  180.     On Local Error GoTo InitializeRecordSet_SetError
  181.     Err = 0
  182.     
  183.     RecordSet("Line1") = Line1
  184.     RecordSet("Line2") = Line2
  185.     RecordSet("Line3") = Line3
  186.     RecordSet("City") = City
  187.     RecordSet("StateCode") = StateCode
  188.     RecordSet("ZipCode") = ZipCode
  189.     RecordSet("ZipSupplement") = ZipSupplement
  190.     RecordSet("ZipExtension") = ZipExtension
  191.     RecordSet("ForeignZipCode") = ForeignZipCode
  192.     RecordSet("Status") = Status
  193.     RecordSet("Usage") = Usage
  194.     
  195.     GoTo InitializeRecordSet_SetError
  196.  
  197. InitializeRecordSet_SetError:
  198.     InitializeRecordSet = Err
  199.     Exit Function
  200. End Function
  201.  
  202.  
  203.