home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l407 / 5.ddi / TBLSTRU.FR_ / TBLSTRU.bin (.txt)
Encoding:
Visual Basic Form  |  1993-04-28  |  16.7 KB  |  612 lines

  1. VERSION 2.00
  2. Begin Form fTblStru 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Table Structure"
  5.    ClientHeight    =   5550
  6.    ClientLeft      =   2100
  7.    ClientTop       =   1890
  8.    ClientWidth     =   5040
  9.    Height          =   5955
  10.    Left            =   2040
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   5550
  15.    ScaleWidth      =   5040
  16.    Top             =   1545
  17.    Width           =   5160
  18.    Begin TextBox cTableName 
  19.       BackColor       =   &H00FFFFFF&
  20.       Height          =   288
  21.       Left            =   1680
  22.       TabIndex        =   0
  23.       Tag             =   "OL"
  24.       Top             =   120
  25.       Width           =   1932
  26.    End
  27.    Begin PictureBox IndexBox 
  28.       BackColor       =   &H00C0C0C0&
  29.       BorderStyle     =   0  'None
  30.       Height          =   1692
  31.       Left            =   0
  32.       ScaleHeight     =   1695
  33.       ScaleWidth      =   5055
  34.       TabIndex        =   9
  35.       Top             =   3720
  36.       Width           =   5052
  37.       Begin CommandButton PrintButton 
  38.          Caption         =   "&Print Structure"
  39.          Height          =   372
  40.          Left            =   720
  41.          TabIndex        =   14
  42.          Top             =   1320
  43.          Visible         =   0   'False
  44.          Width           =   1452
  45.       End
  46.       Begin CommandButton AddTableButton 
  47.          Caption         =   "&Build the Table"
  48.          Enabled         =   0   'False
  49.          Height          =   372
  50.          Left            =   720
  51.          TabIndex        =   8
  52.          Top             =   1320
  53.          Visible         =   0   'False
  54.          Width           =   1452
  55.       End
  56.       Begin CommandButton CloseButton 
  57.          Cancel          =   -1  'True
  58.          Caption         =   "&Close"
  59.          Height          =   372
  60.          Left            =   2880
  61.          TabIndex        =   3
  62.          Top             =   1320
  63.          Width           =   1452
  64.       End
  65.       Begin CommandButton AddIndexButton 
  66.          Caption         =   "Add &Index"
  67.          Height          =   252
  68.          Left            =   1200
  69.          TabIndex        =   5
  70.          Top             =   120
  71.          Width           =   1332
  72.       End
  73.       Begin CommandButton DelIndexButton 
  74.          Caption         =   "&Delete Index"
  75.          Height          =   252
  76.          Left            =   2640
  77.          TabIndex        =   6
  78.          Top             =   120
  79.          Width           =   1332
  80.       End
  81.       Begin Grid cIndexes 
  82.          Cols            =   4
  83.          FixedCols       =   0
  84.          Height          =   750
  85.          Left            =   120
  86.          TabIndex        =   2
  87.          Top             =   420
  88.          Width           =   4815
  89.       End
  90.       Begin Line Line1 
  91.          BorderWidth     =   5
  92.          X1              =   0
  93.          X2              =   4800
  94.          Y1              =   0
  95.          Y2              =   0
  96.       End
  97.       Begin Label IndexesLabel 
  98.          BackColor       =   &H00C0C0C0&
  99.          Caption         =   "Indexes:"
  100.          Height          =   252
  101.          Left            =   240
  102.          TabIndex        =   10
  103.          Top             =   120
  104.          Width           =   1092
  105.       End
  106.    End
  107.    Begin PictureBox FieldBox 
  108.       BackColor       =   &H00C0C0C0&
  109.       BorderStyle     =   0  'None
  110.       Height          =   2892
  111.       Left            =   0
  112.       ScaleHeight     =   2895
  113.       ScaleWidth      =   5055
  114.       TabIndex        =   11
  115.       Top             =   600
  116.       Width           =   5052
  117.       Begin CommandButton RemoveFieldButton 
  118.          Caption         =   "&Remove Field"
  119.          Height          =   252
  120.          Left            =   2625
  121.          TabIndex        =   7
  122.          Top             =   0
  123.          Width           =   1332
  124.       End
  125.       Begin CommandButton AddFieldButton 
  126.          Caption         =   "&Add Field"
  127.          Height          =   252
  128.          Left            =   1200
  129.          TabIndex        =   4
  130.          Top             =   0
  131.          Width           =   1332
  132.       End
  133.       Begin Grid cFields 
  134.          BackColor       =   &H00FFFFFF&
  135.          Cols            =   3
  136.          FixedCols       =   0
  137.          Height          =   2532
  138.          Left            =   120
  139.          TabIndex        =   1
  140.          Top             =   288
  141.          Width           =   4800
  142.       End
  143.       Begin Label FieldsLabel 
  144.          BackColor       =   &H00C0C0C0&
  145.          Caption         =   "Fields:"
  146.          Height          =   192
  147.          Left            =   240
  148.          TabIndex        =   12
  149.          Top             =   0
  150.          Width           =   732
  151.       End
  152.    End
  153.    Begin Label TableNameLabel 
  154.       BackColor       =   &H00C0C0C0&
  155.       Caption         =   "Table Name:"
  156.       Height          =   252
  157.       Left            =   360
  158.       TabIndex        =   13
  159.       Top             =   120
  160.       Width           =   1212
  161.    End
  162. Option Explicit
  163. Sub AddFieldButton_Click ()
  164.   MsgBar "Enter New Field Parameters, Press 'Close' when finished", False
  165.   fAddField.Show MODAL
  166.   MsgBar "", False
  167. End Sub
  168. Sub AddIndexButton_Click ()
  169.   MsgBar "Enter New Index Parameters, Press 'Close' when finished", False
  170.   fIndexAdd.Show MODAL
  171.   MsgBar "", False
  172. End Sub
  173. Sub AddTableButton_Click ()
  174.   Dim tbl As New TableDef
  175.   Dim fld As Field
  176.   Dim ind As Index
  177.   Dim i As Integer
  178.   Dim x As String
  179.   On Error GoTo ATErr
  180.   SetHourglass Me
  181.   MsgBar "Building New Table", True
  182.   tbl.Name = cTableName
  183.   'search to see if table exists
  184.   For i = 0 To gCurrentDB.TableDefs.Count - 1
  185.     If UCase(gCurrentDB.TableDefs(i).Name) = UCase(tbl.Name) Then
  186.       If MsgBox(tbl.Name + " already exists, delete it?", 4) = YES Then
  187.          gCurrentDB.TableDefs.Delete gCurrentDB.TableDefs(tbl.Name)
  188.       Else
  189.          ResetMouse Me
  190.          Exit Sub
  191.       End If
  192.       Exit For
  193.     End If
  194.   Next
  195.   'add the first field
  196.   cFields.Row = 1
  197.   cFields.Col = 0
  198.   If cFields = "" Then
  199.     Beep
  200.     MsgBox "No Fields Defined!", 48
  201.     Exit Sub
  202.   End If
  203.   Set fld = New Field
  204.   fld.Name = cFields
  205.   cFields.Col = 1
  206.   fld.Type = GetFieldType((cFields))
  207.   If cFields = "Counter" Then
  208.     fld.Attributes = &H10   'counter type
  209.   End If
  210.   cFields.Col = 2
  211.   fld.Size = Val(cFields)
  212.   tbl.Fields.Append fld
  213.   gCurrentDB.TableDefs.Append tbl
  214.   'add the rest of the fields
  215.   For i = 2 To cFields.Rows - 1
  216.     Set fld = New Field
  217.     cFields.Row = i
  218.     cFields.Col = 0
  219.     fld.Name = cFields
  220.     cFields.Col = 1
  221.     fld.Type = GetFieldType((cFields))
  222.     If cFields = "Counter" Then
  223.       fld.Attributes = &H10   'counter type
  224.     End If
  225.     cFields.Col = 2
  226.     fld.Size = Val(cFields)
  227.     gCurrentDB.TableDefs(tbl.Name).Fields.Append fld
  228.   Next
  229.   'add the indexes
  230.   For i = 1 To cIndexes.Rows - 1
  231.     Set ind = New Index
  232.     cIndexes.Row = i
  233.     cIndexes.Col = 0
  234.     If cIndexes = "" Then Exit For
  235.     ind.Name = cIndexes
  236.     cIndexes.Col = 1
  237.     ind.Fields = cIndexes
  238.     cIndexes.Col = 2
  239.     If cIndexes = "True" Then
  240.       ind.Unique = True
  241.     Else
  242.       ind.Unique = False
  243.     End If
  244.     cIndexes.Col = 3
  245.     If gstDataType = "ODBC" Then
  246.       cIndexes = "N/A"
  247.     Else
  248.       If cIndexes = "True" Then
  249.         ind.Primary = True
  250.       Else
  251.         ind.Primary = False
  252.       End If
  253.     End If
  254.     gCurrentDB.TableDefs(tbl.Name).Indexes.Append ind
  255.   Next
  256.   RefreshTables fTables.cTableList, True
  257.   GoTo ATEnd
  258. ATErr:
  259.   ResetMouse Me
  260.   ShowError
  261.   Resume ATEnd
  262. ATEnd:
  263.   ResetMouse Me
  264.   MsgBar "", False
  265.   Unload Me
  266. End Sub
  267. Sub cFields_DblClick ()
  268.    Dim f As New fDataBox
  269.    Dim erm As String
  270.    'only allowed on existing tables
  271.    If gfAddTableFlag = True Then
  272.      Exit Sub
  273.    End If
  274.    On Error GoTo FldPropErr
  275.    cFields.Row = cFields.SelStartRow
  276.    cFields.Col = 0
  277.    Set gCurrentField = gCurrentDB.TableDefs(fTables.cTableList).Fields(cFields)
  278.    f.Caption = "Field Properties"
  279.    f.Tag = "FLD"
  280.    erm = "Name"
  281.    f.cData.AddItem "Name = " + gCurrentField.Name
  282.    erm = "Type"
  283.    f.cData.AddItem "Type = " & gCurrentField.Type
  284.    erm = "Size"
  285.    f.cData.AddItem "Size = " & gCurrentField.Size
  286.    erm = "SourceField"
  287.    f.cData.AddItem "SourceField = " + gCurrentField.SourceField
  288.    erm = "SourceTable"
  289.    f.cData.AddItem "SourceTable = " + gCurrentField.SourceTable
  290.    erm = "CollatingOrder"
  291.    f.cData.AddItem "CollatingOrder = " & gCurrentField.CollatingOrder
  292.    erm = "Attributes"
  293.    f.cData.AddItem "Attributes = &H" & Hex(gCurrentField.Attributes)
  294.    erm = "OrdinalPosition"
  295.    f.cData.AddItem "OrdinalPosition = " & gCurrentField.OrdinalPosition
  296.    f.Show MODAL
  297.   GoTo FldPropEnd
  298. FldPropErr:
  299.   f.cData.AddItem erm + ":" + Error$
  300.   Resume Next
  301. FldPropEnd:
  302. End Sub
  303. Sub cIndexes_DblClick ()
  304.    Dim f As New fDataBox
  305.    Dim erm As String
  306.    'only allowed on existing tables
  307.    If gfAddTableFlag = True Then
  308.      Exit Sub
  309.    End If
  310.    On Error GoTo IndPropErr
  311.    cIndexes.Row = cIndexes.SelStartRow
  312.    cIndexes.Col = 0
  313.    Set gCurrentIndex = gCurrentDB.TableDefs(fTables.cTableList).Indexes(cIndexes)
  314.    f.Caption = "Field Properties"
  315.    f.Tag = "IND"
  316.    erm = "Name"
  317.    f.cData.AddItem "Name = " + gCurrentIndex.Name
  318.    erm = "Fields"
  319.    f.cData.AddItem "Fields = " + gCurrentIndex.Fields
  320.    erm = "Unique"
  321.    f.cData.AddItem "Unique Flag = " + stTrueFalse((gCurrentIndex.Unique))
  322.    erm = "Primary"
  323.    f.cData.AddItem "PrimaryFlag = " + stTrueFalse((gCurrentIndex.Primary))
  324.    f.Show MODAL
  325.   GoTo IndPropEnd
  326. IndPropErr:
  327.   f.cData.AddItem erm + ":" + Error$
  328.   Resume Next
  329. IndPropEnd:
  330. End Sub
  331. Sub CloseButton_Click ()
  332.   Unload Me
  333.   MsgBar "", False
  334. End Sub
  335. Sub cTableName_Change ()
  336.   If cTableName = "" Then
  337.     AddTableButton.Enabled = False
  338.   Else
  339.     AddTableButton.Enabled = True
  340.   End If
  341. End Sub
  342. Sub cTableName_KeyPress (KeyAscii As Integer)
  343.   If cTableName.TabStop = False Then
  344.     KeyAscii = 0   'throw away the key
  345.   End If
  346. End Sub
  347. Sub DelIndexButton_Click ()
  348.   cIndexes.Row = cIndexes.SelStartRow
  349.   cIndexes.Col = 0
  350.   If cIndexes = "" Then Exit Sub
  351.   If MsgBox("Delete """ + cIndexes + """ index?", MSGBOX_TYPE) = YES Then
  352.     If gfAddTableFlag = False Then
  353.       gCurrentDB.TableDefs(fTables.cTableList).Indexes.Delete gCurrentDB.TableDefs(fTables.cTableList).Indexes(cIndexes)
  354.     End If
  355.     'refresh the list of indexes
  356.     If cIndexes.Rows = 2 Then
  357.       cIndexes.Col = 0
  358.       cIndexes = ""
  359.       cIndexes.Col = 1
  360.       cIndexes = ""
  361.       cIndexes.Col = 2
  362.       cIndexes = ""
  363.     Else
  364.       cIndexes.RemoveItem cIndexes.Row
  365.     End If
  366.   End If
  367. End Sub
  368. Sub Form_Load ()
  369.   Dim tbl As TableDef
  370.   Dim i As Integer
  371.   Dim s As String
  372.   On Error GoTo LoadErr
  373.   Width = 5160
  374.   Height = 5955
  375.   SetHourglass Me
  376.   fTables.MousePointer = HOURGLASS
  377.   MsgBar "Opening Design Form", True
  378.   fTblStru.cTableName.TabStop = gfAddTableFlag
  379.   'setup field grid titles
  380.   cFields.ColWidth(0) = 2500
  381.   cFields.ColWidth(1) = 1500
  382.   cFields.ColWidth(2) = 500
  383.   cFields.Row = 0
  384.   cFields.Col = 0
  385.   cFields = "Name"
  386.   cFields.Col = 1
  387.   cFields = "Type"
  388.   cFields.Col = 2
  389.   cFields = "Size"
  390.   'setup index grid titles
  391.   cIndexes.ColWidth(0) = 850
  392.   cIndexes.ColWidth(1) = 2250
  393.   cIndexes.ColWidth(2) = 650
  394.   cIndexes.ColWidth(3) = 700
  395.   cIndexes.Row = 0
  396.   cIndexes.Col = 0
  397.   cIndexes = "Name"
  398.   cIndexes.Col = 1
  399.   cIndexes = "Indexed Fields"
  400.   cIndexes.Col = 2
  401.   cIndexes = "Unique"
  402.   cIndexes.Col = 3
  403.   cIndexes = "Primary"
  404.   If gfAddTableFlag = True Then
  405.     Caption = "Add Table"
  406.     AddTableButton.Visible = True
  407.     cFields.Rows = 2
  408.     cIndexes.Rows = 2
  409.   Else
  410.     Caption = "View/Modify Structure"
  411.     PrintButton.Visible = True
  412.     RemoveFieldButton.Visible = False
  413.     fTblStru.cTableName = fTables.cTableList
  414.     Set tbl = gCurrentDB.TableDefs(fTables.cTableList)
  415.     cFields.Rows = tbl.Fields.Count + 1
  416.     For i = 1 To cFields.Rows - 1
  417.       cFields.Row = i
  418.       cFields.Col = 0
  419.       cFields = tbl.Fields(i - 1).Name
  420.       cFields.Col = 1
  421.       Select Case tbl.Fields(i - 1).Type
  422.         Case FT_TRUEFALSE
  423.           s = "True/False"
  424.         Case FT_BYTE
  425.           s = "Byte"
  426.         Case FT_INTEGER
  427.           s = "Integer"
  428.         Case FT_LONG
  429.           If tbl.Fields(i - 1).Attributes And &H10 = &H10 Then
  430.             s = "Counter"
  431.           Else
  432.             s = "Long"
  433.           End If
  434.         Case FT_CURRENCY
  435.           s = "Currency"
  436.         Case FT_SINGLE
  437.           s = "Single"
  438.         Case FT_DOUBLE
  439.           s = "Double"
  440.         Case FT_DATETIME
  441.           s = "Date/Time"
  442.         Case 9
  443.           s = "Reserved/9"
  444.         Case FT_STRING
  445.           s = "String"
  446.         Case FT_BINARY
  447.           s = "Binary"
  448.         Case FT_MEMO
  449.           s = "Memo"
  450.         Case Else
  451.           s = CStr(tbl.Fields(i - 1).Type)
  452.       End Select
  453.       cFields = s
  454.       cFields.Col = 2
  455.       cFields = CStr(tbl.Fields(i - 1).Size)
  456.     Next
  457.     If tbl.Indexes.Count = 0 Then
  458.       cIndexes.Rows = 2
  459.     Else
  460.       cIndexes.Rows = tbl.Indexes.Count + 1
  461.       For i = 1 To cIndexes.Rows - 1
  462.         cIndexes.Row = i
  463.         cIndexes.Col = 0
  464.         cIndexes = tbl.Indexes(i - 1).Name
  465.         cIndexes.Col = 1
  466.         cIndexes = tbl.Indexes(i - 1).Fields
  467.         cIndexes.Col = 2
  468.         If tbl.Indexes(i - 1).Unique = False Then
  469.           s = "False"
  470.         Else
  471.           s = "True"
  472.         End If
  473.         cIndexes = s
  474.         cIndexes.Col = 3
  475.         If gstDataType = "ODBC" Then
  476.           s = "N/A"
  477.         Else
  478.           If tbl.Indexes(i - 1).Primary = False Then
  479.             s = "False"
  480.           Else
  481.             s = "True"
  482.           End If
  483.         End If
  484.         cIndexes = s
  485.       Next
  486.     End If
  487.   End If
  488.   'lock the titles row and set the selected cell
  489.   cFields.Row = 1
  490.   cFields.SelStartCol = 0
  491.   cFields.SelEndCol = 0
  492.   cFields.FixedRows = 1
  493.   cIndexes.Row = 1
  494.   cIndexes.SelStartCol = 0
  495.   cIndexes.SelEndCol = 0
  496.   cIndexes.FixedRows = 1
  497.   ResizeFieldGrid
  498.   GoTo LoadEnd
  499. LoadErr:
  500.   ResetMouse Me
  501.   fTables.MousePointer = DEFAULT_MOUSE
  502.   ShowError
  503.   Unload Me
  504.   MsgBar "", False
  505.   Exit Sub
  506.   Resume LoadEnd
  507. LoadEnd:
  508.   ResetMouse Me
  509.   fTables.MousePointer = DEFAULT_MOUSE
  510.   MsgBar "", False
  511.         
  512. End Sub
  513. Sub Form_Paint ()
  514.   Outlines Me
  515.   FieldBox.Refresh
  516.   PicOutlines FieldBox, cFields
  517.   IndexBox.Refresh
  518.   PicOutlines IndexBox, cIndexes
  519. End Sub
  520. Sub Form_Resize ()
  521.   On Error Resume Next
  522.   If WindowState <> 1 Then
  523.     If Width < 5190 Then
  524.       Width = 5190
  525.     End If
  526.     FieldBox.Width = Width' - 350
  527.     cFields.Width = FieldBox.Width - 350
  528.     IndexBox.Width = Width' - 350
  529.     cIndexes.Width = IndexBox.Width - 350
  530.     Line1.X2 = IndexBox.Width
  531.     Form_Paint
  532.   End If
  533. End Sub
  534. Sub PrintButton_Click ()
  535.   'this routine simply prints the currently
  536.   'selected table's definition
  537.   Dim i As Integer
  538.   Dim s As String
  539.   MsgBar "Printing Table Structure", True
  540.   Printer.Print
  541.   Printer.Print
  542.   Printer.Print
  543.   Printer.Print "DataBase: " + gstDBName
  544.   Printer.Print
  545.   Printer.Print
  546.   Printer.Print "Table Definition for " + cTableName
  547.   Printer.Print
  548.   Printer.Print
  549.   Printer.Print "Fields: (Name - Type - Size)"
  550.   Printer.Print String(60, "-")
  551.   For i = 1 To cFields.Rows - 1
  552.     cFields.Row = i
  553.     cFields.Col = 0
  554.     s = cFields + " - "
  555.     cFields.Col = 1
  556.     s = s + cFields + " - "
  557.     cFields.Col = 2
  558.     s = s + cFields
  559.     Printer.Print s
  560.   Next
  561.   Printer.Print
  562.   Printer.Print
  563.   Printer.Print "Index List (Name - Fields - Unique)"
  564.   Printer.Print String(60, "-")
  565.   For i = 1 To cIndexes.Rows - 1
  566.     cIndexes.Row = i
  567.     cIndexes.Col = 0
  568.     s = cIndexes + " - "
  569.     cIndexes.Col = 1
  570.     s = s + cIndexes + " - "
  571.     cIndexes.Col = 2
  572.     s = s + cIndexes
  573.     Printer.Print s
  574.   Next
  575.   Printer.NewPage
  576.   Printer.EndDoc
  577.   MsgBar "", False
  578. End Sub
  579. Sub RemoveFieldButton_Click ()
  580.   On Error GoTo RFErr
  581.   cFields.Row = cFields.SelStartRow
  582.   cFields.Col = 0
  583.   If cFields = "" Then Exit Sub
  584.   If MsgBox("Remove """ + cFields + """ field?", MSGBOX_TYPE) = YES Then
  585.     'refresh the list of indexes
  586.     If cFields.Rows = 2 Then
  587.       cFields.Col = 0
  588.       cFields = ""
  589.       cFields.Col = 1
  590.       cFields = ""
  591.       cFields.Col = 2
  592.       cFields = ""
  593.     Else
  594.       cFields.RemoveItem cFields.Row
  595.       ResizeFieldGrid
  596.     End If
  597.   End If
  598.   GoTo RFEnd
  599. RFErr:
  600.   ShowError
  601.   Resume RFEnd
  602. RFEnd:
  603. End Sub
  604. Sub ResizeFieldGrid ()
  605.   If cFields.Rows < 12 Then
  606.     cFields.Height = cFields.Rows * 245
  607.     FieldBox.Height = cFields.Height + 360
  608.     IndexBox.Top = FieldBox.Top + FieldBox.Height + 250
  609.     Height = IndexBox.Top + IndexBox.Height + 500
  610.   End If
  611. End Sub
  612.