home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / btrtest / btrtest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  14.8 KB  |  491 lines

  1. VERSION 2.00
  2. Begin Form EmpMst 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Btrieve Test Program"
  5.    ClientHeight    =   3420
  6.    ClientLeft      =   1140
  7.    ClientTop       =   1470
  8.    ClientWidth     =   7635
  9.    Height          =   3825
  10.    Icon            =   BTRTEST.FRX:0000
  11.    Left            =   1080
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   3420
  16.    ScaleWidth      =   7635
  17.    Top             =   1125
  18.    Width           =   7755
  19.    Begin TextBox HPhone 
  20.       Height          =   285
  21.       Left            =   3600
  22.       TabIndex        =   26
  23.       Top             =   3015
  24.       Width           =   1860
  25.    End
  26.    Begin TextBox WPhone 
  27.       Height          =   285
  28.       Left            =   3600
  29.       TabIndex        =   25
  30.       Top             =   2655
  31.       Width           =   1860
  32.    End
  33.    Begin TextBox ZipCod 
  34.       Height          =   285
  35.       Left            =   3600
  36.       TabIndex        =   4
  37.       Top             =   2295
  38.       Width           =   1095
  39.    End
  40.    Begin TextBox SocSec 
  41.       Height          =   285
  42.       Left            =   3600
  43.       TabIndex        =   3
  44.       Top             =   1935
  45.       Width           =   2175
  46.    End
  47.    Begin TextBox FstNam 
  48.       Height          =   285
  49.       Left            =   3600
  50.       TabIndex        =   2
  51.       Top             =   1575
  52.       Width           =   2190
  53.    End
  54.    Begin TextBox LstNam 
  55.       Height          =   285
  56.       Left            =   3600
  57.       TabIndex        =   1
  58.       Top             =   1215
  59.       Width           =   2190
  60.    End
  61.    Begin ListBox EmpList 
  62.       Height          =   2370
  63.       Left            =   90
  64.       TabIndex        =   10
  65.       Top             =   900
  66.       Width           =   2265
  67.    End
  68.    Begin TextBox EmpNum 
  69.       Height          =   285
  70.       Left            =   3600
  71.       TabIndex        =   0
  72.       Top             =   855
  73.       Width           =   735
  74.    End
  75.    Begin Frame Frame3 
  76.       BackColor       =   &H00C0C0C0&
  77.       Caption         =   "Data Access"
  78.       Height          =   3210
  79.       Left            =   5895
  80.       TabIndex        =   16
  81.       Top             =   90
  82.       Width           =   1680
  83.       Begin Frame Frame4 
  84.          BackColor       =   &H00C0C0C0&
  85.          Caption         =   "Select By"
  86.          Height          =   1230
  87.          Left            =   90
  88.          TabIndex        =   21
  89.          Top             =   1845
  90.          Width           =   1500
  91.          Begin OptionButton SelectByFirst 
  92.             BackColor       =   &H00C0C0C0&
  93.             Caption         =   "First Name"
  94.             Height          =   240
  95.             Left            =   90
  96.             TabIndex        =   23
  97.             Top             =   900
  98.             Width           =   1365
  99.          End
  100.          Begin OptionButton SelectByLast 
  101.             BackColor       =   &H00C0C0C0&
  102.             Caption         =   "Last Name"
  103.             Height          =   240
  104.             Left            =   90
  105.             TabIndex        =   22
  106.             Top             =   585
  107.             Width           =   1365
  108.          End
  109.          Begin OptionButton SelectByNum 
  110.             BackColor       =   &H00C0C0C0&
  111.             Caption         =   "Employee #"
  112.             Height          =   240
  113.             Left            =   90
  114.             TabIndex        =   24
  115.             Top             =   270
  116.             Width           =   1320
  117.          End
  118.       End
  119.       Begin CommandButton LastCommand 
  120.          Caption         =   "Last"
  121.          Height          =   330
  122.          Left            =   315
  123.          TabIndex        =   18
  124.          Top             =   1485
  125.          Width           =   1050
  126.       End
  127.       Begin CommandButton PreviousCommand 
  128.          Caption         =   "Previous"
  129.          Height          =   330
  130.          Left            =   315
  131.          TabIndex        =   17
  132.          Top             =   1080
  133.          Width           =   1050
  134.       End
  135.       Begin CommandButton NextCommand 
  136.          Caption         =   "Next"
  137.          Height          =   330
  138.          Left            =   315
  139.          TabIndex        =   19
  140.          Top             =   675
  141.          Width           =   1050
  142.       End
  143.       Begin CommandButton FirstCommand 
  144.          Caption         =   "First"
  145.          Height          =   330
  146.          Left            =   315
  147.          TabIndex        =   20
  148.          Top             =   270
  149.          Width           =   1050
  150.       End
  151.    End
  152.    Begin Frame Frame2 
  153.       BackColor       =   &H00C0C0C0&
  154.       Caption         =   " Action"
  155.       Height          =   690
  156.       Left            =   90
  157.       TabIndex        =   11
  158.       Top             =   90
  159.       Width           =   5685
  160.       Begin CommandButton ExitCommand 
  161.          Caption         =   "Exit"
  162.          Height          =   330
  163.          Left            =   4500
  164.          TabIndex        =   15
  165.          Top             =   270
  166.          Width           =   1050
  167.       End
  168.       Begin CommandButton DeleteCommand 
  169.          Caption         =   "Delete"
  170.          Height          =   330
  171.          Left            =   3060
  172.          TabIndex        =   14
  173.          Top             =   270
  174.          Width           =   1050
  175.       End
  176.       Begin CommandButton ChangeCommand 
  177.          Caption         =   "Change"
  178.          Height          =   330
  179.          Left            =   1620
  180.          TabIndex        =   13
  181.          Top             =   270
  182.          Width           =   1050
  183.       End
  184.       Begin CommandButton AddCommand 
  185.          Caption         =   "Add"
  186.          Height          =   330
  187.          Left            =   135
  188.          TabIndex        =   12
  189.          Top             =   270
  190.          Width           =   1050
  191.       End
  192.    End
  193.    Begin Label Label5 
  194.       BackColor       =   &H00C0C0C0&
  195.       Caption         =   "Home Phone"
  196.       Height          =   195
  197.       Left            =   2430
  198.       TabIndex        =   28
  199.       Top             =   3060
  200.       Width           =   1140
  201.    End
  202.    Begin Label Label12 
  203.       BackColor       =   &H00C0C0C0&
  204.       Caption         =   "Work Phone"
  205.       Height          =   195
  206.       Left            =   2430
  207.       TabIndex        =   27
  208.       Top             =   2700
  209.       Width           =   1095
  210.    End
  211.    Begin Label Label4 
  212.       BackColor       =   &H00C0C0C0&
  213.       Caption         =   "Zip Code"
  214.       Height          =   210
  215.       Left            =   2430
  216.       TabIndex        =   9
  217.       Top             =   2340
  218.       Width           =   975
  219.    End
  220.    Begin Label Label1 
  221.       BackColor       =   &H00C0C0C0&
  222.       Caption         =   "SSN"
  223.       Height          =   210
  224.       Left            =   2430
  225.       TabIndex        =   8
  226.       Top             =   1980
  227.       Width           =   960
  228.    End
  229.    Begin Label Label2 
  230.       BackColor       =   &H00C0C0C0&
  231.       Caption         =   "First Name"
  232.       Height          =   210
  233.       Left            =   2430
  234.       TabIndex        =   5
  235.       Top             =   1620
  236.       Width           =   1005
  237.    End
  238.    Begin Label Label6 
  239.       BackColor       =   &H00C0C0C0&
  240.       Caption         =   "Last Name"
  241.       Height          =   210
  242.       Left            =   2430
  243.       TabIndex        =   7
  244.       Top             =   1260
  245.       Width           =   1020
  246.    End
  247.    Begin Label Label7 
  248.       BackColor       =   &H00C0C0C0&
  249.       Caption         =   "Employee #"
  250.       Height          =   210
  251.       Left            =   2430
  252.       TabIndex        =   6
  253.       Top             =   900
  254.       Width           =   1095
  255.    End
  256. Sub AddCommand_Click ()
  257.     KeyBufLen% = Len(KeyBuff)
  258.     SetBuff
  259.     BufLen% = Len(DataBuff)
  260.     Status% = BTRCALL(BINSERT, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  261.     If Status% <> 0 Then
  262.         BtrErr (Status%)
  263.       Else
  264.         PaintData
  265.         Response% = MsgBox("Add Action Successful", 64, "File Action Message")
  266.     End If
  267.     SetEmpList
  268. End Sub
  269. Sub ChangeCommand_Click ()
  270.     KeyBufLen% = Len(KeyBuff)
  271.     BufLen% = Len(DataBuff)
  272.     SetBuff
  273.     Status% = BTRCALL(BUpdate, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  274.     If Status% <> 0 Then
  275.         BtrErr (Status%)
  276.       Else
  277.         Response% = MsgBox("Change SuccessFul", 64, "File Action Message")
  278.     End If
  279.     SetEmpList
  280. End Sub
  281. Sub ClearData ()
  282.     'Clear Screen Data
  283.     LstNam.Text = ""
  284.     SocSec.Text = ""
  285.     FstNam.Text = ""
  286.     WPhone.Text = ""
  287.     EmpNum.Text = ""
  288.     ZipCod.Text = ""
  289.     HPhone.Text = ""
  290. End Sub
  291. Sub CommandsOff ()
  292.         
  293.         AddCommand.Enabled = False
  294.         ChangeCommand.Enabled = False
  295.         DeleteCommand.Enabled = False
  296.         FirstCommand.Enabled = False
  297.         LastCommand.Enabled = False
  298.         NextCommand.Enabled = False
  299.         PreviousCommand.Enabled = False
  300. End Sub
  301. Sub DeleteCommand_Click ()
  302.     BufLen% = Len(DataBuff)
  303.     KeyBufLen% = Len(KeyBuff)
  304.     Status% = BTRCALL(BDELETE, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  305.     Response% = MsgBox("Are you Sure?", 32, "File Action Message")
  306.     If Response% = 1 Then
  307.         If Status% <> 0 Then
  308.             BtrErr (Status%)
  309.           Else
  310.             PaintData
  311.             Response% = MsgBox("Delete SuccessFul", 64, "File Action Message")
  312.             ClearData
  313.         End If
  314.     End If
  315.     SetEmpList
  316. End Sub
  317. Sub EmpList_Click ()
  318.     'Set Select Box
  319.     SelectByLast.Value = True
  320.     SetSelectBy
  321.     'Get First by EmpNum
  322.     BufLen% = Len(DataBuff)
  323.     KeyBufLen% = Len(KeyBuff)
  324.     Status% = BTRCALL(BGET_FIRST, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  325.     Index% = 1
  326.     While Index% <= EmpList.ListIndex And Status% <> 9
  327.         Status% = BTRCALL(BGET_NEXT, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  328.         If Status% <> 0 Then
  329.             BtrErr (Status%)
  330.           Else
  331.             'MsgBox DataBuff.LstNam + DataBuff.EmpNum, 0
  332.             Index% = Index% + 1
  333.         End If
  334.     Wend
  335.     PaintData
  336.     PreviousCommand.Enabled = True
  337.     NextCommand.Enabled = True
  338.     DeleteCommand.Enabled = True
  339.     ChangeCommand.Enabled = True
  340. End Sub
  341. Sub ExitCommand_Click ()
  342.     Status% = WBTRVSTOP
  343.     If Status% <> 0 Then
  344.         BtrErr (Status%)
  345.       Else
  346.         End   'Quit App
  347.     End If
  348. End Sub
  349. Sub FirstCommand_Click ()
  350.     BufLen% = Len(DataBuff)
  351.     KeyBufLen% = Len(KeyBuff)
  352.     Status% = BTRCALL(BGET_FIRST, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  353.     If Status% <> 0 Then
  354.         BtrErr (Status%)
  355.         ClearData
  356.         CommandsOff
  357.       Else
  358.         AddCommand.Enabled = True
  359.         ChangeCommand.Enabled = True
  360.         DeleteCommand.Enabled = True
  361.         FirstCommand.Enabled = True
  362.         LastCommand.Enabled = True
  363.         NextCommand.Enabled = True
  364.         PreviousCommand.Enabled = True
  365.         PaintData
  366.         NextCommand.SetFocus
  367.     End If
  368. End Sub
  369. Sub Form_Load ()
  370.     StartUp             'Execute StartUp Routine
  371.     ExitCommand.Enabled = True
  372.     SelectByLast.Value = True
  373.     SelectByFirst.Value = False
  374.     SelectByNum.Value = False
  375.     SetSelectBy
  376.      
  377.     'Open EmpMst.Dat File
  378.     KeyBuff.FILENAME = "C:\VB\BtrTest\EmpMsts.Dat"
  379.     BufLen% = Len(DataBuff)
  380.     KeyBufLen% = Len(KeyBuff)
  381.     Status% = BTRCALL(BOPEN, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  382.     If Status% <> 0 Then
  383.         BtrErr (Status%)
  384.         CommandsOff
  385.     Else
  386.         CommandsOff
  387.         AddCommand.Enabled = True
  388.         FirstCommand.Enabled = True
  389.         LastCommand.Enabled = True
  390.     End If
  391.     SetEmpList
  392.     ClearData
  393. End Sub
  394. Sub LastCommand_Click ()
  395.     BufLen% = Len(DataBuff)
  396.     KeyBufLen% = Len(KeyBuff)
  397.     Status% = BTRCALL(BGET_LAST, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  398.     If Status% <> 0 Then
  399.         BtrErr (Status%)
  400.         ClearData
  401.         CommandsOff
  402.     Else
  403.         AddCommand.Enabled = True
  404.         ChangeCommand.Enabled = True
  405.         DeleteCommand.Enabled = True
  406.         FirstCommand.Enabled = True
  407.         LastCommand.Enabled = True
  408.         NextCommand.Enabled = True
  409.         PreviousCommand.Enabled = True
  410.         PaintData
  411.         PreviousCommand.SetFocus
  412.     End If
  413. End Sub
  414. Sub NextCommand_Click ()
  415.     BufLen% = Len(DataBuff)
  416.     KeyBufLen% = Len(KeyBuff)
  417.     Status% = BTRCALL(BGET_NEXT, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  418.     If Status% <> 0 Then
  419.         BtrErr (Status%)
  420.       Else
  421.         PaintData
  422.     End If
  423.     NextCommand.SetFocus
  424. End Sub
  425. Sub PaintData ()
  426.     'Paint Screen Data after file I/O
  427.     LstNam.Text = DataBuff.LstNam
  428.     ZipCod.Text = DataBuff.ZipCod
  429.     SocSec.Text = DataBuff.SocSec
  430.     FstNam.Text = DataBuff.FstNam
  431.     WPhone.Text = DataBuff.WPhone
  432.     EmpNum.Text = DataBuff.EmpNum
  433.     HPhone.Text = DataBuff.HPhone
  434. End Sub
  435. Sub PreviousCommand_Click ()
  436.     BufLen% = Len(DataBuff)
  437.     KeyBufLen% = Len(KeyBuff)
  438.     Status% = BTRCALL(BGET_PREV, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  439.     If Status% <> 0 Then
  440.         BtrErr (Status%)
  441.       Else
  442.         PaintData
  443.     End If
  444.     PreviousCommand.SetFocus
  445. End Sub
  446. Sub SelectByFirst_Click ()
  447.     SetSelectBy
  448. End Sub
  449. Sub SelectByLast_Click ()
  450.     SetSelectBy
  451. End Sub
  452. Sub SelectByNum_Click ()
  453.     SetSelectBy
  454. End Sub
  455. Sub SetBuff ()
  456.     'Set data buffer to the field values
  457.     DataBuff.SocSec = SocSec.Text
  458.     DataBuff.FstNam = FstNam.Text
  459.     DataBuff.WPhone = WPhone.Text
  460.     DataBuff.ZipCod = ZipCod.Text
  461.     DataBuff.EmpNum = EmpNum.Text
  462.     DataBuff.HPhone = HPhone.Text
  463.     DataBuff.LstNam = LstNam.Text
  464. End Sub
  465. Sub SetEmpList ()
  466.     'Load EmpList Listbox with Employee Data
  467.     BufLen% = Len(DataBuff)
  468.     KeyBufLen% = Len(KeyBuff)
  469.     Status% = BTRCALL(BGET_FIRST, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  470.     If Status% <> 0 Then
  471.         BtrErr (Status%)
  472.       Else
  473.         EmpList.List(0) = RTrim$(DataBuff.LstNam) + ", " + RTrim$(DataBuff.FstNam) '+ "  #" + DataBuff.EmpNum
  474.     End If
  475.     Index% = 0
  476.     While Status% = 0
  477.         Status% = BTRCALL(BGET_NEXT, POSBLOCK, DataBuff, BufLen%, KeyBuff, KeyBufLen%, KeyNum%)
  478.         If Status% = 0 Then
  479.             Index% = Index% + 1
  480.             EmpList.List(Index%) = RTrim$(DataBuff.LstNam) + ", " + RTrim$(DataBuff.FstNam) '+ " #" + DataBuff.EmpNum
  481.         End If
  482.     Wend
  483. End Sub
  484. Sub SetSelectBy ()
  485.     If SelectByNum.Value = True Then KeyNum% = 0
  486.     If SelectByLast.Value = True Then KeyNum% = 1
  487.     If SelectByFirst.Value = True Then KeyNum% = 2
  488.     NextCommand.Enabled = False
  489.     PreviousCommand.Enabled = False
  490. End Sub
  491.