home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l406 / 1.ddi / RECEDIT.FR_ / RECEDIT.bin (.txt)
Encoding:
Visual Basic Form  |  1992-10-21  |  10.9 KB  |  383 lines

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