home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / addfield.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  11.4 KB  |  377 lines

  1. VERSION 4.00
  2. Begin VB.Form frmAddField 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Add Field"
  5.    ClientHeight    =   3735
  6.    ClientLeft      =   1365
  7.    ClientTop       =   1290
  8.    ClientWidth     =   6120
  9.    Height          =   4140
  10.    HelpContextID   =   2016117
  11.    Icon            =   "ADDFIELD.frx":0000
  12.    Left            =   1305
  13.    LinkTopic       =   "Form1"
  14.    LockControls    =   -1  'True
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   3707.738
  18.    ScaleMode       =   0  'User
  19.    ScaleWidth      =   6173.218
  20.    Top             =   945
  21.    Width           =   6240
  22.    Begin VB.OptionButton optVariable 
  23.       Caption         =   "VariableField"
  24.       Height          =   255
  25.       Left            =   240
  26.       TabIndex        =   4
  27.       Top             =   2160
  28.       Value           =   -1  'True
  29.       Width           =   2379
  30.    End
  31.    Begin VB.OptionButton optFixedField 
  32.       Caption         =   "FixedField"
  33.       Height          =   255
  34.       Left            =   240
  35.       TabIndex        =   3
  36.       Top             =   1920
  37.       Width           =   2379
  38.    End
  39.    Begin VB.CheckBox chkAutoInc 
  40.       Caption         =   "AutoIncrField"
  41.       Height          =   255
  42.       Left            =   240
  43.       TabIndex        =   5
  44.       TabStop         =   0   'False
  45.       Top             =   2640
  46.       Width           =   2379
  47.    End
  48.    Begin VB.CheckBox chkAllowZeroLen 
  49.       Caption         =   "AllowZeroLength"
  50.       Height          =   255
  51.       Left            =   240
  52.       TabIndex        =   6
  53.       Top             =   3000
  54.       Width           =   2379
  55.    End
  56.    Begin VB.TextBox txtFieldName 
  57.       Height          =   285
  58.       Left            =   120
  59.       TabIndex        =   0
  60.       Top             =   360
  61.       Width           =   2895
  62.    End
  63.    Begin VB.ComboBox cboFieldType 
  64.       Height          =   300
  65.       ItemData        =   "ADDFIELD.frx":030A
  66.       Left            =   120
  67.       List            =   "ADDFIELD.frx":0332
  68.       Style           =   2  'Dropdown List
  69.       TabIndex        =   1
  70.       Top             =   960
  71.       Width           =   1695
  72.    End
  73.    Begin VB.TextBox txtFieldSize 
  74.       Height          =   285
  75.       Left            =   120
  76.       TabIndex        =   2
  77.       Top             =   1560
  78.       Width           =   1335
  79.    End
  80.    Begin VB.TextBox txtOrdinalPos 
  81.       Height          =   285
  82.       Left            =   3120
  83.       TabIndex        =   8
  84.       Top             =   360
  85.       Width           =   1335
  86.    End
  87.    Begin VB.TextBox txtValidationText 
  88.       Height          =   285
  89.       Left            =   3120
  90.       TabIndex        =   9
  91.       Top             =   960
  92.       Width           =   2895
  93.    End
  94.    Begin VB.TextBox txtValidationRule 
  95.       Height          =   285
  96.       Left            =   3120
  97.       TabIndex        =   10
  98.       Top             =   1680
  99.       Width           =   2895
  100.    End
  101.    Begin VB.TextBox txtDefaultValue 
  102.       Height          =   285
  103.       Left            =   3120
  104.       TabIndex        =   11
  105.       Top             =   2280
  106.       Width           =   2895
  107.    End
  108.    Begin VB.CheckBox chkRequired 
  109.       Caption         =   "Required"
  110.       Height          =   255
  111.       Left            =   240
  112.       TabIndex        =   7
  113.       Top             =   3360
  114.       Width           =   2379
  115.    End
  116.    Begin VB.CommandButton cmdOK 
  117.       Caption         =   "&OK"
  118.       Default         =   -1  'True
  119.       Enabled         =   0   'False
  120.       Height          =   375
  121.       Left            =   3480
  122.       TabIndex        =   12
  123.       Top             =   2760
  124.       Width           =   2175
  125.    End
  126.    Begin VB.CommandButton cmdCancel 
  127.       Cancel          =   -1  'True
  128.       Caption         =   "&Close"
  129.       Height          =   375
  130.       Left            =   3480
  131.       TabIndex        =   13
  132.       Top             =   3240
  133.       Width           =   2175
  134.    End
  135.    Begin VB.Label lblLabels 
  136.       AutoSize        =   -1  'True
  137.       Caption         =   " Name: "
  138.       Height          =   195
  139.       Index           =   1
  140.       Left            =   120
  141.       TabIndex        =   20
  142.       Top             =   120
  143.       Width           =   555
  144.    End
  145.    Begin VB.Label lblLabels 
  146.       AutoSize        =   -1  'True
  147.       Caption         =   " Type: "
  148.       Height          =   195
  149.       Index           =   4
  150.       Left            =   120
  151.       TabIndex        =   19
  152.       Top             =   720
  153.       Width           =   495
  154.    End
  155.    Begin VB.Label lblLabels 
  156.       AutoSize        =   -1  'True
  157.       Caption         =   " Size: "
  158.       Height          =   195
  159.       Index           =   5
  160.       Left            =   120
  161.       TabIndex        =   18
  162.       Top             =   1320
  163.       Width           =   435
  164.    End
  165.    Begin VB.Label lblLabels 
  166.       AutoSize        =   -1  'True
  167.       Caption         =   "OrdinalPosition: "
  168.       Height          =   195
  169.       Index           =   7
  170.       Left            =   3120
  171.       TabIndex        =   17
  172.       Top             =   120
  173.       Width           =   1140
  174.    End
  175.    Begin VB.Label lblLabels 
  176.       AutoSize        =   -1  'True
  177.       Caption         =   "ValidationText: "
  178.       Height          =   195
  179.       Index           =   8
  180.       Left            =   3120
  181.       TabIndex        =   16
  182.       Top             =   720
  183.       Width           =   1095
  184.    End
  185.    Begin VB.Label lblLabels 
  186.       AutoSize        =   -1  'True
  187.       Caption         =   "ValidationRule: "
  188.       Height          =   195
  189.       Index           =   9
  190.       Left            =   3120
  191.       TabIndex        =   15
  192.       Top             =   1320
  193.       Width           =   1110
  194.    End
  195.    Begin VB.Label lblLabels 
  196.       AutoSize        =   -1  'True
  197.       Caption         =   "DefaultValue: "
  198.       Height          =   195
  199.       Index           =   10
  200.       Left            =   3120
  201.       TabIndex        =   14
  202.       Top             =   2040
  203.       Width           =   1005
  204.    End
  205. Attribute VB_Name = "frmAddField"
  206. Attribute VB_Creatable = False
  207. Attribute VB_Exposed = False
  208. Option Explicit
  209. Private Sub cmdCancel_Click()
  210.   Unload Me
  211. End Sub
  212. Sub Form_Load()
  213.   CenterMe Me, gnMDIFORM
  214.   SetDefaults
  215.   'need to disable controls that don't apply
  216.   'to non Jet tables
  217.   If gsDataType <> gsJETMDB Then
  218.     optFixedField.Enabled = False
  219.     chkAutoInc.Enabled = False
  220.     optVariable.Enabled = False
  221.     txtValidationText.Enabled = False
  222.     txtValidationRule.Enabled = False
  223.     txtDefaultValue.Enabled = False
  224.     chkRequired.Enabled = False
  225.     chkAllowZeroLen.Enabled = False
  226.   End If
  227. End Sub
  228. Private Sub txtFieldName_Change()
  229.   'activate the ok button only if the
  230.   'name field has something in it
  231.   If Len(txtFieldName.Text) > 0 Then
  232.     cmdOK.Enabled = True
  233.   Else
  234.     cmdOK.Enabled = False
  235.   End If
  236. End Sub
  237. Private Sub cboFieldType_Click()
  238.   Dim nFldType As Integer
  239.   'call function to set size and type of field
  240.   txtFieldSize.Text = SetFldProperties(cboFieldType.ItemData(cboFieldType.ListIndex))
  241.   txtFieldSize.Enabled = False
  242.   nFldType = cboFieldType.ItemData(cboFieldType.ListIndex)
  243.   'enable appropriate controls for each field type
  244.   If gsDataType <> gsJETMDB Then
  245.     If nFldType = dbText Then
  246.       'allow entry of field length
  247.       txtFieldSize.Enabled = True
  248.       'default field size from Access UI
  249.       txtFieldSize.Text = "50"
  250.     End If
  251.     'only do the stuff below for MDB dbs
  252.     Exit Sub
  253.   End If
  254.   If nFldType = dbText Then
  255.     'allow entry of field length
  256.     txtFieldSize.Enabled = True
  257.     'default field size from Access UI
  258.     txtFieldSize.Text = "50"
  259.     'avaiable for memo and text
  260.     chkAllowZeroLen.Enabled = True
  261.     'avaiable for text only
  262.     optVariable.Enabled = True
  263.     optFixedField.Enabled = True
  264.     'disable these controls
  265.     chkAutoInc.Enabled = False
  266.     chkAutoInc.Value = 0
  267.   ElseIf nFldType = dbMemo Then
  268.     'avaiable for memo and text
  269.     chkAllowZeroLen.Enabled = True
  270.     'disable these controls
  271.     optVariable.Enabled = False
  272.     optFixedField.Enabled = False
  273.     chkAutoInc.Enabled = False
  274.     'set the value to 0
  275.     optVariable.Value = False
  276.     optFixedField.Value = False
  277.     chkAutoInc.Value = 0
  278.   ElseIf nFldType = dbLong Then
  279.     'enable this one for counter type fields
  280.     chkAutoInc.Enabled = True
  281.     'disable these controls
  282.     chkAllowZeroLen.Enabled = False
  283.     optVariable.Enabled = False
  284.     optFixedField.Enabled = False
  285.     'set the value to 0
  286.     chkAllowZeroLen.Value = 0
  287.     optVariable.Value = False
  288.     optFixedField.Value = False
  289.   Else
  290.     'disable these for all other types
  291.     chkAllowZeroLen.Enabled = False
  292.     optVariable.Enabled = False
  293.     optFixedField.Enabled = False
  294.     chkAutoInc.Enabled = False
  295.     'set the value to 0
  296.     chkAllowZeroLen.Value = 0
  297.     optVariable.Value = False
  298.     optFixedField.Value = False
  299.     chkAutoInc.Value = 0
  300.   End If
  301. End Sub
  302. Private Sub cmdOK_Click()
  303.   On Error GoTo OkayErr
  304.   Dim fld As Field     'local field structure
  305.   Dim i As Integer
  306.   'get a fresh field object
  307.   Set fld = gtdfTableDef.CreateField()
  308.   'fill the field structure
  309.   With fld
  310.     .Name = txtFieldName.Text
  311.     .Type = cboFieldType.ItemData(cboFieldType.ListIndex)
  312.     .Size = txtFieldSize.Text
  313.     If Len(txtOrdinalPos.Text) > 0 Then .OrdinalPosition = txtOrdinalPos.Text
  314.     If gsDataType = gsJETMDB Then
  315.       .Required = IIf(chkRequired.Value = 1, -1, 0)
  316.       If .Type = dbText Then
  317.         'this only applies to text
  318.         .AllowZeroLength = IIf(chkAllowZeroLen.Value = 1, -1, 0)
  319.       End If
  320.       If optFixedField.Value = True Then
  321.         .Attributes = .Attributes Or dbFixedField
  322.       End If
  323.       If .Type = dbLong Then
  324.         'only applies to long type
  325.         If chkAutoInc.Value = 1 Then
  326.           .Attributes = .Attributes Or dbAutoIncrField
  327.         End If
  328.       End If
  329.       If optVariable.Value = True Then
  330.         .Attributes = .Attributes Or dbVariableField
  331.       End If
  332.       .ValidationText = txtValidationText.Text
  333.       .ValidationRule = txtValidationRule.Text
  334.       .DefaultValue = txtDefaultValue.Text
  335.     End If
  336.   End With
  337.   'try to append the field
  338.   gtdfTableDef.Fields.Append fld
  339.   'must've been successful, so...
  340.   'add the item to the list
  341.   frmTblStruct.lstFields.AddItem txtFieldName
  342.   'make the new item active
  343.   frmTblStruct.lstFields.ListIndex = frmTblStruct.lstFields.NewIndex
  344.   'enable the add table button if needed
  345.   If frmTblStruct.cmdAddTable.Visible = True Then
  346.     frmTblStruct.cmdAddTable.Enabled = True
  347.   End If
  348.   'clear the name and allow entry of another
  349.   SetDefaults
  350.   txtFieldName.SetFocus
  351.   Exit Sub
  352. OkayErr:
  353.   ShowError
  354.   Exit Sub
  355. End Sub
  356. Private Sub SetDefaults()
  357.   txtFieldName.Text = gsNULL_STR
  358.   If gsDataType = gsJETMDB Then
  359.     optFixedField.Value = False
  360.     chkAutoInc.Value = 0
  361.     optVariable.Value = True
  362.     chkRequired.Value = 0
  363.     chkAllowZeroLen.Value = 1
  364.   Else
  365.     optFixedField.Value = False
  366.     chkAutoInc.Value = 2
  367.     optVariable.Value = False
  368.     chkRequired.Value = 2
  369.     chkAllowZeroLen.Value = 2
  370.   End If
  371.   cboFieldType.ListIndex = 8             'default to text
  372.   txtFieldSize.Text = 50                 'default to 50
  373.   txtValidationText.Text = gsNULL_STR
  374.   txtValidationRule.Text = gsNULL_STR
  375.   txtDefaultValue.Text = gsNULL_STR
  376. End Sub
  377.