home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / eofbof / eofbof.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-05-02  |  10.3 KB  |  308 lines

  1. VERSION 2.00
  2. Begin Form frmEOF_BOF 
  3.    BackColor       =   &H00C0C0FF&
  4.    Caption         =   "EOF / BOF"
  5.    ClientHeight    =   4440
  6.    ClientLeft      =   1200
  7.    ClientTop       =   1500
  8.    ClientWidth     =   6345
  9.    Height          =   4845
  10.    Icon            =   EOFBOF.FRX:0000
  11.    KeyPreview      =   -1  'True
  12.    Left            =   1140
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   4440
  15.    ScaleWidth      =   6345
  16.    Top             =   1155
  17.    Width           =   6465
  18.    Begin CommandButton cmdPrint 
  19.       Caption         =   "P&rint List"
  20.       Height          =   396
  21.       Left            =   4800
  22.       TabIndex        =   4
  23.       Top             =   960
  24.       Width           =   1260
  25.    End
  26.    Begin ListBox lstActions 
  27.       FontBold        =   -1  'True
  28.       FontItalic      =   0   'False
  29.       FontName        =   "MS Sans Serif"
  30.       FontSize        =   8.25
  31.       FontStrikethru  =   0   'False
  32.       FontUnderline   =   0   'False
  33.       Height          =   2175
  34.       Left            =   240
  35.       TabIndex        =   11
  36.       Top             =   2040
  37.       Width           =   5865
  38.    End
  39.    Begin CommandButton cmdMove 
  40.       Caption         =   "Move&Last"
  41.       Height          =   396
  42.       Index           =   3
  43.       Left            =   4800
  44.       TabIndex        =   8
  45.       Top             =   1440
  46.       Width           =   1260
  47.    End
  48.    Begin CommandButton cmdMove 
  49.       Caption         =   "Move&Next"
  50.       Height          =   396
  51.       Index           =   2
  52.       Left            =   3240
  53.       TabIndex        =   7
  54.       Top             =   1440
  55.       Width           =   1260
  56.    End
  57.    Begin CommandButton cmdMove 
  58.       Caption         =   "Move&Prev"
  59.       Height          =   396
  60.       Index           =   1
  61.       Left            =   1725
  62.       TabIndex        =   6
  63.       Top             =   1440
  64.       Width           =   1260
  65.    End
  66.    Begin CommandButton cmdMove 
  67.       Caption         =   "Move&First"
  68.       Height          =   396
  69.       Index           =   0
  70.       Left            =   240
  71.       TabIndex        =   5
  72.       Top             =   1440
  73.       Width           =   1260
  74.    End
  75.    Begin CommandButton cmdRefresh 
  76.       Caption         =   "&Refresh"
  77.       Height          =   396
  78.       Left            =   3270
  79.       TabIndex        =   3
  80.       Top             =   960
  81.       Width           =   1260
  82.    End
  83.    Begin CommandButton cmdDelete 
  84.       Caption         =   "&Del Rec"
  85.       Height          =   396
  86.       Left            =   1725
  87.       TabIndex        =   2
  88.       Top             =   960
  89.       Width           =   1260
  90.    End
  91.    Begin CommandButton cmdAdd 
  92.       Caption         =   "&Add Rec"
  93.       Height          =   396
  94.       Left            =   240
  95.       TabIndex        =   1
  96.       Top             =   960
  97.       Width           =   1260
  98.    End
  99.    Begin TextBox Text1 
  100.       DataField       =   "KeyFld"
  101.       DataSource      =   "Data1"
  102.       Height          =   300
  103.       Left            =   195
  104.       TabIndex        =   0
  105.       Top             =   600
  106.       Width           =   1260
  107.    End
  108.    Begin Data Data1 
  109.       Caption         =   "Data1"
  110.       Connect         =   ""
  111.       DatabaseName    =   "C:\CODE\IRA\VB\TESTBED\EOF_BOF.MDB"
  112.       Exclusive       =   0   'False
  113.       Height          =   300
  114.       Left            =   192
  115.       Options         =   0
  116.       ReadOnly        =   0   'False
  117.       RecordSource    =   "eof_bof"
  118.       Top             =   192
  119.       Width           =   5868
  120.    End
  121.    Begin Label Label1 
  122.       AutoSize        =   -1  'True
  123.       Caption         =   "EOF State"
  124.       Height          =   195
  125.       Index           =   1
  126.       Left            =   3240
  127.       TabIndex        =   10
  128.       Top             =   600
  129.       Width           =   855
  130.    End
  131.    Begin Label Label1 
  132.       AutoSize        =   -1  'True
  133.       Caption         =   "BOF State"
  134.       Height          =   195
  135.       Index           =   0
  136.       Left            =   1800
  137.       TabIndex        =   9
  138.       Top             =   600
  139.       Width           =   855
  140.    End
  141. Option Explicit
  142. Sub cmdAdd_Click ()
  143.     '---------------------------------------------
  144.     ' Notice that the MoveLast is artificial, not
  145.     ' a true part of the "Add" process.  Neither is
  146.     ' the Find performed after added -- these are
  147.     ' simply "bells and whistles" I included.
  148.     '---------------------------------------------
  149.     lstActions.AddItem "Add Record:"
  150.     Dim i%
  151.     If ((data1.Recordset.EOF = False) Or (data1.Recordset.BOF = False)) Then
  152.         data1.Recordset.MoveLast
  153.         i% = data1.Recordset.Fields(0)
  154.         i% = i% + 1
  155.     End If
  156.     data1.Recordset.AddNew
  157.     text1 = i%
  158.     data1.Recordset.Update
  159.     ' Why do this?  To restore position to the latest added record...(!)
  160.     data1.Recordset.FindFirst "[KeyFld] = " & i%
  161. End Sub
  162. Sub cmdDelete_Click ()
  163.     '---------------------------------------------
  164.     ' Delete Record (if it exists)
  165.     '---------------------------------------------
  166.     lstActions.AddItem "Del Record:"
  167.     If data1.Recordset.BOF = False And data1.Recordset.EOF = False Then
  168.         data1.Recordset.Delete
  169.         cmdMove(2).Value = True  ' i.e. MoveNext
  170.     End If
  171. End Sub
  172. Sub cmdMove_Click (Index As Integer)
  173.     '---------------------------------------------
  174.     ' MoveFirst/Next/Previous/Last code.
  175.     ' Code to prevent "No Current Record" when
  176.     ' Move Methods are invoked.
  177.     '---------------------------------------------
  178.     ' Okay, is this an empty table...?
  179.     If data1.Recordset.EOF = False And data1.Recordset.BOF = False Then
  180.         ' No...  So let's do a move!
  181.         Select Case Index
  182.             Case 0      ' MoveFirst
  183.                 lstActions.AddItem "MoveFirst:"
  184.                 data1.Recordset.MoveFirst
  185.             Case 1      ' MovePrevious
  186.                 lstActions.AddItem "MovePrevious:"
  187.                 data1.Recordset.MovePrevious
  188.                 ' Ah, but is there a record there?
  189.                 If data1.Recordset.BOF = True Then
  190.                     data1.Refresh
  191.                     If data1.Recordset.EOF = False Then
  192.                         data1.Recordset.MoveFirst
  193.                     End If
  194.                 End If
  195.             Case 2      ' MoveNext
  196.                 lstActions.AddItem "MoveNext:"
  197.                 data1.Recordset.MoveNext
  198.                 ' Ah, but is there a record there?
  199.                 If data1.Recordset.EOF = True Then
  200.                     data1.Refresh
  201.                     If data1.Recordset.BOF = False Then
  202.                         data1.Recordset.MoveLast
  203.                     End If
  204.                 End If
  205.             Case 3      ' MovePrevious
  206.                 lstActions.AddItem "MoveLast:"
  207.                 data1.Recordset.MoveLast
  208.         End Select
  209.     End If
  210.     ' Wanna see something irritating?  Put the code below in the
  211.     ' reposition event(!)
  212.     If ((data1.Recordset.EOF = True) And (data1.Recordset.BOF = True)) Then
  213.         MsgBox "You will probably want to add a record or exit.", 0, "Empty Table!"
  214.     End If
  215. End Sub
  216. Sub cmdPrint_Click ()
  217.     '------------
  218.     ' Print List
  219.     '------------
  220.     Screen.MousePointer = 11
  221.     Dim i%
  222.     For i% = 0 To lstActions.ListCount - 1
  223.         printer.Print lstActions.List(i%)
  224.     Next i%
  225.     Screen.MousePointer = 0
  226. End Sub
  227. Sub cmdRefresh_Click ()
  228.     '---------------------------------------------
  229.     ' Refresh - Refreshes database
  230.     '---------------------------------------------
  231.     lstActions.AddItem "Refresh:"
  232.     data1.Refresh
  233. End Sub
  234. Sub Data1_Reposition ()
  235.     '---------------------------------------------
  236.     ' Reposition - Just updates the EOF/BOF flags
  237.     '              and adds to the list.
  238.     ' Reposition events triggered by the data
  239.     ' control are rarely a problem (unless the
  240.     ' table is empty).  The Data Control automatically
  241.     ' prevents moving off the end of a table.  It's the
  242.     ' actual MoveNext/MovePrevious methods which are
  243.     ' dangerous/require extra action (see cmdMove_Click)
  244.     '---------------------------------------------
  245.     Static i%
  246.     If data1.Recordset.BOF = True Then
  247.         label1(0) = "BOF(" & i% & ") =  TRUE"
  248.     Else
  249.         label1(0) = "BOF(" & i% & ") = FALSE"
  250.     End If
  251.     If data1.Recordset.EOF = True Then
  252.         label1(1) = "EOF(" & i% & ") =  TRUE"
  253.     Else
  254.         label1(1) = "EOF(" & i% & ") = FALSE"
  255.     End If
  256.     ' Add current state to the list, and keep list on the last item
  257.     lstActions.AddItem "        " & label1(0) & ";  " & label1(1)
  258.     i% = i% + 1
  259.     lstActions.ListIndex = lstActions.ListCount - 1
  260. End Sub
  261. Sub Data1_Validate (Action As Integer, Save As Integer)
  262.     '---------------------------------------------
  263.     '  This just makes sure the list knows what the
  264.     '  latest action to take place is.
  265.     '---------------------------------------------
  266.     Select Case Action
  267.         Case 0
  268.             lstActions.AddItem "    ACTIONCANCEL"
  269.         Case 1
  270.             lstActions.AddItem "    ACTIONMOVEFIRST"
  271.         Case 2
  272.             lstActions.AddItem "    ACTIONMOVEPREVIOUS"
  273.         Case 3
  274.             lstActions.AddItem "    ACTIONMOVENEXT"
  275.         Case 4
  276.             lstActions.AddItem "    ACTIONMOVELAST"
  277.         Case 5
  278.             lstActions.AddItem "    ACTIONADDNEW"
  279.         Case 6
  280.             lstActions.AddItem "    ACTIONUPDATE"
  281.         Case 7
  282.             lstActions.AddItem "    ACTIONDELETE"
  283.         Case 8
  284.             lstActions.AddItem "    ACTIONFIND"
  285.         Case 9
  286.             lstActions.AddItem "    ACTIONBOOKMARK"
  287.         Case 10
  288.             lstActions.AddItem "    ACTIONCLOSE"
  289.         Case 11
  290.             lstActions.AddItem "    ACTIONUNLOAD"
  291.     End Select
  292. End Sub
  293. Sub Form_Load ()
  294.     '---------------------------------------------
  295.     ' Load - Set Data control to read EOFBOF.MDB
  296.     '        and delete all records in it.
  297.     '---------------------------------------------
  298.     Dim TmpStr$
  299.     TmpStr$ = App.Path & "\EOFBOF.MDB"
  300.     data1.DatabaseName = TmpStr$
  301.     lstActions.AddItem "Form Load:"
  302.     Dim Db As Database
  303.     Set Db = OpenDatabase(TmpStr$)
  304.     Db.Execute ("DELETE * FROM eof_bof")
  305.     Db.Close
  306.     Set Db = Nothing
  307. End Sub
  308.