home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / PROGWOB / PWOBRICK.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-26  |  6.3 KB  |  209 lines

  1. VERSION 5.00
  2. Begin VB.Form frmBricks 
  3.    Caption         =   "Employees Collection - House of Bricks"
  4.    ClientHeight    =   3525
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1515
  7.    ClientWidth     =   4995
  8.    LinkTopic       =   "Form1"
  9.    LockControls    =   -1  'True
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   3525
  12.    ScaleWidth      =   4995
  13.    Begin VB.CommandButton cmdTrouble 
  14.       Caption         =   "&Trouble"
  15.       Enabled         =   0   'False
  16.       Height          =   465
  17.       Left            =   3150
  18.       TabIndex        =   8
  19.       Top             =   2250
  20.       Width           =   1545
  21.    End
  22.    Begin VB.CommandButton cmdClose 
  23.       Caption         =   "&Close"
  24.       Height          =   285
  25.       Left            =   3150
  26.       TabIndex        =   9
  27.       Top             =   2880
  28.       Width           =   1545
  29.    End
  30.    Begin VB.CommandButton cmdListEmployees 
  31.       Caption         =   "&Refresh List"
  32.       Height          =   285
  33.       Left            =   3150
  34.       TabIndex        =   7
  35.       Top             =   1800
  36.       Width           =   1545
  37.    End
  38.    Begin VB.CommandButton cmdDeleteEmployee 
  39.       Caption         =   "&Delete"
  40.       Height          =   285
  41.       Left            =   3150
  42.       TabIndex        =   6
  43.       Top             =   1440
  44.       Width           =   1545
  45.    End
  46.    Begin VB.CommandButton cmdAddEmployee 
  47.       Caption         =   "&Add"
  48.       Default         =   -1  'True
  49.       Enabled         =   0   'False
  50.       Height          =   285
  51.       Left            =   3150
  52.       TabIndex        =   5
  53.       Top             =   1080
  54.       Width           =   1545
  55.    End
  56.    Begin VB.ListBox lstEmployees 
  57.       Height          =   1845
  58.       Left            =   180
  59.       TabIndex        =   4
  60.       Top             =   1080
  61.       Width           =   2715
  62.    End
  63.    Begin VB.TextBox txtSalary 
  64.       Height          =   285
  65.       Left            =   2700
  66.       TabIndex        =   3
  67.       Top             =   450
  68.       Width           =   1995
  69.    End
  70.    Begin VB.TextBox txtName 
  71.       Height          =   285
  72.       Left            =   180
  73.       TabIndex        =   1
  74.       Top             =   450
  75.       Width           =   2265
  76.    End
  77.    Begin VB.Label Label2 
  78.       Caption         =   "&Salary"
  79.       Height          =   195
  80.       Left            =   2700
  81.       TabIndex        =   2
  82.       Top             =   180
  83.       Width           =   2025
  84.    End
  85.    Begin VB.Label Label1 
  86.       Caption         =   "&Name"
  87.       Height          =   195
  88.       Left            =   180
  89.       TabIndex        =   0
  90.       Top             =   180
  91.       Width           =   2265
  92.    End
  93. Attribute VB_Name = "frmBricks"
  94. Attribute VB_GlobalNameSpace = False
  95. Attribute VB_Creatable = False
  96. Attribute VB_PredeclaredId = True
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99. Public sbMain As New SmallBusiness3
  100. Private Sub cmdAddEmployee_Click()
  101.     Dim empNew As Employee
  102.     If Not IsNumeric(txtSalary) Then
  103.         MsgBox "Salary is not a valid amount."
  104.         With txtSalary
  105.             .SetFocus
  106.             .SelStart = 0
  107.             .SelLength = Len(.Text)
  108.         End With
  109.         Exit Sub
  110.     End If
  111.     ' The new employee can only be created
  112.     '   by calling the Add method of the
  113.     '   Employees collection.
  114.     Set empNew = sbMain.Employees.Add(txtName.Text, CDbl(txtSalary.Text))
  115.     ' Add new employee to the list box.
  116.     With empNew
  117.         lstEmployees.AddItem .ID & ", " & .Name & ", " & .Salary
  118.     End With
  119.     With lstEmployees
  120.         ' Select the newly added item.
  121.         .ListIndex = .NewIndex
  122.     End With
  123.     txtName.Text = ""
  124.     txtSalary.Text = ""
  125.     txtName.SetFocus
  126. End Sub
  127. Private Sub cmdClose_Click()
  128.     Unload Me
  129. End Sub
  130. Private Sub cmdDeleteEmployee_Click()
  131.     Dim lngDeletedItem As Long
  132.     With lstEmployees
  133.         lngDeletedItem = .ListIndex
  134.         ' Check to make sure there is an employee selected.
  135.         If .ListIndex > -1 Then
  136.             ' The employee ID is the first six characters on the line.
  137.             sbMain.Employees.Delete Left(.Text, 6)
  138.             ' Remove the selected item.
  139.             .RemoveItem .ListIndex
  140.             If .ListCount = 0 Then
  141.                 ' If the list is now empty,
  142.                 '   don't attempt to set a new
  143.                 '   selection.
  144.                 Exit Sub
  145.             End If
  146.             ' Was the deleted item at the very bottom of
  147.             '   the list box?  If so, its index wil be
  148.             '   greater than or equal to the list count...
  149.             If .ListCount <= lngDeletedItem Then
  150.                 '   ...so set the current selection to
  151.                 '   the new bottom item...
  152.                 .ListIndex = lngDeletedItem - 1
  153.             Else
  154.                 '   ...otherwise, keep the selection in
  155.                 '   the same physical position in the
  156.                 '   list.
  157.                 .ListIndex = lngDeletedItem
  158.             End If
  159.         Else
  160.             MsgBox "No employee selected."
  161.         End If
  162.     End With
  163. End Sub
  164. Private Sub cmdListEmployees_Click()
  165.     Dim emp As Employee
  166.     With lstEmployees
  167.         .Clear
  168.         For Each emp In sbMain.Employees
  169.             With emp
  170.                 lstEmployees.AddItem .ID & ", " & .Name & ", " & .Salary
  171.             End With
  172.         Next
  173.         If .ListCount <> 0 Then
  174.             ' If there are any items in the list,
  175.             '   select the first.
  176.             .ListIndex = 0
  177.         End If
  178.     End With
  179. End Sub
  180. Private Sub Form_Unload(Cancel As Integer)
  181.     ' Set the hidden global variable for
  182.     '   this form to Nothing, to release
  183.     '   its resources.
  184.     Set frmBricks = Nothing
  185. End Sub
  186. Private Sub txtName_Change()
  187.     Call EnableAddButton
  188. End Sub
  189. Private Sub txtSalary_Change()
  190.     Call EnableAddButton
  191. End Sub
  192. Private Sub txtSalary_KeyPress(KeyAscii As Integer)
  193.     Select Case KeyAscii
  194.         Case 48 To 57   ' Allow digits
  195.         Case 8      ' Allow backspace
  196.         Case 46     ' Allow period
  197.         Case Else
  198.             KeyAscii = 0
  199.             Beep
  200.     End Select
  201. End Sub
  202. Private Sub EnableAddButton()
  203.     If (Len(txtName) > 0) And (Len(txtSalary) > 0) Then
  204.         cmdAddEmployee.Enabled = True
  205.     Else
  206.         cmdAddEmployee.Enabled = False
  207.     End If
  208. End Sub
  209.