home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / recedit.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  13.2 KB  |  436 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Record Editor"
  4.    ClientHeight    =   5385
  5.    ClientLeft      =   975
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6375
  8.    ClipControls    =   0   'False
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   5820
  19.    Left            =   915
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   5385
  22.    ScaleWidth      =   6375
  23.    Top             =   1140
  24.    Width           =   6495
  25.    Begin VB.Frame FileIOFrame 
  26.       Enabled         =   0   'False
  27.       Height          =   3255
  28.       Left            =   4320
  29.       TabIndex        =   16
  30.       Top             =   120
  31.       Width           =   1935
  32.       Begin VB.CommandButton NextRecord 
  33.          Caption         =   "Next Record"
  34.          Height          =   495
  35.          Left            =   120
  36.          TabIndex        =   20
  37.          Top             =   2625
  38.          Width           =   1695
  39.       End
  40.       Begin VB.CommandButton PreviousRecord 
  41.          Caption         =   "Previous Record"
  42.          Height          =   495
  43.          Left            =   120
  44.          TabIndex        =   19
  45.          Top             =   1920
  46.          Width           =   1695
  47.       End
  48.       Begin VB.CommandButton AddRecord 
  49.          Caption         =   "Add Record"
  50.          Height          =   495
  51.          Left            =   120
  52.          TabIndex        =   18
  53.          Top             =   240
  54.          Width           =   1695
  55.       End
  56.       Begin VB.CommandButton DeleteRecord 
  57.          Caption         =   "Delete Record"
  58.          Height          =   495
  59.          Left            =   120
  60.          TabIndex        =   17
  61.          Top             =   960
  62.          Width           =   1695
  63.       End
  64.    End
  65.    Begin VB.TextBox FieldBoxes 
  66.       Height          =   2415
  67.       Index           =   6
  68.       Left            =   210
  69.       MaxLength       =   50
  70.       MultiLine       =   -1  'True
  71.       ScrollBars      =   2  'Vertical
  72.       TabIndex        =   6
  73.       Top             =   2730
  74.       Width           =   3735
  75.    End
  76.    Begin VB.TextBox FieldBoxes 
  77.       Height          =   375
  78.       Index           =   5
  79.       Left            =   2280
  80.       TabIndex        =   5
  81.       Top             =   1890
  82.       Width           =   1695
  83.    End
  84.    Begin VB.TextBox FieldBoxes 
  85.       Height          =   375
  86.       Index           =   4
  87.       Left            =   210
  88.       TabIndex        =   4
  89.       Top             =   1890
  90.       Width           =   1695
  91.    End
  92.    Begin VB.CommandButton ExitButton 
  93.       Caption         =   "Exit"
  94.       Height          =   495
  95.       Left            =   4440
  96.       TabIndex        =   8
  97.       Top             =   4320
  98.       Width           =   1695
  99.    End
  100.    Begin VB.CommandButton OpenFile 
  101.       Caption         =   "Open File"
  102.       Height          =   495
  103.       Left            =   4440
  104.       TabIndex        =   7
  105.       Top             =   3600
  106.       Width           =   1695
  107.    End
  108.    Begin VB.TextBox FieldBoxes 
  109.       Height          =   375
  110.       Index           =   3
  111.       Left            =   2280
  112.       MaxLength       =   15
  113.       TabIndex        =   3
  114.       Top             =   1155
  115.       Width           =   1695
  116.    End
  117.    Begin VB.TextBox FieldBoxes 
  118.       Height          =   375
  119.       Index           =   2
  120.       Left            =   225
  121.       TabIndex        =   2
  122.       Top             =   1155
  123.       Width           =   1695
  124.    End
  125.    Begin VB.TextBox FieldBoxes 
  126.       Height          =   375
  127.       Index           =   1
  128.       Left            =   2280
  129.       MaxLength       =   15
  130.       TabIndex        =   1
  131.       Top             =   420
  132.       Width           =   1695
  133.    End
  134.    Begin VB.TextBox FieldBoxes 
  135.       Height          =   375
  136.       Index           =   0
  137.       Left            =   210
  138.       MaxLength       =   15
  139.       TabIndex        =   0
  140.       Top             =   420
  141.       Width           =   1695
  142.    End
  143.    Begin VB.Label Label9 
  144.       Caption         =   "Last Review Comments"
  145.       Height          =   255
  146.       Left            =   210
  147.       TabIndex        =   15
  148.       Top             =   2520
  149.       Width           =   2055
  150.    End
  151.    Begin VB.Label Label8 
  152.       Caption         =   "Last Review Date"
  153.       Height          =   255
  154.       Left            =   2280
  155.       TabIndex        =   14
  156.       Top             =   1680
  157.       Width           =   1575
  158.    End
  159.    Begin VB.Label Label7 
  160.       Caption         =   "Monthly Salary"
  161.       Height          =   255
  162.       Left            =   210
  163.       TabIndex        =   13
  164.       Top             =   1680
  165.       Width           =   1335
  166.    End
  167.    Begin VB.Label Label4 
  168.       Caption         =   "Title"
  169.       Height          =   255
  170.       Left            =   2310
  171.       TabIndex        =   12
  172.       Top             =   945
  173.       Width           =   375
  174.    End
  175.    Begin VB.Label Label3 
  176.       Caption         =   "ID #"
  177.       Height          =   255
  178.       Left            =   210
  179.       TabIndex        =   11
  180.       Top             =   945
  181.       Width           =   495
  182.    End
  183.    Begin VB.Label Label2 
  184.       Caption         =   "Last Name"
  185.       Height          =   255
  186.       Left            =   2310
  187.       TabIndex        =   10
  188.       Top             =   210
  189.       Width           =   975
  190.    End
  191.    Begin VB.Label Label1 
  192.       Caption         =   "First Name"
  193.       Height          =   255
  194.       Left            =   210
  195.       TabIndex        =   9
  196.       Top             =   210
  197.       Width           =   975
  198.    End
  199. Attribute VB_Name = "Form1"
  200. Attribute VB_Creatable = False
  201. Attribute VB_Exposed = False
  202. Option Explicit
  203. Dim Employee As Person
  204. Dim OldContents As Person
  205. Dim Position As Long         ' Position describes presentation order.
  206. Dim LastRecord As Long
  207. Dim FileName As String
  208. Dim FileNum As Integer
  209. Dim FieldDirty As Boolean
  210. Private Sub AddRecord_Click()
  211.     Dim Ind As Integer
  212.     If FileNum = 0 Then Exit Sub
  213.     SaveRecordChanges
  214.     For Ind = 0 To 6
  215.         Form1.FieldBoxes(Ind).TEXT = ""
  216.     Next Ind
  217.     GetFields
  218.     LastRecord = LastRecord + 1
  219.     Put #FileNum, LastRecord, Employee
  220.     Position = LastRecord
  221.     ShowRecord
  222. End Sub
  223. Private Sub CleanUpFile()
  224.     Dim CleanFileNum As Integer
  225.     Dim Ind As Long
  226.     Dim Confirm As Integer
  227.     If FileNum = 0 Then Exit Sub
  228.     Confirm = False
  229.     CleanFileNum = FileOpener("~~Tmp~~.Tmp", conRandomFile, Len(Employee), Confirm)
  230.     For Ind = 1 To LastRecord
  231.         Get #FileNum, Ind, Employee
  232.         ' Debug.print Ind; Employee.FirstName
  233.         Put #CleanFileNum, Ind, Employee
  234.     Next Ind
  235.     Close       ' Close all files.
  236.     FileCopy "~~Tmp~~.Tmp", FileName
  237.     FileNum = FileOpener(FileName, conRandomFile, Len(Employee), Confirm)
  238.     Kill "~~Tmp~~.Tmp"
  239. End Sub
  240. Private Sub DeleteRecord_Click()
  241.     Dim TempVar As Person
  242.     Dim Ind As Integer
  243.     Dim Msg As String
  244.     If FileNum = 0 Then Exit Sub
  245.     If LastRecord = 1 Then
  246.         Msg = "This is the last record in the file. Deleting it will delete"
  247.         Msg = Msg + " the entire file."
  248.         Msg = Msg + " Record Editor will also be closed."
  249.         Msg = Msg + " Choose OK to delete the file."
  250.         Ind = MsgBox(Msg, 65, "About to delete file!")
  251.             If Ind = vbOK Then
  252.                 Close (FileNum)
  253.                 On Error Resume Next
  254.                 Kill FileName
  255.                 Unload Form1
  256.             Else
  257.                 Exit Sub    ' Cancel pressed.
  258.             End If
  259.     End If
  260.     For Ind = Position To LastRecord - 1
  261.         Get #FileNum, Ind + 1, TempVar
  262.         Put #FileNum, Ind, TempVar
  263.     Next Ind
  264.     LastRecord = LastRecord - 1
  265.     If Position > LastRecord Then
  266.         Position = LastRecord
  267.     End If
  268.     CleanUpFile
  269.     ShowRecord                          ' This displays the record that follows the deleted record.
  270.     Exit Sub
  271. End Sub
  272. Private Sub ExitButton_Click()
  273.     If FieldDirty Then SaveRecordChanges
  274.     CleanUpFile
  275.     Unload Form1
  276. End Sub
  277. Private Sub FieldBoxes_Change(Index As Integer)
  278. FieldDirty = True
  279. End Sub
  280. Private Sub FieldBoxes_GotFocus(Index As Integer)
  281.     FieldBoxes(Index).SelStart = 0
  282.     FieldBoxes(Index).SelLength = Len(FieldBoxes(Index).TEXT)
  283. End Sub
  284. Private Sub FieldBoxes_LostFocus(Index As Integer)
  285.   If Val(FieldBoxes(2).TEXT) > 32767 Then
  286.     MsgBox "Enter a number less than 32,768"
  287.     FieldBoxes(2).SetFocus
  288.   End If
  289. End Sub
  290. Private Sub Form_Load()
  291.     Dim BoxCaption As String
  292.     Dim NL As String
  293.     Dim Msg As String
  294.     ChDrive App.Path
  295.     ChDir App.Path
  296.     Form1.Show
  297.     OpenFile_Click
  298. End Sub
  299. Private Sub Form_Unload(Cancel As Integer)
  300.     End
  301. End Sub
  302. Private Sub GetFields()
  303.     Employee.FirstName = Form1.FieldBoxes(0).TEXT
  304.     Employee.LastName = Form1.FieldBoxes(1).TEXT
  305.     If IsNumeric(Form1.FieldBoxes(2).TEXT) Then
  306.         Employee.ID = CInt(Form1.FieldBoxes(2).TEXT)
  307.     Else
  308.         Employee.ID = 0
  309.     End If
  310.     Employee.Title = Form1.FieldBoxes(3).TEXT
  311.     If IsNumeric(Form1.FieldBoxes(4).TEXT) Then
  312.         Employee.MonthlySalary = CDbl(CCur(Form1.FieldBoxes(4).TEXT))
  313.     Else
  314.         Employee.MonthlySalary = CDbl(CCur(0))
  315.     End If
  316.     If IsDate(Form1.FieldBoxes(5).TEXT) Then
  317.         Employee.LastReviewDate = CLng(DateValue(Form1.FieldBoxes(5).TEXT))
  318.     Else
  319.         Employee.LastReviewDate = CLng(DateValue("1/1/1753"))
  320.     End If
  321.     Employee.ReviewComments = Form1.FieldBoxes(6).TEXT
  322. End Sub
  323. Private Sub Initialize()
  324.     LastRecord = LOF(FileNum) \ Len(Employee)
  325.     ' Debug.print LOF(FileNum), Len(Employee), LastRecord
  326.     Position = 1
  327.     If LastRecord < 1 Then
  328.         GetFields
  329.         OldContents = Employee
  330.         AddRecord_Click
  331.     Else
  332.         ShowRecord
  333.     End If
  334. End Sub
  335. Private Sub NextRecord_Click()
  336.     Dim Msg As String
  337.     SaveRecordChanges
  338.     If Position = LastRecord Then
  339.         Msg = "There are no records greater than " + Str(LastRecord) + "."
  340.         MsgBox (Msg)
  341.     Else
  342.         Position = Position + 1
  343.     End If
  344.     ShowRecord
  345.     FieldDirty = False
  346. End Sub
  347. Private Sub OpenFile_Click()
  348.     Dim Confirm As Integer
  349.     Confirm = True
  350.     If LastRecord > 0 Then
  351.         SaveRecordChanges
  352.         CleanUpFile
  353.     End If
  354.     FileNum = 0
  355.     Do While FileNum = 0
  356.         FileName = GetFileName("Enter the name of a file to create or open.")
  357.         If FileName = "" Then
  358.             FileIOFrame.Enabled = False
  359.             If LastRecord > 0 Then
  360.                 Exit Sub
  361.             Else
  362.                 End
  363.             End If
  364.         Else
  365.             FileNum = FileOpener(FileName, conRandomFile, Len(Employee), Confirm)
  366.             FileIOFrame.Enabled = True
  367.         End If
  368.     Loop
  369.     Initialize
  370.     FieldDirty = False
  371. End Sub
  372. Private Sub PreviousRecord_Click()
  373.     SaveRecordChanges
  374.     If Position = 1 Then
  375.         MsgBox ("There are no records less than 1.")
  376.     Else
  377.         Position = Position - 1
  378.     End If
  379.     ShowRecord
  380. End Sub
  381. Private Sub SaveRecordChanges()
  382.     Dim ConvertVariant As Variant
  383.     Dim Equal As Integer
  384.     Equal = True
  385.     If FileNum = 0 Then Exit Sub
  386.     GetFields
  387.     If Employee.FirstName <> OldContents.FirstName Then Equal = False
  388.     If Employee.LastName <> OldContents.LastName Then Equal = False
  389.     If Employee.ID <> OldContents.ID Then Equal = False
  390.     If Employee.Title <> OldContents.Title Then Equal = False
  391.     If Employee.MonthlySalary <> OldContents.MonthlySalary Then Equal = False
  392.     If Employee.LastReviewDate <> OldContents.LastReviewDate Then Equal = False
  393.     If Employee.ReviewComments <> OldContents.ReviewComments Then Equal = False
  394.     If Not Equal Then
  395.         ' Debug.print "Position:"; Position; " Name:"; Employee.FirstName
  396.         Put #FileNum, Position, Employee
  397.     End If
  398. End Sub
  399. Private Sub ShowRecord()
  400.     If FileNum = 0 Then Exit Sub
  401.     Get #FileNum, Position, Employee
  402.     Dim ConvertVariant As Variant
  403.     Form1.FieldBoxes(0).TEXT = Trim(Employee.FirstName)
  404.     Form1.FieldBoxes(1).TEXT = Trim(Employee.LastName)
  405.     If Employee.ID > 0 Then
  406.         Form1.FieldBoxes(2).TEXT = LTrim(Str(Employee.ID))
  407.     Else
  408.         Form1.FieldBoxes(2).TEXT = ""
  409.     End If
  410.     Form1.FieldBoxes(3) = Trim(Employee.Title)
  411.     ConvertVariant = Employee.MonthlySalary
  412.     ConvertVariant = CCur(ConvertVariant)
  413.     If ConvertVariant > 0 Then
  414.         Form1.FieldBoxes(4) = Format(ConvertVariant, "$#,##0.00;(#,##0.00)")
  415.     Else
  416.         Form1.FieldBoxes(4) = ""
  417.     End If
  418.     ConvertVariant = CDate(Employee.LastReviewDate)
  419.     If ConvertVariant <> DateValue("1/1/1753") Then
  420.         Form1.FieldBoxes(5).TEXT = ConvertVariant
  421.     Else
  422.         FieldBoxes(5) = ""
  423.     End If
  424.     Form1.FieldBoxes(6) = Trim(Employee.ReviewComments)
  425.     GetFields
  426.     OldContents = Employee
  427.     UpdateCaption
  428.     FieldBoxes(0).SetFocus
  429. End Sub
  430. Private Sub UpdateCaption()
  431.     Dim Caption As String
  432.     Caption = FileName + ": Record " + Str$(Position)
  433.     Caption = Caption + " of " + Str$(LastRecord)
  434.     Form1.Caption = Caption
  435. End Sub
  436.