home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / demo / truegrid / trubrwse / trubrwse.$ / SCHEMA.FRM < prev    next >
Text File  |  1994-02-08  |  33KB  |  1,171 lines

  1. VERSION 2.00
  2. Begin Form SchemaForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "SchemaForm"
  5.    ClientHeight    =   3120
  6.    ClientLeft      =   1905
  7.    ClientTop       =   1830
  8.    ClientWidth     =   5700
  9.    Height          =   3525
  10.    Left            =   1845
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3120
  15.    ScaleWidth      =   5700
  16.    Top             =   1485
  17.    Visible         =   0   'False
  18.    Width           =   5820
  19.    Begin TextBox ZoomText 
  20.       BorderStyle     =   0  'None
  21.       Height          =   975
  22.       Left            =   2880
  23.       MultiLine       =   -1  'True
  24.       ScrollBars      =   2  'Vertical
  25.       TabIndex        =   31
  26.       Top             =   1680
  27.       Visible         =   0   'False
  28.       Width           =   975
  29.    End
  30.    Begin PictureBox AddPanel 
  31.       BorderStyle     =   0  'None
  32.       Height          =   3195
  33.       Left            =   1440
  34.       ScaleHeight     =   3195
  35.       ScaleWidth      =   1215
  36.       TabIndex        =   14
  37.       TabStop         =   0   'False
  38.       Top             =   1170
  39.       Visible         =   0   'False
  40.       Width           =   1215
  41.       Begin CommandButton DoneButton 
  42.          Caption         =   "&Done"
  43.          Height          =   375
  44.          Index           =   1
  45.          Left            =   120
  46.          TabIndex        =   18
  47.          Top             =   2400
  48.          Width           =   975
  49.       End
  50.       Begin CommandButton ZoomButton 
  51.          Caption         =   "&Zoom"
  52.          Height          =   375
  53.          Index           =   1
  54.          Left            =   120
  55.          TabIndex        =   17
  56.          Top             =   1680
  57.          Width           =   975
  58.       End
  59.       Begin CommandButton ClearButton 
  60.          Caption         =   "&Clear"
  61.          Height          =   375
  62.          Index           =   1
  63.          Left            =   120
  64.          TabIndex        =   16
  65.          Top             =   960
  66.          Width           =   975
  67.       End
  68.       Begin CommandButton AddButton 
  69.          Caption         =   "&Add"
  70.          Height          =   375
  71.          Left            =   120
  72.          TabIndex        =   15
  73.          Top             =   240
  74.          Width           =   975
  75.       End
  76.    End
  77.    Begin VScrollBar ScrollBar 
  78.       Height          =   2895
  79.       Left            =   5400
  80.       TabIndex        =   2
  81.       Top             =   0
  82.       Visible         =   0   'False
  83.       Width           =   255
  84.    End
  85.    Begin PictureBox UpdatePanel 
  86.       BorderStyle     =   0  'None
  87.       Height          =   3195
  88.       Left            =   4080
  89.       ScaleHeight     =   3195
  90.       ScaleWidth      =   1215
  91.       TabIndex        =   19
  92.       TabStop         =   0   'False
  93.       Top             =   0
  94.       Visible         =   0   'False
  95.       Width           =   1215
  96.       Begin PictureBox NavigationButton 
  97.          AutoSize        =   -1  'True
  98.          BorderStyle     =   0  'None
  99.          DrawMode        =   6  'Invert
  100.          DrawWidth       =   480
  101.          Height          =   480
  102.          Index           =   3
  103.          Left            =   660
  104.          Picture         =   SCHEMA.FRX:0000
  105.          ScaleHeight     =   480
  106.          ScaleWidth      =   480
  107.          TabIndex        =   30
  108.          Top             =   2430
  109.          Width           =   480
  110.       End
  111.       Begin PictureBox NavigationButton 
  112.          AutoSize        =   -1  'True
  113.          BorderStyle     =   0  'None
  114.          DrawMode        =   6  'Invert
  115.          DrawWidth       =   480
  116.          Height          =   480
  117.          Index           =   2
  118.          Left            =   60
  119.          Picture         =   SCHEMA.FRX:0442
  120.          ScaleHeight     =   480
  121.          ScaleWidth      =   480
  122.          TabIndex        =   28
  123.          Top             =   2430
  124.          Width           =   480
  125.       End
  126.       Begin PictureBox NavigationButton 
  127.          AutoSize        =   -1  'True
  128.          BorderStyle     =   0  'None
  129.          DrawMode        =   6  'Invert
  130.          DrawWidth       =   480
  131.          Height          =   480
  132.          Index           =   1
  133.          Left            =   660
  134.          Picture         =   SCHEMA.FRX:0884
  135.          ScaleHeight     =   480
  136.          ScaleWidth      =   480
  137.          TabIndex        =   26
  138.          Top             =   1710
  139.          Width           =   480
  140.       End
  141.       Begin PictureBox NavigationButton 
  142.          AutoSize        =   -1  'True
  143.          BorderStyle     =   0  'None
  144.          DrawMode        =   6  'Invert
  145.          DrawWidth       =   480
  146.          Height          =   480
  147.          Index           =   0
  148.          Left            =   60
  149.          Picture         =   SCHEMA.FRX:0CC6
  150.          ScaleHeight     =   480
  151.          ScaleWidth      =   480
  152.          TabIndex        =   24
  153.          Top             =   1710
  154.          Width           =   480
  155.       End
  156.       Begin CommandButton DoneButton 
  157.          Cancel          =   -1  'True
  158.          Caption         =   "&Done"
  159.          Height          =   315
  160.          Index           =   2
  161.          Left            =   120
  162.          TabIndex        =   22
  163.          Top             =   1260
  164.          Width           =   975
  165.       End
  166.       Begin CommandButton ZoomButton 
  167.          Caption         =   "&Zoom"
  168.          Height          =   315
  169.          Index           =   0
  170.          Left            =   120
  171.          TabIndex        =   21
  172.          Top             =   870
  173.          Width           =   975
  174.       End
  175.       Begin CommandButton ClearButton 
  176.          Caption         =   "&Clear"
  177.          Height          =   315
  178.          Index           =   2
  179.          Left            =   120
  180.          TabIndex        =   20
  181.          Top             =   480
  182.          Width           =   975
  183.       End
  184.       Begin CommandButton UpdateButton 
  185.          Caption         =   "&Update"
  186.          Height          =   315
  187.          Left            =   120
  188.          TabIndex        =   32
  189.          Top             =   90
  190.          Width           =   975
  191.       End
  192.       Begin Label NavigationLabel 
  193.          Alignment       =   2  'Center
  194.          Caption         =   "&Next"
  195.          FontBold        =   0   'False
  196.          FontItalic      =   0   'False
  197.          FontName        =   "MS Sans Serif"
  198.          FontSize        =   8.25
  199.          FontStrikethru  =   0   'False
  200.          FontUnderline   =   0   'False
  201.          Height          =   210
  202.          Index           =   3
  203.          Left            =   600
  204.          TabIndex        =   29
  205.          Top             =   2910
  206.          Width           =   615
  207.       End
  208.       Begin Label NavigationLabel 
  209.          Alignment       =   2  'Center
  210.          Caption         =   "&Prev"
  211.          FontBold        =   0   'False
  212.          FontItalic      =   0   'False
  213.          FontName        =   "MS Sans Serif"
  214.          FontSize        =   8.25
  215.          FontStrikethru  =   0   'False
  216.          FontUnderline   =   0   'False
  217.          Height          =   210
  218.          Index           =   2
  219.          Left            =   0
  220.          TabIndex        =   27
  221.          Top             =   2910
  222.          Width           =   615
  223.       End
  224.       Begin Label NavigationLabel 
  225.          Alignment       =   2  'Center
  226.          Caption         =   "&Last"
  227.          FontBold        =   0   'False
  228.          FontItalic      =   0   'False
  229.          FontName        =   "MS Sans Serif"
  230.          FontSize        =   8.25
  231.          FontStrikethru  =   0   'False
  232.          FontUnderline   =   0   'False
  233.          Height          =   210
  234.          Index           =   1
  235.          Left            =   600
  236.          TabIndex        =   25
  237.          Top             =   2190
  238.          Width           =   615
  239.       End
  240.       Begin Label NavigationLabel 
  241.          Alignment       =   2  'Center
  242.          Caption         =   "&First"
  243.          FontBold        =   0   'False
  244.          FontItalic      =   0   'False
  245.          FontName        =   "MS Sans Serif"
  246.          FontSize        =   8.25
  247.          FontStrikethru  =   0   'False
  248.          FontUnderline   =   0   'False
  249.          Height          =   210
  250.          Index           =   0
  251.          Left            =   0
  252.          TabIndex        =   23
  253.          Top             =   2190
  254.          Width           =   615
  255.       End
  256.    End
  257.    Begin PictureBox Background 
  258.       BackColor       =   &H00C0C0C0&
  259.       BorderStyle     =   0  'None
  260.       Height          =   975
  261.       Left            =   1350
  262.       ScaleHeight     =   975
  263.       ScaleWidth      =   2415
  264.       TabIndex        =   0
  265.       TabStop         =   0   'False
  266.       Top             =   0
  267.       Visible         =   0   'False
  268.       Width           =   2415
  269.       Begin TextBox FieldText 
  270.          Height          =   315
  271.          Index           =   0
  272.          Left            =   1500
  273.          TabIndex        =   33
  274.          Text            =   "Text1"
  275.          Top             =   75
  276.          Width           =   2955
  277.       End
  278.       Begin Label FieldLabel 
  279.          BackColor       =   &H00C0C0C0&
  280.          Caption         =   "Label1"
  281.          Height          =   255
  282.          Index           =   0
  283.          Left            =   0
  284.          TabIndex        =   1
  285.          Top             =   150
  286.          Visible         =   0   'False
  287.          Width           =   1440
  288.       End
  289.    End
  290.    Begin PictureBox FindPanel 
  291.       BorderStyle     =   0  'None
  292.       Height          =   3200
  293.       Left            =   0
  294.       ScaleHeight     =   3195
  295.       ScaleWidth      =   1215
  296.       TabIndex        =   3
  297.       TabStop         =   0   'False
  298.       Top             =   0
  299.       Visible         =   0   'False
  300.       Width           =   1215
  301.       Begin CommandButton QueryButton 
  302.          Caption         =   "<="
  303.          Height          =   375
  304.          Index           =   5
  305.          Left            =   720
  306.          TabIndex        =   13
  307.          Top             =   2640
  308.          Width           =   375
  309.       End
  310.       Begin CommandButton QueryButton 
  311.          Caption         =   "<"
  312.          Height          =   375
  313.          Index           =   4
  314.          Left            =   120
  315.          TabIndex        =   12
  316.          Top             =   2640
  317.          Width           =   375
  318.       End
  319.       Begin CommandButton QueryButton 
  320.          Caption         =   ">="
  321.          Height          =   375
  322.          Index           =   3
  323.          Left            =   720
  324.          TabIndex        =   11
  325.          Top             =   2160
  326.          Width           =   375
  327.       End
  328.       Begin CommandButton QueryButton 
  329.          Caption         =   ">"
  330.          Height          =   375
  331.          Index           =   2
  332.          Left            =   120
  333.          TabIndex        =   10
  334.          Top             =   2160
  335.          Width           =   375
  336.       End
  337.       Begin CommandButton QueryButton 
  338.          Caption         =   "<>"
  339.          Height          =   375
  340.          Index           =   1
  341.          Left            =   720
  342.          TabIndex        =   9
  343.          Top             =   1680
  344.          Width           =   375
  345.       End
  346.       Begin CommandButton QueryButton 
  347.          Caption         =   "="
  348.          Height          =   375
  349.          Index           =   0
  350.          Left            =   120
  351.          TabIndex        =   8
  352.          Top             =   1680
  353.          Width           =   375
  354.       End
  355.       Begin CommandButton DoneButton 
  356.          Caption         =   "&Done"
  357.          Height          =   315
  358.          Index           =   0
  359.          Left            =   120
  360.          TabIndex        =   7
  361.          Top             =   1260
  362.          Width           =   975
  363.       End
  364.       Begin CommandButton ClearButton 
  365.          Caption         =   "&Clear"
  366.          Height          =   315
  367.          Index           =   0
  368.          Left            =   120
  369.          TabIndex        =   6
  370.          Top             =   870
  371.          Width           =   975
  372.       End
  373.       Begin CommandButton FindButton 
  374.          Caption         =   "Find &Also"
  375.          Height          =   315
  376.          Index           =   1
  377.          Left            =   120
  378.          TabIndex        =   5
  379.          Top             =   480
  380.          Width           =   975
  381.       End
  382.       Begin CommandButton FindButton 
  383.          Caption         =   "&Find"
  384.          Height          =   315
  385.          Index           =   0
  386.          Left            =   120
  387.          TabIndex        =   4
  388.          Top             =   90
  389.          Width           =   975
  390.       End
  391.    End
  392.    Begin Menu UnzoomMenu 
  393.       Caption         =   "&Unzoom"
  394.       Visible         =   0   'False
  395.       Begin Menu SaveItem 
  396.          Caption         =   "&Save Changes"
  397.       End
  398.       Begin Menu UnzoomSeparator 
  399.          Caption         =   "-"
  400.       End
  401.       Begin Menu DiscardItem 
  402.          Caption         =   "&Discard Changes"
  403.       End
  404.    End
  405.    Begin Menu EditMenu 
  406.       Caption         =   "&Edit"
  407.       Visible         =   0   'False
  408.       Begin Menu UndoItem 
  409.          Caption         =   "&Undo"
  410.          Enabled         =   0   'False
  411.       End
  412.       Begin Menu EditSeparator 
  413.          Caption         =   "-"
  414.       End
  415.       Begin Menu CutItem 
  416.          Caption         =   "Cu&t"
  417.          Enabled         =   0   'False
  418.       End
  419.       Begin Menu CopyItem 
  420.          Caption         =   "&Copy"
  421.          Enabled         =   0   'False
  422.       End
  423.       Begin Menu PasteItem 
  424.          Caption         =   "&Paste"
  425.          Enabled         =   0   'False
  426.       End
  427.    End
  428. End
  429. ' ---------------------------------------------------------
  430. '       Copyright (C) 1993 Apex Software Corporation
  431. '
  432. ' You have a royalty-free right to use, modify, reproduce,
  433. ' and distribute the True Grid sample application files
  434. ' (and/or any modified version) in any way you find useful,
  435. ' provided that you agree that Apex Software Corporation
  436. ' has no warranty, obligations, or liability for any sample
  437. ' application files.
  438. ' ---------------------------------------------------------
  439.  
  440. ' True Grid Browser Sample Application
  441.  
  442. ' SCHEMA.FRM - This form displays label and text control
  443. ' arrays corresponding to the current database schema.
  444. ' The controls are contained within a picture control to
  445. ' facilitate scrolling.  The form's caption determines
  446. ' whether it is used to add, update, or find records.
  447.  
  448. ' ---- Local definitions ----
  449.  
  450. ' Height of the background picture control, in twips
  451.  
  452. Const BACKHEIGHT = 32768
  453.  
  454. ' Space between control rows, expressed as
  455. ' a multiple of the height of a text box
  456.  
  457. Const SPACING = 1.33
  458.  
  459. ' Space between control rows, in twips
  460.  
  461. Dim Delta As Single
  462.  
  463. ' Flag used by Form_Paint handler to set focus upon start-up
  464.  
  465. Dim Initialized As Integer
  466.  
  467. ' Active text box indices
  468.  
  469. Dim TextIndex As Integer
  470. Dim ZoomIndex As Integer
  471.  
  472. ' Visible states for mode-specific controls
  473.  
  474. Dim FindVisible As Integer
  475. Dim AddVisible As Integer
  476. Dim UpdateVisible As Integer
  477. Dim ScrollVisible As Integer
  478.  
  479. ' Save flag for zoomed text
  480.  
  481. Dim SaveZoomText As Integer
  482.  
  483. Sub AddButton_Click ()
  484.  
  485. 'Adds a record to the Database using the AddNew and Update methods.
  486. 'Again uses the columns property of the Grid to get the valid fieldnames
  487. On Error GoTo AddError
  488.  
  489.     Screen.MousePointer = HOURGLASS
  490.     MainForm.Data1.Recordset.AddNew
  491.     
  492.     'Loop through all the fields
  493.     For ct% = 0 To MainForm.Table1.Columns - 1
  494.         MainForm.Data1.Recordset.Fields(ct%) = FieldText(ct% + 1).Text
  495.     Next ct%
  496.  
  497.     'After all the information is loaded into the buffer the update adds the new record
  498.     MainForm.Data1.Recordset.Update
  499.     Screen.MousePointer = Default
  500.     Exit Sub
  501.  
  502. AddError:
  503.     Screen.MousePointer = Default
  504.     MsgBox "Add Error: " + Error$, MB_ICONEXCLAMATION
  505.     On Error Resume Next
  506.     Exit Sub
  507.  
  508. End Sub
  509.  
  510. Sub AdjustSystemMenu (F As Form)
  511.  
  512. ' Remove all but the Move and Close items from the system menu of a form
  513.  
  514.     ' Get the handle of the system menu
  515.  
  516.     M% = GetSystemMenu(F.hWnd, 0)
  517.   
  518.     ' Remove items starting from the bottom
  519.  
  520.     Z% = RemoveMenu(M%, 8, MF_BYPOSITION) ' Switch to
  521.     Z% = RemoveMenu(M%, 7, MF_BYPOSITION) ' Separator
  522.   
  523.     ' Remove the other separator only if the
  524.     ' form has neither min nor max buttons
  525.  
  526.     If Not (F.MinButton Or F.MaxButton) Then
  527.         Z% = RemoveMenu(M%, 5, MF_BYPOSITION) ' Separator
  528.     End If
  529.  
  530. End Sub
  531.  
  532. Sub ClearButton_Click (Index As Integer)
  533.  
  534. ' Clear all of the form's text controls
  535.  
  536.     For I% = 1 To MainForm.Table1.Columns
  537.         FieldText(I%).Text = ""
  538.     Next I%
  539.  
  540. End Sub
  541.  
  542. Sub CopyItem_Click ()
  543.  
  544. ' Implement Copy using the SendMessage API
  545.  
  546.     Z& = SendMessage(GetFocus(), WM_COPY, 0, 0&)
  547.  
  548. End Sub
  549.  
  550. Sub CutItem_Click ()
  551.  
  552.  'Implement Cut using the SendMessage API
  553.  
  554.     Z& = SendMessage(GetFocus(), WM_CUT, 0, 0&)
  555.  
  556. End Sub
  557.  
  558. Sub DiscardItem_Click ()
  559.  
  560. ' Form_Unload will restore the form to its previous state
  561.  
  562.     SaveZoomText = False
  563.     Unload SchemaForm
  564.  
  565. End Sub
  566.  
  567. Sub DoneButton_Click (Index As Integer)
  568.  
  569.     'Unloads the SchemaForm
  570.     Unload SchemaForm
  571.  
  572. End Sub
  573.  
  574. Sub EditMenu_Click ()
  575.  
  576. ' Enable/disable Edit menu items as appropriate
  577.  
  578.     ' Use the GetFocus API to obtain a window handle
  579.  
  580.     W% = GetFocus()
  581.  
  582.     ' Determine if the zoomed text box has undo information
  583.  
  584.     If SendMessage(W%, EM_CANUNDO, 0, 0&) = 0 Then
  585.         Undo% = False
  586.     Else
  587.         Undo% = True
  588.     End If
  589.  
  590.     ' Determine if the zoomed text box has a text selection
  591.  
  592.     Sel% = (ZoomText.SelLength > 0)
  593.  
  594.     ' Determine if there is text in the clipboard
  595.  
  596.     Clip% = (Clipboard.GetText() <> "")
  597.  
  598.     ' Adjust the Edit menu accordingly
  599.  
  600.     UndoItem.Enabled = Undo%
  601.     CutItem.Enabled = Sel%
  602.     CopyItem.Enabled = Sel%
  603.     PasteItem.Enabled = Clip%
  604.  
  605. End Sub
  606.  
  607. Sub FieldText_GotFocus (Index As Integer)
  608.  
  609. ' Save the index of the active text box for the query
  610. ' symbol buttons, and make the control visible if it
  611. ' is scrolled out of view
  612.  
  613.     TextIndex = Index
  614.  
  615.     If Not ScrollBar.Visible Then Exit Sub
  616.  
  617.     If Index < ScrollBar.Value Then
  618.         ScrollBar.Value = Index
  619.  
  620.     ElseIf Index > (ScrollBar.Value + MainForm.Table1.Columns - ScrollBar.Max) Then
  621.         ScrollBar.Value = Index - MainForm.Table1.Columns + ScrollBar.Max
  622.     End If
  623.  
  624. End Sub
  625.  
  626. Sub FindButton_Click (Index As Integer)
  627.     
  628. 'The procedure does a find by going out getting the FieldText controls, checking to see if they
  629. 'contain a search condition, if they do then they are added to a select statement which is then
  630. 'assigned to the Data Control RecordSource property
  631.     Dim First As Integer
  632.     Dim Conjunct As String
  633.     Dim QueryVal As String
  634.     Dim FldType As Integer
  635.  
  636.     'If find is click then use AND if Findalso is clicked use OR
  637.     Select Case Index
  638.         Case 0
  639.             Conjunct = " AND "
  640.         Case 1
  641.             Conjunct = " OR "
  642.     End Select
  643.  
  644. 'Any error generated here is usually going to be an SQL Error
  645. On Error GoTo ErrHandler3
  646.  
  647.     Screen.MousePointer = HOURGLASS
  648.  
  649.     'First time through no AND is used
  650.     First = True
  651.  
  652.     'Loop through all valid Fields
  653.     For ct% = 1 To MainForm.Table1.Columns
  654.         
  655.         'If the FieldText control is not empty then add it to the find critera
  656.         If FieldText(ct%) <> "" Then
  657.             
  658.             'He were get the Field Type and pass that along with FieldText to a procedure
  659.             'That checks the value and formats it for the SQL statement
  660.             FldType = MainForm.Data1.Database.TableDefs(curTable).Fields(FieldLabel(ct%).Caption).Type
  661.             QueryVal = FieldText(ct%).Text
  662.             
  663.             Call SQLFieldValue(FldType, QueryVal)
  664.             If FldType = DB_ERROR Then Error SQLError
  665.             
  666.             If First Then
  667.                 First = False
  668.                 temp$ = temp$ + Chr$(91) + FieldLabel(ct%).Caption + Chr$(93) + " " + QueryVal
  669.             Else
  670.                 temp$ = temp$ + Conjunct + Chr$(91) + FieldLabel(ct%).Caption + Chr$(93) + " " + QueryVal
  671.             End If
  672.         End If
  673.     Next ct%
  674.  
  675.     'Add the Where clause to the beginning of the Find condition
  676.     curFind = " Where " + temp$
  677.  
  678.     'Rebuild the Table
  679.     MainForm.Data1.RecordSource = "Select * From " + "[" + curTable + "]" + curFind + curSort
  680.     MainForm.Data1.Refresh
  681.  
  682.     Screen.MousePointer = Default
  683.  
  684. Exit Sub
  685.  
  686. ErrHandler3:
  687.     Screen.MousePointer = Default
  688.     Select Case Err
  689.         Case SQLError
  690.             MsgBox "SQL Error:  Your Field Value is incorrect", MB_ICONEXCLAMATION
  691.         Case Else
  692.             MsgBox "SQL Error:  " + Str$(Err) + " " + Error, MB_ICONEXCLAMATION
  693.         
  694.     End Select
  695.     Exit Sub
  696.  
  697. End Sub
  698.  
  699. Sub FlashIcon (This As Control)
  700.  
  701. ' This routine is used to give the user some feedback
  702. ' when selecting one of the picture control buttons
  703.  
  704.     For I% = 1 To 4
  705.         This.Line (0, 0)-(This.ScaleWidth, This.ScaleHeight), , B
  706.     Next I%
  707.  
  708. End Sub
  709.  
  710. Sub Form_Load ()
  711.  
  712.     ' Switch to the hourglass cursor while loading
  713.  
  714.     Screen.MousePointer = HOURGLASS
  715.     Initialized = False
  716.  
  717.     ' Center the form within the screen
  718.  
  719.     CenterForm SchemaForm
  720.  
  721.     ' Remove unwanted menu items
  722.  
  723.     AdjustSystemMenu SchemaForm
  724.  
  725.     ' Add accelerators to Edit menu items
  726.  
  727.     UndoItem.Caption = "&Undo" + Chr$(9) + "Alt+BkSp"
  728.     CutItem.Caption = "Cu&t" + Chr$(9) + "Shift+Del"
  729.     CopyItem.Caption = "&Copy" + Chr$(9) + "Ctrl+Ins"
  730.     PasteItem.Caption = "&Paste" + Chr$(9) + "Shift+Ins"
  731.  
  732.     ' Compute the spacing between control rows and
  733.     ' reposition the hidden controls accordingly
  734.  
  735.     Delta = FieldText(0).Height * 1.33
  736.     FieldLabel(0).Top = FieldLabel(0).Top - Delta
  737.     FieldText(0).Top = FieldText(0).Top - Delta
  738.  
  739.     ' Initialize control array elements for each schema field
  740.  
  741.     For I% = 1 To MainForm.Table1.Columns
  742.  
  743.         Load FieldLabel(I%)
  744.         FieldLabel(I%).Caption = MainForm.Table1.ColumnName(I%)
  745.         FieldLabel(I%).Top = FieldLabel(I% - 1).Top + Delta
  746.         FieldLabel(I%).Visible = True
  747.  
  748.         Load FieldText(I%)
  749.         FieldText(I%).Top = FieldText(I% - 1).Top + Delta
  750.         FieldText(I%).Visible = True
  751.  
  752.     Next I%
  753.  
  754. End Sub
  755.  
  756. Sub Form_Paint ()
  757.  
  758. ' If this is the first time this event was fired, finish
  759. ' initializing the form; otherwise, do nothing.
  760.  
  761.     If Initialized Then Exit Sub
  762.  
  763.     Initialized = True
  764.  
  765.     If SchemaForm.Caption = "Update..." Then
  766.         GetFields
  767.     Else
  768.         ClearButton_Click (0)
  769.     End If
  770.     
  771.     ' Set focus to the first visible text control
  772.  
  773.     FieldText(1).SetFocus
  774.     Screen.MousePointer = Default
  775.  
  776. End Sub
  777.  
  778. Sub Form_Resize ()
  779.  
  780.     ' If the Edit menu is visible, adjust the size of the
  781.     ' zoom text box to fit the new form size and exit
  782.  
  783.     If EditMenu.Visible Then
  784.         ZoomText.Visible = False
  785.         ZoomText.Top = 0
  786.         ZoomText.Left = 0
  787.         ZoomText.Width = SchemaForm.ScaleWidth
  788.         ZoomText.Height = SchemaForm.ScaleHeight
  789.         ZoomText.Visible = True
  790.         Exit Sub
  791.     End If
  792.  
  793.     ' Hide all controls to avoid flicker
  794.  
  795.     ZoomText.Visible = False
  796.     FindPanel.Visible = False
  797.     AddPanel.Visible = False
  798.     UpdatePanel.Visible = False
  799.     Background.Visible = False
  800.     ScrollBar.Visible = False
  801.  
  802.     ' Undo any prior scrolling
  803.  
  804.     Background.Top = 0
  805.  
  806.     ' Make the height of the picture control as large as possible
  807.     ' so that control array elements which were not originally
  808.     ' visible will be scrolled into view
  809.  
  810.     Background.Height = BACKHEIGHT
  811.  
  812.     ' Assume no scroll bar initially
  813.  
  814.     NeedScroll% = False
  815.     TextLen% = SchemaForm.ScaleWidth - FieldText(0).Left - Background.Left - ScrollBar.Width
  816.  
  817.     ' If a scroll bar is needed, move it to the far right of the
  818.     ' form and adjust the size of the picture control accordingly
  819.  
  820.     If ScrollBarNeeded(SchemaForm) Then
  821.         ScrollBar.Top = 0
  822.         ScrollBar.Left = SchemaForm.ScaleWidth - ScrollBar.Width
  823.         ScrollBar.Height = SchemaForm.ScaleHeight
  824.         ScrollBar.Value = 1
  825.         ScrollBar.Min = 1
  826.         ScrollBar.Max = ScrollBarMax(SchemaForm)
  827.         NeedScroll% = True
  828.         TextLen% = TextLen% - ScrollBar.Width
  829.         Background.Width = ScrollBar.Left - Background.Left
  830.  
  831.     ' Otherwise, extend the picture control to the end of the form
  832.  
  833.     Else
  834.         Background.Width = SchemaForm.ScaleWidth - Background.Left
  835.     End If
  836.  
  837.     ' Set the width of each text box
  838.  
  839.     If TextLen% > 0 Then
  840.         For I% = 1 To MainForm.Table1.Columns
  841.             FieldText(I%).Width = TextLen%
  842.         Next I%
  843.     End If
  844.  
  845.     ' Make the controls visible, if required
  846.  
  847.     ScrollBar.Visible = NeedScroll%
  848.     Background.Visible = True
  849.  
  850.     ' Choose the appropriate set of buttons (contained
  851.     ' in a picture control) based on the form's caption,
  852.     ' which is set by the caller
  853.  
  854.     Select Case SchemaForm.Caption
  855.  
  856.         Case "Find..."
  857.             FindPanel.Left = 0
  858.             FindPanel.Top = 0
  859.             FindButton(0).Default = True
  860.             DoneButton(0).Cancel = True
  861.             FindPanel.Visible = True
  862.  
  863.         Case "Add..."
  864.             AddPanel.Left = 0
  865.             AddPanel.Top = 0
  866.             AddButton.Default = True
  867.             DoneButton(1).Cancel = True
  868.             AddPanel.Visible = True
  869.  
  870.         Case "Update..."
  871.             UpdatePanel.Left = 0
  872.             UpdatePanel.Top = 0
  873.             UpdateButton.Default = True
  874.             DoneButton(2).Cancel = True
  875.             UpdatePanel.Visible = True
  876.  
  877.     End Select
  878.  
  879.     ' Give the first text box focus
  880.  
  881.     FieldText(1).SetFocus
  882.  
  883. End Sub
  884.  
  885. Sub Form_Unload (Cancel As Integer)
  886.  
  887. ' If a zoomed text box is open, restore the form to its
  888. ' prior state without unloading it.  Otherwise, hide the
  889. ' form before unloading control array elements.
  890.  
  891.     If ZoomText.Visible Then
  892.  
  893.         ' Hide zoom controls
  894.  
  895.         ZoomText.Visible = False
  896.         UnzoomMenu.Visible = False
  897.         EditMenu.Visible = False
  898.  
  899.         ' Restore the form to its previous state
  900.  
  901.         ScrollBar.Visible = ScrollVisible
  902.         Background.Visible = True
  903.         FindPanel.Visible = FindVisible
  904.         AddPanel.Visible = AddVisible
  905.         UpdatePanel.Visible = UpdateVisible
  906.  
  907.         ' Copy the edited text to the current text box,
  908.         ' if desired, and give the text box focus
  909.  
  910.         If SaveZoomText Then
  911.             FieldText(ZoomIndex).Text = ZoomText.Text
  912.         End If
  913.  
  914.         FieldText(ZoomIndex).SetFocus
  915.  
  916.         ' Don't unload the form yet
  917.  
  918.         Cancel = True
  919.  
  920.     Else
  921.  
  922.         ' Hide the form to eliminate flicker
  923.  
  924.         SchemaForm.Hide
  925.  
  926.         ' Unload control array elements
  927.  
  928.         For I% = 1 To MainForm.Table1.Columns
  929.             Unload FieldLabel(I%)
  930.             Unload FieldText(I%)
  931.         Next I%
  932.  
  933.     End If
  934.  
  935. End Sub
  936.  
  937. Sub GetFields ()
  938.     
  939. 'Display the current record in the FieldText controls by accessing the current
  940. 'record of the data control
  941.  
  942.     For I% = 0 To MainForm.Table1.Columns - 1
  943.         
  944.         'If the value is NULL in the database then assign a blank, otherwise an error is generated
  945.         If MainForm.Data1.Recordset(I%) <> "#NULL#" Then
  946.             FieldText(I% + 1).Text = MainForm.Data1.Recordset(I%)
  947.         Else
  948.             FieldText(I% + 1).Text = ""
  949.         End If
  950.     Next I%
  951.  
  952. End Sub
  953.  
  954. Sub NavigationButton_Click (Index As Integer)
  955.  
  956. ' Perform the navigation operation associated with
  957. ' the specified picture control button
  958.     
  959.  On Error GoTo ErrHandler1
  960.  
  961.     FlashIcon NavigationButton(Index)
  962.  
  963.     Select Case Index
  964.         Case 0
  965.             MainForm.Data1.Recordset.MoveFirst
  966.         Case 1
  967.             MainForm.Data1.Recordset.MoveLast
  968.         Case 2
  969.             MainForm.Data1.Recordset.MovePrevious
  970.         Case 3
  971.             MainForm.Data1.Recordset.MoveNext
  972.     End Select
  973.  
  974.     'After Navigation update SchemaForm text controls with GetFields
  975.     GetFields
  976.  
  977.     'If users goes beyond the end or before the beginning of the file, give warning beep
  978.     If MainForm.Data1.Recordset.BOF Or MainForm.Data1.Recordset.EOF Then Beep
  979.  
  980. Exit Sub
  981.  
  982. ErrHandler1:
  983.     
  984.     'The only error generated in the case is the BOF and EOF and you can ignore them
  985.     Resume Next
  986.  
  987. End Sub
  988.  
  989. Sub NavigationButton_GotFocus (Index As Integer)
  990.  
  991. ' Toggle the FontItalic property of the label associated
  992. ' with the specified picture control button
  993.  
  994.     UpdateButton.Default = False
  995.     NavigationLabel(Index).FontItalic = Not NavigationLabel(Index).FontItalic
  996.  
  997. End Sub
  998.  
  999. Sub NavigationButton_KeyPress (Index As Integer, KeyAscii As Integer)
  1000.  
  1001. ' Make the Enter key work for picture control buttons
  1002.  
  1003.     If KeyAscii = KEY_RETURN Then NavigationButton_Click Index
  1004.  
  1005. End Sub
  1006.  
  1007. Sub NavigationButton_LostFocus (Index As Integer)
  1008.  
  1009. ' Toggle the FontItalic property of the label associated
  1010. ' with the specified picture control button
  1011.  
  1012.     NavigationLabel(Index).FontItalic = Not NavigationLabel(Index).FontItalic
  1013.     UpdateButton.Default = True
  1014.  
  1015. End Sub
  1016.  
  1017. Sub PasteItem_Click ()
  1018.  
  1019. ' Implement Paste using the SendMessage API
  1020.  
  1021.     Z& = SendMessage(GetFocus(), WM_PASTE, 0, 0&)
  1022.  
  1023. End Sub
  1024.  
  1025. Sub QueryButton_Click (Index As Integer)
  1026.  
  1027. ' Append the button's caption to the current text box
  1028.  
  1029.     T$ = FieldText(TextIndex).Text + QueryButton(Index).Caption
  1030.     FieldText(TextIndex).Text = T$
  1031.     FieldText(TextIndex).SelLength = 0
  1032.     FieldText(TextIndex).SelStart = Len(T$)
  1033.     FieldText(TextIndex).SetFocus
  1034.  
  1035. End Sub
  1036.  
  1037. Sub SaveItem_Click ()
  1038.  
  1039. ' Form_Unload will restore the form to its previous state
  1040.  
  1041.     SaveZoomText = True
  1042.     Unload SchemaForm
  1043.  
  1044. End Sub
  1045.  
  1046. Sub ScrollBar_Change ()
  1047.  
  1048. ' Scroll the label and text controls simply
  1049. ' by moving the background picture control
  1050.  
  1051.     Background.Top = -Delta * (ScrollBar.Value - 1)
  1052.  
  1053. End Sub
  1054.  
  1055. Function ScrollBarMax (This As Form) As Integer
  1056.  
  1057. ' Return the maximum value for the scroll bar (at least 2)
  1058.  
  1059.     N% = MainForm.Table1.Columns - (This.ScaleHeight / Delta) + 1
  1060.  
  1061.     If N% > 1 Then
  1062.         ScrollBarMax = N%
  1063.     Else
  1064.         ScrollBarMax = 2
  1065.     End If
  1066.  
  1067. End Function
  1068.  
  1069. Function ScrollBarNeeded (This As Form) As Integer
  1070.  
  1071. ' Return FALSE if all controls fit on the form, TRUE otherwise
  1072.  
  1073.     I% = MainForm.Table1.Columns
  1074.  
  1075.     If FieldText(I%).Top + FieldText(I%).Height > This.ScaleHeight Then
  1076.         ScrollBarNeeded = True
  1077.     Else
  1078.         ScrollBarNeeded = False
  1079.     End If
  1080.  
  1081. End Function
  1082.  
  1083. Sub UndoItem_Click ()
  1084.  
  1085. ' Implement Undo using the SendMessage API
  1086.  
  1087.     Z& = SendMessage(GetFocus(), EM_UNDO, 0, 0&)
  1088.  
  1089. End Sub
  1090.  
  1091. Sub UpdateButton_Click ()
  1092.  
  1093. 'Update the the current record by first entering the Edit mode of the RecordSet,
  1094. 'change the value to the value in the FieldText control, then call the Update
  1095. On Error GoTo UpdateError
  1096.  
  1097.     Screen.MousePointer = HOURGLASS
  1098.  
  1099.     'Loop through all valid field names
  1100.     For ct% = 0 To MainForm.Table1.Columns - 1
  1101.         MainForm.Data1.Recordset.Edit
  1102.         MainForm.Data1.Recordset.Fields(ct%) = FieldText(ct% + 1).Text
  1103.         MainForm.Data1.Recordset.Update
  1104.     Next ct%
  1105.     Screen.MousePointer = Default
  1106.     Exit Sub
  1107.  
  1108. UpdateError:
  1109.     Screen.MousePointer = Default
  1110.     MsgBox "Update Error: " + Error$, MB_ICONEXCLAMATION
  1111.     Exit Sub
  1112.             
  1113. End Sub
  1114.  
  1115. Sub ZoomButton_Click (Index As Integer)
  1116.  
  1117.     ' Save the visible state of mode-specific controls
  1118.  
  1119.     FindVisible = FindPanel.Visible
  1120.     AddVisible = AddPanel.Visible
  1121.     UpdateVisible = UpdatePanel.Visible
  1122.     ScrollVisible = ScrollBar.Visible
  1123.  
  1124.     ' Hide all controls to avoid flicker
  1125.  
  1126.     ZoomText.Visible = False
  1127.     FindPanel.Visible = False
  1128.     AddPanel.Visible = False
  1129.     UpdatePanel.Visible = False
  1130.     Background.Visible = False
  1131.     ScrollBar.Visible = False
  1132.  
  1133.     ' Make the menu bar visible
  1134.  
  1135.     EditMenu.Visible = True
  1136.     UnzoomMenu.Visible = True
  1137.  
  1138.     ' Resize the text control
  1139.  
  1140.     ZoomText.Top = 0
  1141.     ZoomText.Left = 0
  1142.     ZoomText.Width = SchemaForm.ScaleWidth
  1143.     ZoomText.Height = SchemaForm.ScaleHeight
  1144.     ZoomText.Visible = True
  1145.  
  1146.     ' Copy the contents of the current text box
  1147.  
  1148.     ZoomIndex = TextIndex
  1149.     ZoomText.Text = FieldText(ZoomIndex).Text
  1150.  
  1151.     ' Changes will be saved unless the Discard item is chosen
  1152.  
  1153.     SaveZoomText = True
  1154.  
  1155. End Sub
  1156.  
  1157. Sub ZoomText_KeyUp (KeyCode As Integer, Shift As Integer)
  1158.  
  1159. ' Map Alt+BkSp to the Undo menu item since we can't assign
  1160. ' it as an accelerator key using the Menu Design Window
  1161.  
  1162.     If KeyCode = KEY_BACK And (Shift And ALT_MASK) Then
  1163.         If SendMessage(GetFocus(), EM_CANUNDO, 0, 0&) <> 0 Then
  1164.             KeyCode = 0
  1165.             UndoItem_Click
  1166.         End If
  1167.     End If
  1168.     
  1169. End Sub
  1170.  
  1171.