home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / vbof / democulb.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-20  |  37.0 KB  |  1,129 lines

  1. VERSION 4.00
  2. Begin VB.Form CustomerDetailsListBoxNoDataControl 
  3.    Caption         =   "Customer Details (Pure OO example using ListBoxes)"
  4.    ClientHeight    =   6150
  5.    ClientLeft      =   825
  6.    ClientTop       =   450
  7.    ClientWidth     =   8820
  8.    Height          =   6555
  9.    Left            =   765
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   6150
  12.    ScaleWidth      =   8820
  13.    Top             =   105
  14.    Width           =   8940
  15.    Begin VB.CommandButton Command1 
  16.       Caption         =   "Count Sel"
  17.       Height          =   375
  18.       Left            =   7680
  19.       TabIndex        =   11
  20.       Top             =   1560
  21.       Width           =   975
  22.    End
  23.    Begin VB.ListBox List1 
  24.       Height          =   1815
  25.       Left            =   0
  26.       MultiSelect     =   2  'Extended
  27.       TabIndex        =   0
  28.       Top             =   120
  29.       Width           =   4215
  30.    End
  31.    Begin VB.CommandButton pbOK 
  32.       Cancel          =   -1  'True
  33.       Caption         =   "OK"
  34.       Default         =   -1  'True
  35.       Height          =   375
  36.       Left            =   7680
  37.       TabIndex        =   12
  38.       Top             =   2160
  39.       Width           =   975
  40.    End
  41.    Begin VB.CommandButton pbDeleteCustomer 
  42.       Caption         =   "Delete"
  43.       Height          =   375
  44.       Left            =   7680
  45.       TabIndex        =   10
  46.       Top             =   1080
  47.       Width           =   975
  48.    End
  49.    Begin VB.CommandButton pbUpdateCustomer 
  50.       Caption         =   "Update"
  51.       Height          =   375
  52.       Left            =   7680
  53.       TabIndex        =   9
  54.       Top             =   600
  55.       Width           =   975
  56.    End
  57.    Begin VB.CommandButton pbAddNewCustomer 
  58.       Caption         =   "Add New"
  59.       Height          =   375
  60.       Left            =   7680
  61.       TabIndex        =   8
  62.       Top             =   120
  63.       Width           =   975
  64.    End
  65.    Begin VB.Frame Frame1 
  66.       Caption         =   "Customer Details"
  67.       Height          =   2535
  68.       Left            =   4320
  69.       TabIndex        =   32
  70.       Top             =   0
  71.       Width           =   3255
  72.       Begin VB.ComboBox lbxGenderCodes 
  73.          Height          =   315
  74.          Left            =   2400
  75.          Sorted          =   -1  'True
  76.          TabIndex        =   7
  77.          Top             =   2160
  78.          Width           =   615
  79.       End
  80.       Begin VB.ComboBox lbxMaritalStatusCodes 
  81.          Height          =   315
  82.          Left            =   1200
  83.          Sorted          =   -1  'True
  84.          TabIndex        =   6
  85.          Top             =   2160
  86.          Width           =   855
  87.       End
  88.       Begin VB.TextBox efCustomerNumber 
  89.          Height          =   285
  90.          Left            =   1200
  91.          TabIndex        =   1
  92.          Top             =   360
  93.          Width           =   1815
  94.       End
  95.       Begin VB.TextBox efDateOfBirth 
  96.          Height          =   285
  97.          Left            =   1200
  98.          TabIndex        =   5
  99.          Top             =   1800
  100.          Width           =   1815
  101.       End
  102.       Begin VB.TextBox efFirstName 
  103.          Height          =   285
  104.          Left            =   1200
  105.          TabIndex        =   2
  106.          Top             =   720
  107.          Width           =   1815
  108.       End
  109.       Begin VB.TextBox efLastName 
  110.          Height          =   285
  111.          Left            =   1200
  112.          TabIndex        =   3
  113.          Top             =   1080
  114.          Width           =   1815
  115.       End
  116.       Begin VB.TextBox efSSN 
  117.          Height          =   285
  118.          Left            =   1200
  119.          TabIndex        =   4
  120.          Top             =   1440
  121.          Width           =   1815
  122.       End
  123.       Begin VB.Label Label1 
  124.          Caption         =   "Marital Status"
  125.          Height          =   255
  126.          Index           =   4
  127.          Left            =   120
  128.          TabIndex        =   57
  129.          Top             =   2160
  130.          Width           =   975
  131.       End
  132.       Begin VB.Label Label1 
  133.          Caption         =   "Sex"
  134.          Height          =   255
  135.          Index           =   11
  136.          Left            =   2040
  137.          TabIndex        =   56
  138.          Top             =   2160
  139.          Width           =   375
  140.       End
  141.       Begin VB.Label Label1 
  142.          Caption         =   "Cust Number"
  143.          Height          =   255
  144.          Index           =   12
  145.          Left            =   120
  146.          TabIndex        =   37
  147.          Top             =   360
  148.          Width           =   975
  149.       End
  150.       Begin VB.Label Label1 
  151.          Caption         =   "Date Of Birth"
  152.          Height          =   255
  153.          Index           =   3
  154.          Left            =   120
  155.          TabIndex        =   36
  156.          Top             =   1800
  157.          Width           =   975
  158.       End
  159.       Begin VB.Label Label1 
  160.          Caption         =   "First Name"
  161.          Height          =   255
  162.          Index           =   0
  163.          Left            =   120
  164.          TabIndex        =   35
  165.          Top             =   720
  166.          Width           =   975
  167.       End
  168.       Begin VB.Label Label1 
  169.          Caption         =   "Last Name"
  170.          Height          =   255
  171.          Index           =   1
  172.          Left            =   120
  173.          TabIndex        =   34
  174.          Top             =   1080
  175.          Width           =   975
  176.       End
  177.       Begin VB.Label Label1 
  178.          Caption         =   "SSN"
  179.          Height          =   255
  180.          Index           =   2
  181.          Left            =   120
  182.          TabIndex        =   33
  183.          Top             =   1440
  184.          Width           =   975
  185.       End
  186.    End
  187.    Begin TabDlg.SSTab SSTab1 
  188.       Height          =   3135
  189.       Left            =   0
  190.       TabIndex        =   13
  191.       Top             =   2640
  192.       Width           =   8775
  193.       _Version        =   65536
  194.       _ExtentX        =   15478
  195.       _ExtentY        =   5530
  196.       _StockProps     =   15
  197.       Caption         =   "Addresses"
  198.       TabsPerRow      =   2
  199.       Tab             =   0
  200.       TabOrientation  =   0
  201.       Tabs            =   2
  202.       Style           =   1
  203.       TabMaxWidth     =   0
  204.       TabHeight       =   529
  205.       TabCaption(0)   =   "Addresses"
  206.       Tab(0).ControlCount=   7
  207.       Tab(0).ControlEnabled=   -1  'True
  208.       Tab(0).Control(0)=   "Label1(13)"
  209.       Tab(0).Control(1)=   "efFormattedAddress"
  210.       Tab(0).Control(2)=   "Frame2"
  211.       Tab(0).Control(3)=   "pbDeleteAddress"
  212.       Tab(0).Control(4)=   "pbUpdateAddress"
  213.       Tab(0).Control(5)=   "pbAddNewAddress"
  214.       Tab(0).Control(6)=   "List2"
  215.       TabCaption(1)   =   "Phones"
  216.       Tab(1).ControlCount=   7
  217.       Tab(1).ControlEnabled=   0   'False
  218.       Tab(1).Control(0)=   "Label1(21)"
  219.       Tab(1).Control(1)=   "efFormattedPhoneNumber"
  220.       Tab(1).Control(2)=   "Frame3"
  221.       Tab(1).Control(3)=   "pbDeletePhone"
  222.       Tab(1).Control(4)=   "pbUpdatePhone"
  223.       Tab(1).Control(5)=   "pbAddPhone"
  224.       Tab(1).Control(6)=   "List3"
  225.       Begin VB.ListBox List3 
  226.          Height          =   1815
  227.          Left            =   -74880
  228.          TabIndex        =   26
  229.          Top             =   480
  230.          Width           =   4095
  231.       End
  232.       Begin VB.ListBox List2 
  233.          Height          =   1230
  234.          Left            =   120
  235.          TabIndex        =   14
  236.          Top             =   480
  237.          Width           =   4095
  238.       End
  239.       Begin VB.CommandButton pbAddPhone 
  240.          Caption         =   "Add New"
  241.          Height          =   375
  242.          Left            =   -67320
  243.          TabIndex        =   29
  244.          Top             =   480
  245.          Width           =   975
  246.       End
  247.       Begin VB.CommandButton pbUpdatePhone 
  248.          Caption         =   "Update"
  249.          Height          =   375
  250.          Left            =   -67320
  251.          TabIndex        =   30
  252.          Top             =   960
  253.          Width           =   975
  254.       End
  255.       Begin VB.CommandButton pbDeletePhone 
  256.          Caption         =   "Delete"
  257.          Height          =   375
  258.          Left            =   -67320
  259.          TabIndex        =   31
  260.          Top             =   1440
  261.          Width           =   975
  262.       End
  263.       Begin VB.Frame Frame3 
  264.          Caption         =   "Address Details"
  265.          Height          =   2535
  266.          Left            =   -70680
  267.          TabIndex        =   45
  268.          Top             =   360
  269.          Width           =   3255
  270.          Begin VB.TextBox efUsage 
  271.             Height          =   285
  272.             Left            =   1200
  273.             TabIndex        =   28
  274.             Top             =   720
  275.             Width           =   1815
  276.          End
  277.          Begin VB.TextBox efPhoneNumber 
  278.             Height          =   285
  279.             Left            =   1200
  280.             TabIndex        =   27
  281.             Top             =   360
  282.             Width           =   1815
  283.          End
  284.          Begin VB.Label Label1 
  285.             Caption         =   "Usage"
  286.             Height          =   255
  287.             Index           =   16
  288.             Left            =   120
  289.             TabIndex        =   47
  290.             Top             =   720
  291.             Width           =   975
  292.          End
  293.          Begin VB.Label Label1 
  294.             Caption         =   "Phone Num"
  295.             Height          =   255
  296.             Index           =   15
  297.             Left            =   120
  298.             TabIndex        =   46
  299.             Top             =   360
  300.             Width           =   975
  301.          End
  302.       End
  303.       Begin VB.CommandButton pbAddNewAddress 
  304.          Caption         =   "Add New"
  305.          Height          =   375
  306.          Left            =   7680
  307.          TabIndex        =   23
  308.          Top             =   480
  309.          Width           =   975
  310.       End
  311.       Begin VB.CommandButton pbUpdateAddress 
  312.          Caption         =   "Update"
  313.          Height          =   375
  314.          Left            =   7680
  315.          TabIndex        =   24
  316.          Top             =   960
  317.          Width           =   975
  318.       End
  319.       Begin VB.CommandButton pbDeleteAddress 
  320.          Caption         =   "Delete"
  321.          Height          =   375
  322.          Left            =   7680
  323.          TabIndex        =   25
  324.          Top             =   1440
  325.          Width           =   975
  326.       End
  327.       Begin VB.Frame Frame2 
  328.          Caption         =   "Address Details"
  329.          Height          =   2535
  330.          Left            =   4320
  331.          TabIndex        =   38
  332.          Top             =   360
  333.          Width           =   3255
  334.          Begin VB.ComboBox lbxStateCodes 
  335.             Height          =   315
  336.             Left            =   1200
  337.             Sorted          =   -1  'True
  338.             TabIndex        =   19
  339.             Top             =   1800
  340.             Width           =   1815
  341.          End
  342.          Begin VB.TextBox efLine1 
  343.             Height          =   285
  344.             Left            =   1200
  345.             TabIndex        =   15
  346.             Top             =   360
  347.             Width           =   1815
  348.          End
  349.          Begin VB.TextBox efLine2 
  350.             Height          =   285
  351.             Left            =   1200
  352.             TabIndex        =   16
  353.             Top             =   720
  354.             Width           =   1815
  355.          End
  356.          Begin VB.TextBox efLine3 
  357.             Height          =   285
  358.             Left            =   1200
  359.             TabIndex        =   17
  360.             Top             =   1080
  361.             Width           =   1815
  362.          End
  363.          Begin VB.TextBox efCity 
  364.             Height          =   285
  365.             Left            =   1200
  366.             TabIndex        =   18
  367.             Top             =   1440
  368.             Width           =   1815
  369.          End
  370.          Begin VB.TextBox efZipCode 
  371.             Height          =   285
  372.             Left            =   1200
  373.             MaxLength       =   5
  374.             TabIndex        =   20
  375.             Top             =   2160
  376.             Width           =   735
  377.          End
  378.          Begin VB.TextBox efZipExtension 
  379.             Height          =   285
  380.             Left            =   2640
  381.             MaxLength       =   2
  382.             TabIndex        =   22
  383.             Top             =   2160
  384.             Width           =   375
  385.          End
  386.          Begin VB.TextBox efZipSupplement 
  387.             Height          =   285
  388.             Left            =   2040
  389.             MaxLength       =   4
  390.             TabIndex        =   21
  391.             Top             =   2160
  392.             Width           =   495
  393.          End
  394.          Begin VB.Label Label1 
  395.             Caption         =   "Line 1"
  396.             Height          =   255
  397.             Index           =   5
  398.             Left            =   120
  399.             TabIndex        =   44
  400.             Top             =   360
  401.             Width           =   975
  402.          End
  403.          Begin VB.Label Label1 
  404.             Caption         =   "Line 2"
  405.             Height          =   255
  406.             Index           =   6
  407.             Left            =   120
  408.             TabIndex        =   43
  409.             Top             =   720
  410.             Width           =   975
  411.          End
  412.          Begin VB.Label Label1 
  413.             Caption         =   "Line 3"
  414.             Height          =   255
  415.             Index           =   7
  416.             Left            =   120
  417.             TabIndex        =   42
  418.             Top             =   1080
  419.             Width           =   975
  420.          End
  421.          Begin VB.Label Label1 
  422.             Caption         =   "City"
  423.             Height          =   255
  424.             Index           =   10
  425.             Left            =   120
  426.             TabIndex        =   41
  427.             Top             =   1440
  428.             Width           =   975
  429.          End
  430.          Begin VB.Label Label1 
  431.             Caption         =   "State"
  432.             Height          =   255
  433.             Index           =   8
  434.             Left            =   120
  435.             TabIndex        =   40
  436.             Top             =   1800
  437.             Width           =   975
  438.          End
  439.          Begin VB.Label Label1 
  440.             Caption         =   "Zip Code"
  441.             Height          =   255
  442.             Index           =   9
  443.             Left            =   120
  444.             TabIndex        =   39
  445.             Top             =   2160
  446.             Width           =   975
  447.          End
  448.       End
  449.       Begin VB.Label efFormattedPhoneNumber 
  450.          BorderStyle     =   1  'Fixed Single
  451.          ForeColor       =   &H00FF0000&
  452.          Height          =   255
  453.          Left            =   -74880
  454.          TabIndex        =   51
  455.          Top             =   2640
  456.          Width           =   4095
  457.       End
  458.       Begin VB.Label Label1 
  459.          Caption         =   "Formatted Phone"
  460.          Height          =   255
  461.          Index           =   21
  462.          Left            =   -74880
  463.          TabIndex        =   50
  464.          Top             =   2400
  465.          Width           =   1575
  466.       End
  467.       Begin VB.Label efFormattedAddress 
  468.          BorderStyle     =   1  'Fixed Single
  469.          ForeColor       =   &H00FF0000&
  470.          Height          =   855
  471.          Left            =   120
  472.          TabIndex        =   49
  473.          Top             =   2040
  474.          Width           =   4095
  475.       End
  476.       Begin VB.Label Label1 
  477.          Caption         =   "Formatted Address"
  478.          Height          =   255
  479.          Index           =   13
  480.          Left            =   120
  481.          TabIndex        =   48
  482.          Top             =   1800
  483.          Width           =   1575
  484.       End
  485.    End
  486.    Begin VB.Label lblPersonDetails 
  487.       AutoSize        =   -1  'True
  488.       BackColor       =   &H00C0C0C0&
  489.       BorderStyle     =   1  'Fixed Single
  490.       Caption         =   "lblPersonDetails"
  491.       ForeColor       =   &H00000080&
  492.       Height          =   255
  493.       Left            =   0
  494.       TabIndex        =   58
  495.       Top             =   5880
  496.       Width           =   8775
  497.       WordWrap        =   -1  'True
  498.    End
  499.    Begin VB.Label efAge 
  500.       BorderStyle     =   1  'Fixed Single
  501.       ForeColor       =   &H00FF0000&
  502.       Height          =   255
  503.       Left            =   3600
  504.       TabIndex        =   55
  505.       Top             =   2280
  506.       Width           =   615
  507.    End
  508.    Begin VB.Label Label1 
  509.       Caption         =   "Age"
  510.       Height          =   255
  511.       Index           =   17
  512.       Left            =   3600
  513.       TabIndex        =   54
  514.       Top             =   2040
  515.       Width           =   375
  516.    End
  517.    Begin VB.Label Label1 
  518.       Caption         =   "Formatted Name"
  519.       Height          =   255
  520.       Index           =   14
  521.       Left            =   0
  522.       TabIndex        =   53
  523.       Top             =   2040
  524.       Width           =   1575
  525.    End
  526.    Begin VB.Label efFormattedName 
  527.       BorderStyle     =   1  'Fixed Single
  528.       ForeColor       =   &H00FF0000&
  529.       Height          =   255
  530.       Left            =   0
  531.       TabIndex        =   52
  532.       Top             =   2280
  533.       Width           =   3495
  534.    End
  535. Attribute VB_Name = "CustomerDetailsListBoxNoDataControl"
  536. Attribute VB_Creatable = False
  537. Attribute VB_Exposed = False
  538. Option Explicit
  539. ' This example show how the VBOF can
  540. '   support the VB application in an enriched
  541. '   object-oriented manner without the need
  542. '   for conventional, GUI-centric VB programming
  543. '   techniques, such as extensive the use of the
  544. '   VB DataControl.
  545. ' This example expoits the ability of the
  546. '   VBOFCollection to work in conjunction with
  547. '   the VBOFListBoxWrapper to control
  548. '   VB ListBoxes in an object-oriented manner
  549. Private pvtCurrentPerson As Person
  550. Private pvtCurrentAddress As Address
  551. Private pvtCurrentPhone As Phone
  552. Private pvtState As State
  553. Private pvtPersons As VBOFCollection
  554. Private pvtPersonsListBoxWrapper As VBOFListBoxWrapper
  555. Private pvtAddresses As VBOFCollection
  556. Private pvtAddressesListBoxWrapper As VBOFListBoxWrapper
  557. Private pvtPhones As VBOFCollection
  558. Private pvtPhonesListBoxWrapper As VBOFListBoxWrapper
  559. Private pvtStates As VBOFCollection
  560. Private pvtStatesListBoxWrapper As VBOFListBoxWrapper
  561. Private pvtGenderCodes As VBOFCollection
  562. Private pvtGenderCodesListBoxWrapper As VBOFListBoxWrapper
  563. Private pvtMaritalStatusCodes As VBOFCollection
  564. Private pvtMaritalStatusCodesListBoxWrapper As VBOFListBoxWrapper
  565. Public ObjectManager As VBOFObjectManager
  566. Private Sub DisplayPersonalLineage()
  567.     lblPersonDetails = pvtCurrentPerson.PersonalInformation
  568. End Sub
  569. Private Sub DisplayStateCapital()
  570.     If pvtCurrentAddress Is Nothing Then
  571.         Exit Sub
  572.     End If
  573.     If pvtCurrentAddress.State Is Nothing _
  574.     Then
  575.         Exit Sub
  576.     End If
  577.     lblPersonDetails = "Capital city of " & pvtCurrentAddress.State.StateName & " is " & pvtCurrentAddress.State.CapitalCity
  578. End Sub
  579. Private Sub GetListBoxWrappers()
  580.     Set pvtAddresses = _
  581.         New VBOFCollection
  582.         
  583.     Set pvtPhones = _
  584.         New VBOFCollection
  585. ' attach the Collection, ListBox and ListBoxWrapper
  586.     Set pvtPersonsListBoxWrapper = _
  587.         ObjectManager. _
  588.             NewVBOFListBoxWrapper( _
  589.             Collection:=pvtPersons, _
  590.             ListBox:=List1)
  591. ' attach the Collection, ListBox and ListBoxWrapper
  592.     Set pvtAddressesListBoxWrapper = _
  593.         ObjectManager. _
  594.             NewVBOFListBoxWrapper( _
  595.             Collection:=pvtAddresses, _
  596.             ListBox:=List2)
  597. ' attach the Collection, ListBox and ListBoxWrapper
  598.     Set pvtPhonesListBoxWrapper = _
  599.         ObjectManager. _
  600.             NewVBOFListBoxWrapper( _
  601.             Collection:=pvtPhones, _
  602.             ListBox:=List3)
  603. ' attach the Collection, ListBox and ListBoxWrapper
  604.     Set pvtStatesListBoxWrapper = _
  605.         ObjectManager. _
  606.             NewVBOFListBoxWrapper( _
  607.             Collection:=pvtStates, _
  608.             ListBox:=lbxStateCodes)
  609.     pvtStatesListBoxWrapper. _
  610.         AddItems
  611. ' attach the Collection, ListBox and ListBoxWrapper
  612.     Set pvtGenderCodesListBoxWrapper = _
  613.         ObjectManager. _
  614.             NewVBOFListBoxWrapper( _
  615.             Collection:=pvtGenderCodes, _
  616.             ListBox:=lbxGenderCodes)
  617.     pvtGenderCodesListBoxWrapper. _
  618.         AddItems
  619. ' attach the Collection, ListBox and ListBoxWrapper
  620.     Set pvtMaritalStatusCodesListBoxWrapper = _
  621.         ObjectManager. _
  622.             NewVBOFListBoxWrapper( _
  623.             Collection:=pvtMaritalStatusCodes, _
  624.             ListBox:=lbxMaritalStatusCodes)
  625.     pvtMaritalStatusCodesListBoxWrapper. _
  626.         AddItems
  627. End Sub
  628. Private Sub RefreshAddressList(Optional Person As Variant)
  629.     Set pvtAddresses = _
  630.         Person.Addresses
  631.     Set pvtAddresses.Parent = _
  632.         pvtCurrentPerson
  633. ' rebind the Collection, ListBox and ListBoxWrapper
  634.     pvtAddressesListBoxWrapper.Rebind _
  635.         Collection:=pvtAddresses
  636.        
  637. ' populate the ListBox from the Addresses Collection
  638.     pvtAddressesListBoxWrapper.Clear
  639.     pvtAddressesListBoxWrapper.AddItems
  640.             
  641. ' set the ListIndex to the previously selected item
  642. '   or the first entry
  643.     If Not pvtCurrentAddress Is Nothing Then
  644.         pvtAddressesListBoxWrapper.ListIndex = _
  645.                 pvtAddresses.CollectionIndex _
  646.                     (Item:=pvtCurrentAddress) - 1
  647.     Else
  648.         pvtAddressesListBoxWrapper.ListIndex = 0
  649.     End If
  650. ' get the object at the ListIndex
  651.     Set pvtCurrentAddress = _
  652.         pvtAddressesListBoxWrapper. _
  653.             ListIndexObject
  654. ' display the current address
  655.     RefreshAddressFields
  656. End Sub
  657. Private Sub RefreshCustomerList()
  658. ' populate the ListBox from the Persons Collection
  659.     pvtPersonsListBoxWrapper.Clear
  660.     pvtPersonsListBoxWrapper.AddItems
  661.                 
  662. ' set the ListIndex to the previously selected item
  663. '   or the first entry
  664.     If Not pvtCurrentPerson Is Nothing Then
  665.         If pvtPersons.CollectionIndex _
  666.             (Item:=pvtCurrentPerson) >= 0 Then
  667.             
  668.             pvtPersonsListBoxWrapper.ListIndex = _
  669.                 pvtPersons.CollectionIndex _
  670.                     (Item:=pvtCurrentPerson) - 1
  671.         
  672.         Else
  673.             pvtPersonsListBoxWrapper.ListIndex = 0
  674.                     
  675.             Set pvtCurrentPerson = _
  676.                 pvtPersonsListBoxWrapper. _
  677.                     ListIndexObject
  678.         End If
  679.     Else
  680.         If pvtPersonsListBoxWrapper.ListCount > 0 Then
  681.             pvtPersonsListBoxWrapper.ListIndex = 0
  682.             
  683.             Set pvtCurrentPerson = _
  684.                 pvtPersonsListBoxWrapper. _
  685.                     ListIndexObject
  686.         End If
  687.     End If
  688. ' preselect the previously CurrentPerson
  689.     If Not pvtCurrentPerson Is Nothing Then
  690.         Set pvtPersonsListBoxWrapper. _
  691.             SelectObject = _
  692.                 pvtCurrentPerson
  693.     End If
  694. End Sub
  695. Private Sub RefreshPhoneList(Optional Person As Variant)
  696.     Set pvtPhones = _
  697.         Person.Phones
  698.     Set pvtPhones.Parent = _
  699.         pvtCurrentPerson
  700. ' rebind the Collection, ListBox and ListBoxWrapper
  701.     pvtPhonesListBoxWrapper.Rebind _
  702.         Collection:=pvtPhones
  703. ' populate the ListBox from the Phones Collection
  704.     pvtPhonesListBoxWrapper.Clear
  705.     pvtPhonesListBoxWrapper.AddItems
  706.             
  707. ' set the ListIndex to the first entry
  708. ' set the ListIndex to the previously selected item
  709. '   or the first entry
  710.     If Not pvtCurrentPhone Is Nothing Then
  711.         pvtPhonesListBoxWrapper.ListIndex = _
  712.                 pvtPhones.CollectionIndex _
  713.                     (Item:=pvtCurrentPhone) - 1
  714.     Else
  715.         pvtPhonesListBoxWrapper.ListIndex = 0
  716.     End If
  717. ' get the object at the ListIndex
  718.     Set pvtCurrentPhone = _
  719.         pvtPhonesListBoxWrapper. _
  720.             ListIndexObject
  721. ' display the current phone
  722.     RefreshPhoneFields
  723. End Sub
  724. Private Sub Command1_Click()
  725.     Dim tempCollection As Collection
  726.     Dim tempPerson As Person
  727.     Dim tempNameList As String
  728.     Set tempCollection = _
  729.         pvtPersonsListBoxWrapper. _
  730.             SelectedObjects
  731.     tempNameList = ""
  732.     For Each tempPerson In tempCollection
  733.         If tempNameList = "" Then
  734.             tempNameList = tempPerson.FormattedName
  735.         Else
  736.             tempNameList = tempNameList & ", " & vbCrLf & tempPerson.FormattedName
  737.         End If
  738.     Next tempPerson
  739.     MsgBox "To demonstrate the '(Get) pvtListBoxSelectedObjects' method, there are " & tempCollection.Count & " selected items:" & vbCrLf & tempNameList & vbCrLf & vbCrLf & "The first of these selected entries will be unselected to demonstrate the '(Set) pvtListBoxSelectedObjects' method."
  740.     tempCollection.Remove 1
  741.     Set pvtPersonsListBoxWrapper. _
  742.         SelectedObjects = tempCollection
  743. End Sub
  744. Private Sub efFormattedAddress_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  745.     DisplayStateCapital
  746. End Sub
  747. Private Sub efFormattedName_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  748.     DisplayPersonalLineage
  749. End Sub
  750. Private Sub Form_Load()
  751.     Set pvtStates = _
  752.         pubStates
  753.     Set pvtGenderCodes = _
  754.         pubGenderCodes
  755.     Set pvtMaritalStatusCodes = _
  756.         pubMaritalStatusCodes
  757.     Set pvtPersons = _
  758.         pubPersons
  759.     GetListBoxWrappers
  760.     RefreshCustomerList
  761.     List1_Click
  762.     RegisterForEvents
  763. End Sub
  764. Public Sub ObjectEventCallBack(Optional Event As Variant, Optional Object As Variant)
  765.     Dim tempObjectType As String
  766.     Dim tempUCaseEvent As String
  767.     On Local Error Resume Next
  768.     tempObjectType = TypeName(Object)
  769.     tempUCaseEvent = UCase$(Event)
  770.     If tempObjectType = "Person" Then
  771.         
  772.         If tempUCaseEvent = "REMOVEDITEM" _
  773.         Or tempUCaseEvent = "REPLACEDITEM" _
  774.         Or tempUCaseEvent = "CHANGED" _
  775.         Then
  776.             RefreshCustomerList
  777.             
  778.             If Object.ObjectID = pvtCurrentPerson.ObjectID Then
  779.                 RefreshCustomerFields
  780.             End If
  781.         End If
  782.     End If
  783.     If tempObjectType = "Address" Then
  784.         RefreshAddressFields
  785.     End If
  786.     If tempObjectType = "Phone" Then
  787.         RefreshPhoneFields
  788.     End If
  789. End Sub
  790. Private Sub RefreshAddressFields()
  791.     On Local Error Resume Next
  792.     If pvtCurrentAddress Is Nothing Or Err = 3021 Then
  793.         efLine1 = ""
  794.         efLine2 = ""
  795.         efLine3 = ""
  796.         efCity = ""
  797.         lbxStateCodes = ""
  798.         efZipCode = ""
  799.         efZipSupplement = ""
  800.         efZipExtension = ""
  801.         efFormattedAddress = ""
  802.         Exit Sub
  803.     End If
  804.     efLine1 = pvtCurrentAddress.Line1
  805.     efLine2 = pvtCurrentAddress.Line2
  806.     efLine3 = pvtCurrentAddress.Line3
  807.     efCity = pvtCurrentAddress.City
  808.     lbxStateCodes = _
  809.         pvtCurrentAddress.State.StateCode
  810.     efZipCode = pvtCurrentAddress.ZipCode
  811.     efZipSupplement = pvtCurrentAddress.ZipSupplementString
  812.     efZipExtension = pvtCurrentAddress.ZipExtensionString
  813.     efFormattedAddress = pvtCurrentAddress.FormattedAddress
  814.     Set pvtAddressesListBoxWrapper. _
  815.         SelectObject = _
  816.             pvtCurrentAddress
  817. '    DisplayStateCapital
  818. End Sub
  819. Private Function PopulateCurrentAddress()
  820.     On Local Error Resume Next
  821.     With pvtCurrentAddress
  822.         .Line1 = efLine1
  823.         .Line2 = efLine2
  824.         .Line3 = efLine3
  825.         .City = efCity
  826.         .ZipCode = efZipCode
  827.         .ZipSupplement = efZipSupplement
  828.         .ZipExtension = efZipExtension
  829.     End With
  830.     Set pvtCurrentAddress.State = _
  831.         pvtStatesListBoxWrapper.ListIndexObject
  832. End Function
  833. Private Function PopulateCurrentPerson()
  834.     On Local Error Resume Next
  835.     With pvtCurrentPerson
  836.         .CustomerNumber = efCustomerNumber
  837.         .FirstName = efFirstName
  838.         .LastName = efLastName
  839.         .SSN = efSSN
  840.         .DateOfBirth = DateValue(efDateOfBirth)
  841.         .Sex = _
  842.             pvtGenderCodesListBoxWrapper. _
  843.                 ListIndexObject _
  844.                     (pvtGenderCodesListBoxWrapper.ListBox) _
  845.                 .GenderCode
  846.         .MaritalStatus = _
  847.             pvtMaritalStatusCodesListBoxWrapper. _
  848.                 ListIndexObject _
  849.                     (pvtMaritalStatusCodesListBoxWrapper.ListBox) _
  850.                 .MaritalStatusCode
  851.     End With
  852. End Function
  853. Private Function PopulateCurrentPhone()
  854.     On Local Error Resume Next
  855.     With pvtCurrentPhone
  856.         .PhoneNumber = efPhoneNumber
  857.         .Usage = efUsage
  858.     End With
  859. End Function
  860. Sub RefreshCustomerFields()
  861.     On Local Error Resume Next
  862.         
  863. ' display the person's detail information
  864.     efCustomerNumber = pvtCurrentPerson.CustomerNumber
  865.     efFirstName = pvtCurrentPerson.FirstName
  866.     efLastName = pvtCurrentPerson.LastName
  867.     efSSN = pvtCurrentPerson.SSN
  868.     efDateOfBirth = Format$(pvtCurrentPerson.DateOfBirth, "mm/dd/yyyy")
  869.     lbxMaritalStatusCodes = pvtCurrentPerson.MaritalStatus
  870.     lbxGenderCodes = pvtCurrentPerson.Sex
  871.     efFormattedName = _
  872.         pvtCurrentPerson.FormattedName
  873.     efAge = pvtCurrentPerson.Age
  874.     Set pvtPersonsListBoxWrapper. _
  875.         SelectObject = _
  876.             pvtCurrentPerson
  877.     DisplayPersonalLineage
  878. End Sub
  879. Private Sub RefreshPhoneFields()
  880.     On Local Error Resume Next
  881.     If pvtCurrentPhone Is Nothing Or Err = 3021 Then
  882.         efPhoneNumber = ""
  883.         efUsage = ""
  884.         efFormattedPhoneNumber = ""
  885.         Exit Sub
  886.     End If
  887.     efPhoneNumber = pvtCurrentPhone.PhoneNumber
  888.     efUsage = pvtCurrentPhone.Usage
  889.     efFormattedPhoneNumber = pvtCurrentPhone.FormattedPhoneNumber
  890.     Set pvtPhonesListBoxWrapper. _
  891.         SelectObject = _
  892.             pvtCurrentPhone
  893. End Sub
  894. Private Sub RegisterForEvents()
  895. #If NoEventMgr = False Then
  896.     ObjectManager.RegisterForObjectEvent _
  897.         TriggerObjectType:="Person", _
  898.         RegisterObject:=Me
  899.     ObjectManager.RegisterForObjectEvent _
  900.         TriggerObjectType:="Address", _
  901.         RegisterObject:=Me
  902.     ObjectManager.RegisterForObjectEvent _
  903.         TriggerObjectType:="Phone", _
  904.         RegisterObject:=Me
  905.     ObjectManager.RegisterForCollectionEvent _
  906.         Collection:=pvtPersons, _
  907.         RegisterObject:=Me
  908.     ObjectManager.RegisterForCollectionEvent _
  909.         Collection:=pvtAddresses, _
  910.         RegisterObject:=Me
  911.     ObjectManager.RegisterForCollectionEvent _
  912.         Collection:=pvtPhones, _
  913.         RegisterObject:=Me
  914. #End If
  915. End Sub
  916. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  917.     Me.MousePointer = vbArrowHourglass
  918.     ObjectManager.Form_QueryUnload _
  919.         Me, _
  920.         pvtPersonsListBoxWrapper, _
  921.         pvtAddressesListBoxWrapper, _
  922.         pvtPhonesListBoxWrapper, _
  923.         pvtStatesListBoxWrapper, _
  924.         pvtGenderCodesListBoxWrapper, _
  925.         pvtMaritalStatusCodesListBoxWrapper
  926.     Set pvtPersons = Nothing
  927.     Set pvtAddresses = Nothing
  928.     Set pvtPhones = Nothing
  929.     Set pvtStates = Nothing
  930.     Set pvtGenderCodes = Nothing
  931.     Set pvtMaritalStatusCodes = Nothing
  932. #If NoEventMgr = False Then
  933.     ObjectManager. _
  934.         UnRegisterForAllEvents _
  935.         RegisterObject:=Me
  936. #End If
  937.     Me.MousePointer = vbArrow
  938. End Sub
  939. Private Sub List1_Click()
  940.     Dim tempObjectID As Long
  941.     Set pvtCurrentPerson = _
  942.         pvtPersonsListBoxWrapper. _
  943.             ListIndexObject
  944. ' These next two statements don't contribute anything
  945. '   to the application, but they illustrate usages
  946. '   of other interesting ListBoxWrapper methods.
  947.     Set pvtPersonsListBoxWrapper. _
  948.         SelectObject = _
  949.         pvtCurrentPerson
  950.     Set pvtCurrentPerson = _
  951.         pvtPersonsListBoxWrapper. _
  952.         SelectObject
  953.     RefreshCustomerFields
  954.     RefreshAddressList _
  955.         pvtCurrentPerson
  956.     RefreshPhoneList _
  957.         pvtCurrentPerson
  958.         
  959.     DisplayPersonalLineage
  960. End Sub
  961. Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  962.     DisplayPersonalLineage
  963. End Sub
  964. Private Sub List2_Click()
  965. ' get the object at the ListIndex
  966.     Set pvtCurrentAddress = _
  967.         pvtAddressesListBoxWrapper. _
  968.             ListIndexObject
  969. ' display the current address
  970.     RefreshAddressFields
  971. End Sub
  972. Private Sub List2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  973.     DisplayStateCapital
  974. End Sub
  975. Private Sub List3_Click()
  976. ' get the object at the ListIndex
  977.     Set pvtCurrentPhone = _
  978.         pvtPhonesListBoxWrapper. _
  979.             ListIndexObject
  980. ' display the current phone
  981.     RefreshPhoneFields
  982. End Sub
  983. Private Sub pbAddNewAddress_Click()
  984.     Dim tempNewAddress As New Address
  985.         
  986.     On Local Error Resume Next
  987.     Me.MousePointer = vbArrowHourglass
  988.     Set pvtCurrentAddress = tempNewAddress
  989.     PopulateCurrentAddress
  990.             
  991.     Set pvtCurrentAddress = _
  992.         pvtCurrentPerson.AddAddress _
  993.             (Item:=tempNewAddress)
  994.         
  995.     RefreshAddressList pvtCurrentPerson
  996.     Me.MousePointer = vbArrow
  997. End Sub
  998. Private Sub pbAddNewCustomer_Click()
  999.     Dim tempNewPerson As New Person
  1000.         
  1001.     On Local Error Resume Next
  1002.     Me.MousePointer = vbArrowHourglass
  1003.     Set pvtCurrentPerson = tempNewPerson
  1004.     PopulateCurrentPerson
  1005.     Set pvtCurrentPerson = _
  1006.         pvtPersons.Add _
  1007.             (Item:=tempNewPerson)
  1008.         
  1009.     RefreshAddressList pvtCurrentPerson
  1010.     RefreshPhoneList pvtCurrentPerson
  1011.     Me.MousePointer = vbArrow
  1012. End Sub
  1013. Private Sub pbAddPhone_Click()
  1014.     Dim tempNewPhone As New Phone
  1015.         
  1016.     On Local Error Resume Next
  1017.     Me.MousePointer = vbArrowHourglass
  1018.     Set pvtCurrentPhone = tempNewPhone
  1019.     PopulateCurrentPhone
  1020.             
  1021.     Set pvtCurrentPhone = _
  1022.         pvtCurrentPerson.AddPhone _
  1023.             (Item:=tempNewPhone)
  1024.         
  1025.     RefreshPhoneList pvtCurrentPerson
  1026.     Me.MousePointer = vbArrow
  1027. End Sub
  1028. Private Sub pbDeleteAddress_Click()
  1029.         
  1030.     On Local Error Resume Next
  1031.     Me.MousePointer = vbArrowHourglass
  1032.     pvtAddresses.Remove _
  1033.         Item:=pvtCurrentAddress
  1034.         
  1035.     Set pvtCurrentAddress = Nothing
  1036.         
  1037.     RefreshAddressList pvtCurrentPerson
  1038.     Me.MousePointer = vbArrow
  1039. End Sub
  1040. Private Sub pbDeleteCustomer_Click()
  1041.         
  1042.     On Local Error Resume Next
  1043.     Me.MousePointer = vbArrowHourglass
  1044. MsgBox "Test this code."
  1045.     pvtPersonsListBoxWrapper.RemoveObject _
  1046.         pvtCurrentPerson
  1047.     Set pvtCurrentPerson = Nothing
  1048.         
  1049.     RefreshCustomerList
  1050.     Me.MousePointer = vbArrow
  1051. End Sub
  1052. Private Sub pbDeletePhone_Click()
  1053.         
  1054.     On Local Error Resume Next
  1055.     Me.MousePointer = vbArrowHourglass
  1056.     pvtPhones.Remove _
  1057.         Item:=pvtCurrentPhone
  1058.         
  1059.     Set pvtCurrentPhone = Nothing
  1060.         
  1061.     RefreshPhoneList pvtCurrentPerson
  1062.     Me.MousePointer = vbArrow
  1063. End Sub
  1064. Private Sub pbOK_Click()
  1065.     Unload Me
  1066. End Sub
  1067. Private Sub pbUpdateAddress_Click()
  1068.           
  1069.     On Local Error Resume Next
  1070.     Me.MousePointer = vbArrowHourglass
  1071.     PopulateCurrentAddress
  1072.     pvtAddresses.Replace _
  1073.         Item:=pvtCurrentAddress, _
  1074.         ReplaceWith:=pvtCurrentAddress
  1075.         
  1076. ' trigger the "Changed" event
  1077. ' Note:  This typically a responsibility of the BOM.
  1078. '   But in this demo package, if it were, then the
  1079. '   demo window which is based on the DataControl
  1080. '   would do bunches of database I/O and run for
  1081. '   an extraordinary period.
  1082.     pvtCurrentAddress. _
  1083.         ObjectHasChanged
  1084.         
  1085.     RefreshAddressList pvtCurrentPerson
  1086.     Me.MousePointer = vbArrow
  1087. End Sub
  1088. Private Sub pbUpdateCustomer_Click()
  1089.         
  1090.     On Local Error Resume Next
  1091.     Me.MousePointer = vbArrowHourglass
  1092.     PopulateCurrentPerson
  1093.     pvtPersons.Replace _
  1094.         Item:=pvtCurrentPerson, _
  1095.         ReplaceWith:=pvtCurrentPerson
  1096. ' trigger the "Changed" event
  1097. ' Note:  This typically a responsibility of the BOM.
  1098. '   But in this demo package, if it were, then the
  1099. '   demo window which is based on the DataControl
  1100. '   would do bunches of database I/O and run for
  1101. '   an extraordinary period.
  1102.     pvtCurrentPerson. _
  1103.         ObjectHasChanged
  1104.         
  1105.     RefreshCustomerList
  1106.     Me.MousePointer = vbArrow
  1107. End Sub
  1108. Private Sub pbUpdatePhone_Click()
  1109.         
  1110.     On Local Error Resume Next
  1111.     Me.MousePointer = vbArrowHourglass
  1112.     PopulateCurrentPhone
  1113.     pvtPhones.Replace _
  1114.         Item:=pvtCurrentPhone, _
  1115.         ReplaceWith:=pvtCurrentPhone
  1116.         
  1117. ' trigger the "Changed" event
  1118. ' Note:  This typically a responsibility of the BOM.
  1119. '   But in this demo package, if it were, then the
  1120. '   demo window which is based on the DataControl
  1121. '   would do bunches of database I/O and run for
  1122. '   an extraordinary period.
  1123.     pvtCurrentPhone. _
  1124.         ObjectHasChanged
  1125.         
  1126.     RefreshPhoneList pvtCurrentPerson
  1127.     Me.MousePointer = vbArrow
  1128. End Sub
  1129.