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

  1. VERSION 2.00
  2. Begin Form fTblStru 
  3.    BackColor       =   &H00FFFF80&
  4.    ControlBox      =   0   'False
  5.    Height          =   5955
  6.    Icon            =   0
  7.    Left            =   2055
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    MinButton       =   0   'False
  11.    ScaleHeight     =   5550
  12.    ScaleWidth      =   5040
  13.    Top             =   1140
  14.    Width           =   5160
  15.    Begin TextBox cTableName 
  16.       Height          =   288
  17.       Left            =   1560
  18.       TabIndex        =   0
  19.       Top             =   120
  20.       Width           =   1932
  21.    End
  22.    Begin PictureBox IndexBox 
  23.       BackColor       =   &H00FFFF80&
  24.       BorderStyle     =   0  'None
  25.       Height          =   1692
  26.       Left            =   120
  27.       ScaleHeight     =   1695
  28.       ScaleWidth      =   4815
  29.       TabIndex        =   9
  30.       Top             =   3720
  31.       Width           =   4812
  32.       Begin CommandButton PrintButton 
  33.          Caption         =   "&Print Structure"
  34.          Height          =   375
  35.          Left            =   600
  36.          TabIndex        =   14
  37.          Top             =   1320
  38.          Visible         =   0   'False
  39.          Width           =   1455
  40.       End
  41.       Begin CommandButton AddTableButton 
  42.          Cancel          =   -1  'True
  43.          Caption         =   "&Build the Table"
  44.          Enabled         =   0   'False
  45.          Height          =   372
  46.          Left            =   600
  47.          TabIndex        =   8
  48.          Top             =   1320
  49.          Visible         =   0   'False
  50.          Width           =   1452
  51.       End
  52.       Begin CommandButton CloseButton 
  53.          Caption         =   "&Close"
  54.          Height          =   372
  55.          Left            =   2760
  56.          TabIndex        =   3
  57.          Top             =   1320
  58.          Width           =   1452
  59.       End
  60.       Begin CommandButton AddIndexButton 
  61.          Caption         =   "Add &Index"
  62.          Height          =   252
  63.          Left            =   1080
  64.          TabIndex        =   5
  65.          Top             =   120
  66.          Width           =   1332
  67.       End
  68.       Begin CommandButton DelIndexButton 
  69.          Caption         =   "&Delete Index"
  70.          Height          =   252
  71.          Left            =   2520
  72.          TabIndex        =   6
  73.          Top             =   120
  74.          Width           =   1332
  75.       End
  76.       Begin Grid cIndexes 
  77.          Cols            =   3
  78.          FixedCols       =   0
  79.          Height          =   708
  80.          Left            =   0
  81.          TabIndex        =   2
  82.          Top             =   396
  83.          Width           =   4812
  84.       End
  85.       Begin Line Line1 
  86.          BorderWidth     =   5
  87.          X1              =   0
  88.          X2              =   4800
  89.          Y1              =   0
  90.          Y2              =   0
  91.       End
  92.       Begin Label IndexesLabel 
  93.          BackColor       =   &H00FFFF80&
  94.          Caption         =   "Indexes:"
  95.          Height          =   252
  96.          Left            =   120
  97.          TabIndex        =   10
  98.          Top             =   120
  99.          Width           =   1092
  100.       End
  101.    End
  102.    Begin PictureBox FieldBox 
  103.       BackColor       =   &H00FFFF80&
  104.       BorderStyle     =   0  'None
  105.       Height          =   2892
  106.       Left            =   120
  107.       ScaleHeight     =   2895
  108.       ScaleWidth      =   4815
  109.       TabIndex        =   11
  110.       Top             =   600
  111.       Width           =   4812
  112.       Begin CommandButton RemoveFieldButton 
  113.          Caption         =   "&Remove Field"
  114.          Height          =   252
  115.          Left            =   2520
  116.          TabIndex        =   7
  117.          Top             =   0
  118.          Visible         =   0   'False
  119.          Width           =   1332
  120.       End
  121.       Begin CommandButton AddFieldButton 
  122.          Caption         =   "&Add Field"
  123.          Height          =   252
  124.          Left            =   1080
  125.          TabIndex        =   4
  126.          Top             =   0
  127.          Width           =   1332
  128.       End
  129.       Begin Grid cFields 
  130.          BackColor       =   &H00FFFFFF&
  131.          Cols            =   3
  132.          FixedCols       =   0
  133.          Height          =   2532
  134.          Left            =   0
  135.          TabIndex        =   1
  136.          Top             =   290
  137.          Width           =   4800
  138.       End
  139.       Begin Label FieldsLabel 
  140.          BackColor       =   &H00FFFF80&
  141.          Caption         =   "Fields:"
  142.          Height          =   252
  143.          Left            =   120
  144.          TabIndex        =   12
  145.          Top             =   0
  146.          Width           =   732
  147.       End
  148.    End
  149.    Begin Label TableNameLabel 
  150.       BackColor       =   &H00FFFF80&
  151.       Caption         =   "Table Name:"
  152.       Height          =   252
  153.       Left            =   360
  154.       TabIndex        =   13
  155.       Top             =   120
  156.       Width           =   1212
  157.    End
  158. Option Explicit
  159. Sub AddFieldButton_Click ()
  160.   MsgBar "Enter New Field Parameters, Press 'Close' when finished", False
  161.   fAddField.Show MODAL
  162.   MsgBar "", False
  163. End Sub
  164. Sub AddIndexButton_Click ()
  165.   MsgBar "Enter New Index Parameters, Press 'Close' when finished", False
  166.   fIndexAdd.Show MODAL
  167.   MsgBar "", False
  168. End Sub
  169. Sub AddTableButton_Click ()
  170.   Dim tbl As New TableDef
  171.   Dim fld As Field
  172.   Dim ind As Index
  173.   Dim i As Integer
  174.   Dim x As String
  175.   On Error GoTo ATErr
  176.   SetHourGlass Me
  177.   MsgBar "Building New Table", True
  178.   tbl.Name = cTableName
  179.   'search to see if table exists
  180.   For i = 0 To gCurrentDB.TableDefs.Count - 1
  181.     If UCase(gCurrentDB.TableDefs(i).Name) = UCase(tbl.Name) Then
  182.       If MsgBox(tbl.Name + " already exists, delete it?", 4) = YES Then
  183.          gCurrentDB.TableDefs.Delete gCurrentDB.TableDefs(tbl.Name)
  184.       Else
  185.          Exit Sub
  186.       End If
  187.       Exit For
  188.     End If
  189.   Next
  190.   'add the first field
  191.   cFields.Row = 1
  192.   cFields.Col = 0
  193.   If cFields = "" Then
  194.     Beep
  195.     MsgBox "No Fields Defined!", 48
  196.     Exit Sub
  197.   End If
  198.   Set fld = New Field
  199.   fld.Name = cFields
  200.   cFields.Col = 1
  201.   fld.Type = GetFieldType((cFields))
  202.   cFields.Col = 2
  203.   fld.Size = Val(cFields)
  204.   tbl.Fields.Append fld
  205.   gCurrentDB.TableDefs.Append tbl
  206.   'add the rest of the fields
  207.   For i = 2 To cFields.Rows - 1
  208.     Set fld = New Field
  209.     cFields.Row = i
  210.     cFields.Col = 0
  211.     fld.Name = cFields
  212.     cFields.Col = 1
  213.     fld.Type = GetFieldType((cFields))
  214.     cFields.Col = 2
  215.     fld.Size = Val(cFields)
  216.     gCurrentDB.TableDefs(tbl.Name).Fields.Append fld
  217.   Next
  218.   'add the indexes
  219.   For i = 1 To cIndexes.Rows - 1
  220.     Set ind = New Index
  221.     cIndexes.Row = i
  222.     cIndexes.Col = 0
  223.     If cIndexes = "" Then Exit For
  224.     ind.Name = cIndexes
  225.     cIndexes.Col = 1
  226.     ind.Fields = cIndexes
  227.     cIndexes.Col = 2
  228.     If cIndexes = "True" Then
  229.       ind.Unique = True
  230.     Else
  231.       ind.Unique = False
  232.     End If
  233.     gCurrentDB.TableDefs(tbl.Name).Indexes.Append ind
  234.   Next
  235.   fTables.cTableList.AddItem tbl.Name
  236.   Unload Me
  237.   GoTo ATEnd
  238. ATErr:
  239.   ResetMouse Me
  240.   ShowError
  241.   Resume ATEnd
  242. ATEnd:
  243.   ResetMouse Me
  244.   MsgBar "", False
  245. End Sub
  246. Sub CloseButton_Click ()
  247.   Unload Me
  248.   MsgBar "", False
  249. End Sub
  250. Sub cTableName_Change ()
  251.   If cTableName = "" Then
  252.     AddTableButton.Enabled = False
  253.   Else
  254.     AddTableButton.Enabled = True
  255.   End If
  256. End Sub
  257. Sub DelIndexButton_Click ()
  258.   cIndexes.Row = cIndexes.SelStartRow
  259.   cIndexes.Col = 0
  260.   If cIndexes = "" Then Exit Sub
  261.   If MsgBox("Delete """ + cIndexes + """ index?", MSGBOX_TYPE) = YES Then
  262.     If gfAddTableFlag = False Then
  263.       gCurrentDB.TableDefs(fTables.cTableList).Indexes.Delete gCurrentDB.TableDefs(fTables.cTableList).Indexes(cIndexes)
  264.     End If
  265.     'refresh the list of indexes
  266.     If cIndexes.Rows = 2 Then
  267.       cIndexes.Col = 0
  268.       cIndexes = ""
  269.       cIndexes.Col = 1
  270.       cIndexes = ""
  271.       cIndexes.Col = 2
  272.       cIndexes = ""
  273.     Else
  274.       cIndexes.RemoveItem cIndexes.Row
  275.     End If
  276.   End If
  277. End Sub
  278. Sub Form_Load ()
  279.   Dim tbl As TableDef
  280.   Dim i As Integer
  281.   Dim s As String
  282.   MsgBar "Opening Design Form", True
  283.   'setup field grid titles
  284.   cFields.ColWidth(0) = 2500
  285.   cFields.ColWidth(1) = 1500
  286.   cFields.ColWidth(2) = 500
  287.   cFields.Row = 0
  288.   cFields.Col = 0
  289.   cFields = "Name"
  290.   cFields.Col = 1
  291.   cFields = "Type"
  292.   cFields.Col = 2
  293.   cFields = "Size"
  294.   'setup index grid titles
  295.   cIndexes.ColWidth(0) = 850
  296.   cIndexes.ColWidth(1) = 3012
  297.   cIndexes.ColWidth(2) = 650
  298.   cIndexes.Row = 0
  299.   cIndexes.Col = 0
  300.   cIndexes = "Name"
  301.   cIndexes.Col = 1
  302.   cIndexes = "Indexed Fields"
  303.   cIndexes.Col = 2
  304.   cIndexes = "Unique"
  305.   If gfAddTableFlag = True Then
  306.     Caption = "Add Table"
  307.     AddTableButton.Visible = True
  308.     RemoveFieldButton.Visible = True
  309.     cFields.Rows = 2
  310.     cIndexes.Rows = 2
  311.   Else
  312.     Caption = "View/Modify Structure"
  313.     PrintButton.Visible = True
  314.     fTblStru.cTableName = fTables.cTableList
  315.     'view / modify
  316.     Set tbl = gCurrentDB.TableDefs(fTables.cTableList)
  317.     tbl.Fields.Refresh
  318.     tbl.Indexes.Refresh
  319.     cFields.Rows = tbl.Fields.Count + 1
  320.     For i = 1 To cFields.Rows - 1
  321.       cFields.Row = i
  322.       cFields.Col = 0
  323.       cFields = tbl.Fields(i - 1).Name
  324.       cFields.Col = 1
  325.       Select Case tbl.Fields(i - 1).Type
  326.         Case FT_TRUEFALSE
  327.           s = "True/False"
  328.         Case FT_BYTE
  329.           s = "Byte"
  330.         Case FT_INTEGER
  331.           s = "Integer"
  332.         Case FT_LONG
  333.           s = "Long"
  334.         Case FT_CURRENCY
  335.           s = "Currency"
  336.         Case FT_SINGLE
  337.           s = "Single"
  338.         Case FT_DOUBLE
  339.           s = "Double"
  340.         Case FT_DATETIME
  341.           s = "Date/Time"
  342.         Case 9
  343.           s = "Reserved/9"
  344.         Case FT_STRING
  345.           s = "String"
  346.         Case 11
  347.           s = "Reserved/11"
  348.         Case FT_MEMO
  349.           s = "Memo"
  350.         Case Else
  351.           s = CStr(tbl.Fields(i - 1).Type)
  352.       End Select
  353.       cFields = s
  354.       cFields.Col = 2
  355.       cFields = CStr(tbl.Fields(i - 1).Size)
  356.     Next
  357.     If tbl.Indexes.Count = 0 Then
  358.       cIndexes.Rows = 2
  359.     Else
  360.       cIndexes.Rows = tbl.Indexes.Count + 1
  361.       For i = 1 To cIndexes.Rows - 1
  362.         cIndexes.Row = i
  363.         cIndexes.Col = 0
  364.         cIndexes = tbl.Indexes(i - 1).Name
  365.         cIndexes.Col = 1
  366.         cIndexes = tbl.Indexes(i - 1).Fields
  367.         cIndexes.Col = 2
  368.         If tbl.Indexes(i - 1).Unique = False Then
  369.           s = "False"
  370.         Else
  371.           s = "True"
  372.         End If
  373.         cIndexes = s
  374.       Next
  375.     End If
  376.   End If
  377.   'lock the titles row and set the selected cell
  378.   cFields.Row = 1
  379.   cFields.SelStartCol = 0
  380.   cFields.SelEndCol = 0
  381.   cFields.FixedRows = 1
  382.   cIndexes.Row = 1
  383.   cIndexes.SelStartCol = 0
  384.   cIndexes.SelEndCol = 0
  385.   cIndexes.FixedRows = 1
  386.   ResizeFieldGrid
  387.   MsgBar "", False
  388. End Sub
  389. Sub Form_Resize ()
  390.   If WindowState <> 1 Then
  391.     If Width < 5190 Then
  392.       Width = 5190
  393.     End If
  394.     FieldBox.Width = Width - 350
  395.     cFields.Width = FieldBox.Width
  396.     IndexBox.Width = Width - 350
  397.     cIndexes.Width = IndexBox.Width
  398.   End If
  399. End Sub
  400. Sub PrintButton_Click ()
  401.   'this routine simply prints the currently
  402.   'selected table's definition
  403.   Dim i As Integer
  404.   Dim s As String
  405.   MsgBar "Printing Table Structure", True
  406.   Printer.Print
  407.   Printer.Print
  408.   Printer.Print
  409.   Printer.Print "DataBase: " + gstDBName
  410.   Printer.Print
  411.   Printer.Print
  412.   Printer.Print "Table Definition for " + cTableName
  413.   Printer.Print
  414.   Printer.Print
  415.   Printer.Print "Fields: (Name - Type - Size)"
  416.   Printer.Print String(60, "-")
  417.   For i = 1 To cFields.Rows - 1
  418.     cFields.Row = i
  419.     cFields.Col = 0
  420.     s = cFields + " - "
  421.     cFields.Col = 1
  422.     s = s + cFields + " - "
  423.     cFields.Col = 2
  424.     s = s + cFields
  425.     Printer.Print s
  426.   Next
  427.   Printer.Print
  428.   Printer.Print
  429.   Printer.Print "Index List (Name - Fields - Unique)"
  430.   Printer.Print String(60, "-")
  431.   For i = 1 To cIndexes.Rows - 1
  432.     cIndexes.Row = i
  433.     cIndexes.Col = 0
  434.     s = cIndexes + " - "
  435.     cIndexes.Col = 1
  436.     s = s + cIndexes + " - "
  437.     cIndexes.Col = 2
  438.     s = s + cIndexes
  439.     Printer.Print s
  440.   Next
  441.   Printer.NewPage
  442.   Printer.EndDoc
  443.   MsgBar "", False
  444. End Sub
  445. Sub RemoveFieldButton_Click ()
  446.   cFields.Row = cFields.SelStartRow
  447.   cFields.Col = 0
  448.   If cFields = "" Then Exit Sub
  449.   If MsgBox("Remove """ + cFields + """ field?", MSGBOX_TYPE) = YES Then
  450.     'refresh the list of indexes
  451.     If cFields.Rows = 2 Then
  452.       cFields.Col = 0
  453.       cFields = ""
  454.       cFields.Col = 1
  455.       cFields = ""
  456.       cFields.Col = 2
  457.       cFields = ""
  458.     Else
  459.       cFields.RemoveItem cFields.Row
  460.       ResizeFieldGrid
  461.     End If
  462.   End If
  463. End Sub
  464. Sub ResizeFieldGrid ()
  465.   If cFields.Rows < 12 Then
  466.     cFields.Height = cFields.Rows * 232
  467.     FieldBox.Height = cFields.Height + 360
  468.     IndexBox.Top = FieldBox.Top + FieldBox.Height + 250
  469.     Height = IndexBox.Top + IndexBox.Height + 500
  470.   End If
  471. End Sub
  472.