home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l405 / 1.ddi / RECEDIT.FR_ / RECEDIT.bin (.txt)
Encoding:
Visual Basic Form  |  1993-04-28  |  11.2 KB  |  393 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. Option Explicit
  183. Dim Employee As Person
  184. Dim OldContents As Person
  185. Dim Position As Long         ' Position describes presentation order.
  186. Dim LastRecord As Long
  187. Dim FileName As String
  188. Dim FileNum As Integer
  189. Sub AddRecord_Click ()
  190.     Dim Ind As Integer
  191.     SaveRecordChanges
  192.     For Ind = 0 To 6
  193.     Form1.FieldBoxes(Ind).Text = ""
  194.     Next Ind
  195.     GetFields
  196.     LastRecord = LastRecord + 1
  197.     Put #FileNum, LastRecord, Employee
  198.     Position = LastRecord
  199.     ShowRecord
  200. End Sub
  201. Sub CleanUpFile ()
  202.     Dim CleanFileNum As Integer
  203.     Dim Ind As Long
  204.     Dim Confirm As Integer
  205.     Confirm = False
  206.     CleanFileNum = FileOpener("~~Tmp~~.Tmp", RANDOMFILE, Len(Employee), Confirm)
  207.     For Ind = 1 To LastRecord
  208.     Get #FileNum, Ind, Employee
  209.     Put #CleanFileNum, Ind, Employee
  210.     Next Ind
  211.     Close ' Close all files.
  212.     FileCopy "~~Tmp~~.Tmp", FileName
  213.     FileNum = FileOpener(FileName, RANDOMFILE, Len(Employee), Confirm)
  214.     Kill "~~Tmp~~.Tmp"
  215. End Sub
  216. Sub DeleteRecord_Click ()
  217.     Dim TempVar As Person
  218.     Dim Ind As Integer
  219.     Dim Msg As String
  220.     If LastRecord = 1 Then
  221.     Msg = "This is the last record in the file. Deleting it will destroy"
  222.     Msg = Msg + " the whole file."
  223.     Msg = Msg + " Record Editor will also be closed."
  224.     Msg = Msg + " Choose OK to destroy file."
  225.     If MsgBox(Msg, 65, "About to delete file!") = 1 Then
  226.         Close (FileNum)
  227.         Kill FileName
  228.     End If
  229.     End If
  230.     For Ind = Position To LastRecord - 1
  231.     Get #FileNum, Ind + 1, TempVar
  232.     Put #FileNum, Ind, TempVar
  233.     Next Ind
  234.     LastRecord = LastRecord - 1
  235.     If Position > LastRecord Then
  236.     Position = LastRecord
  237.     End If
  238.     CleanUpFile
  239.     ShowRecord                          ' Note that this displays record
  240. End Sub                                 ' following deleted record.
  241. Sub ExitButton_Click ()
  242.     CleanUpFile
  243.     End
  244. End Sub
  245. Sub FieldBoxes_GotFocus (Index As Integer)
  246.     FieldBoxes(Index).SelStart = 0
  247.     FieldBoxes(Index).SelLength = Len(FieldBoxes(Index).Text)
  248. End Sub
  249. Sub FieldBoxes_LostFocus (Index As Integer)
  250.   If Val(FieldBoxes(2).Text) > 32767 Then
  251.     MsgBox "Enter a number less than 32,768"
  252.     FieldBoxes(2).SetFocus
  253.   End If
  254. End Sub
  255. Sub Form_Load ()
  256.     Dim BoxCaption As String
  257.     Dim NL As String
  258.     Dim Msg As String
  259.     ChDrive App.Path
  260.     ChDir App.Path
  261.     Form1.Show
  262.     OpenFile_Click
  263. End Sub
  264. Sub Form_Unload (Cancel As Integer)
  265.     End
  266. End Sub
  267. Sub GetFields ()
  268.     Employee.FirstName = Form1.FieldBoxes(0).Text
  269.     Employee.LastName = Form1.FieldBoxes(1).Text
  270.     If IsNumeric(Form1.FieldBoxes(2).Text) Then
  271.     Employee.ID = CInt(Form1.FieldBoxes(2).Text)
  272.     Else
  273.     Employee.ID = 0
  274.     End If
  275.     Employee.Title = Form1.FieldBoxes(3).Text
  276.     If IsNumeric(Form1.FieldBoxes(4).Text) Then
  277.     Employee.MonthlySalary = CDbl(CCur(Form1.FieldBoxes(4).Text))
  278.     Else
  279.     Employee.MonthlySalary = CDbl(CCur(0))
  280.     End If
  281.     If IsDate(Form1.FieldBoxes(5).Text) Then
  282.     Employee.LastReviewDate = CLng(DateValue(Form1.FieldBoxes(5).Text))
  283.     Else
  284.     Employee.LastReviewDate = CLng(DateValue("1/1/1753"))
  285.     End If
  286.     Employee.ReviewComments = Form1.FieldBoxes(6).Text
  287. End Sub
  288. Sub Initialize ()
  289.     LastRecord = LOF(FileNum) \ Len(Employee)
  290.     Position = 1
  291.     If LastRecord < 1 Then
  292.     GetFields
  293.     OldContents = Employee
  294.     AddRecord_Click
  295.     Else
  296.     ShowRecord
  297.     End If
  298. End Sub
  299. Sub NextRecord_Click ()
  300.     Dim Msg As String
  301.     SaveRecordChanges
  302.     If Position = LastRecord Then
  303.     Msg = "There are no records greater than " + Str$(LastRecord) + "."
  304.     MsgBox (Msg)
  305.     Else
  306.     Position = Position + 1
  307.     End If
  308.     ShowRecord
  309. End Sub
  310. Sub OpenFile_Click ()
  311.     Dim Confirm As Integer
  312.     Confirm = True
  313.     If LastRecord > 0 Then
  314.     SaveRecordChanges
  315.     CleanUpFile
  316.     End If
  317.     FileNum = 0
  318.     Do While FileNum = 0
  319.     FileName = GetFileName("Enter the name of a file to create or open.")
  320.     If FileName = "" Then
  321.         If LastRecord > 0 Then
  322.         Exit Sub
  323.         Else
  324.         End
  325.         End If
  326.     Else
  327.         FileNum = FileOpener(FileName, RANDOMFILE, Len(Employee), Confirm)
  328.     End If
  329.     Loop
  330.     Initialize
  331. End Sub
  332. Sub PreviousRecord_Click ()
  333.     SaveRecordChanges
  334.     If Position = 1 Then
  335.     MsgBox ("There are no records less than 1.")
  336.     Else
  337.     Position = Position - 1
  338.     End If
  339.     ShowRecord
  340. End Sub
  341. Sub SaveRecordChanges ()
  342.     Dim ConvertVariant As Variant
  343.     Dim Equal As Integer
  344.     Equal = True
  345.     GetFields
  346.     If Employee.FirstName <> OldContents.FirstName Then Equal = False
  347.     If Employee.LastName <> OldContents.LastName Then Equal = False
  348.     If Employee.ID <> OldContents.ID Then Equal = False
  349.     If Employee.Title <> OldContents.Title Then Equal = False
  350.     If Employee.MonthlySalary <> OldContents.MonthlySalary Then Equal = False
  351.     If Employee.LastReviewDate <> OldContents.LastReviewDate Then Equal = False
  352.     If Employee.ReviewComments <> OldContents.ReviewComments Then Equal = False
  353.     If Not Equal Then
  354.     Put #FileNum, Position, Employee
  355.     End If
  356. End Sub
  357. Sub ShowRecord ()
  358.     Get #FileNum, Position, Employee
  359.     Dim ConvertVariant As Variant
  360.     Form1.FieldBoxes(0).Text = Trim(Employee.FirstName)
  361.     Form1.FieldBoxes(1).Text = Trim(Employee.LastName)
  362.     If Employee.ID > 0 Then
  363.     Form1.FieldBoxes(2).Text = LTrim(Str(Employee.ID))
  364.     Else
  365.     Form1.FieldBoxes(2).Text = ""
  366.     End If
  367.     Form1.FieldBoxes(3) = Trim(Employee.Title)
  368.     ConvertVariant = Employee.MonthlySalary
  369.     ConvertVariant = CCur(ConvertVariant)
  370.     If ConvertVariant > 0 Then
  371.     Form1.FieldBoxes(4) = Format(ConvertVariant, "$#,##0.00;(#,##0.00)")
  372.     Else
  373.     Form1.FieldBoxes(4) = ""
  374.     End If
  375.     ConvertVariant = CVDate(Employee.LastReviewDate)
  376.     If ConvertVariant <> DateValue("1/1/1753") Then
  377.     Form1.FieldBoxes(5).Text = ConvertVariant
  378.     Else
  379.     FieldBoxes(5) = ""
  380.     End If
  381.     Form1.FieldBoxes(6) = Trim(Employee.ReviewComments)
  382.     GetFields
  383.     OldContents = Employee
  384.     UpdateCaption
  385.     FieldBoxes(0).SetFocus
  386. End Sub
  387. Sub UpdateCaption ()
  388.     Dim Caption As String
  389.     Caption = FileName + ": Record " + Str$(Position)
  390.     Caption = Caption + " of " + Str$(LastRecord)
  391.     Form1.Caption = Caption
  392. End Sub
  393.