home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk1 / recedit.fr_ / recedit.bin
Text File  |  1993-04-28  |  11KB  |  412 lines

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