home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / SAMPLES / VISDATA / ADDFIELD.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-01-11  |  12.9 KB  |  418 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAddField 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "
  5.    ClientHeight    =   3735
  6.    ClientLeft      =   2490
  7.    ClientTop       =   2865
  8.    ClientWidth     =   6120
  9.    HelpContextID   =   2016117
  10.    Icon            =   "ADDFIELD.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    LockControls    =   -1  'True
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3297.239
  16.    ScaleMode       =   0  'User
  17.    ScaleWidth      =   6054.501
  18.    ShowInTaskbar   =   0   'False
  19.    StartUpPosition =   1  'CenterOwner
  20.    Begin VB.OptionButton optVariable 
  21.       Caption         =   "
  22.       Height          =   255
  23.       Left            =   240
  24.       MaskColor       =   &H00000000&
  25.       TabIndex        =   4
  26.       Top             =   2160
  27.       Value           =   -1  'True
  28.       Width           =   2379
  29.    End
  30.    Begin VB.OptionButton optFixedField 
  31.       Caption         =   "
  32.       Height          =   255
  33.       Left            =   240
  34.       MaskColor       =   &H00000000&
  35.       TabIndex        =   3
  36.       Top             =   1920
  37.       Width           =   2379
  38.    End
  39.    Begin VB.CheckBox chkAutoInc 
  40.       Caption         =   "
  41.       Height          =   255
  42.       Left            =   240
  43.       MaskColor       =   &H00000000&
  44.       TabIndex        =   5
  45.       TabStop         =   0   'False
  46.       Top             =   2640
  47.       Width           =   2379
  48.    End
  49.    Begin VB.CheckBox chkAllowZeroLen 
  50.       Caption         =   "
  51.       Height          =   255
  52.       Left            =   240
  53.       MaskColor       =   &H00000000&
  54.       TabIndex        =   6
  55.       Top             =   3000
  56.       Width           =   2379
  57.    End
  58.    Begin VB.TextBox txtFieldName 
  59.       Height          =   285
  60.       Left            =   120
  61.       TabIndex        =   0
  62.       Top             =   360
  63.       Width           =   2895
  64.    End
  65.    Begin VB.ComboBox cboFieldType 
  66.       Height          =   315
  67.       ItemData        =   "ADDFIELD.frx":030A
  68.       Left            =   120
  69.       List            =   "ADDFIELD.frx":030C
  70.       Style           =   2  'Dropdown List
  71.       TabIndex        =   1
  72.       Top             =   960
  73.       Width           =   1695
  74.    End
  75.    Begin VB.TextBox txtFieldSize 
  76.       Height          =   285
  77.       Left            =   120
  78.       TabIndex        =   2
  79.       Top             =   1560
  80.       Width           =   1335
  81.    End
  82.    Begin VB.TextBox txtOrdinalPos 
  83.       Height          =   285
  84.       Left            =   3120
  85.       TabIndex        =   8
  86.       Top             =   360
  87.       Width           =   1335
  88.    End
  89.    Begin VB.TextBox txtValidationText 
  90.       Height          =   285
  91.       Left            =   3120
  92.       TabIndex        =   9
  93.       Top             =   960
  94.       Width           =   2895
  95.    End
  96.    Begin VB.TextBox txtValidationRule 
  97.       Height          =   285
  98.       Left            =   3120
  99.       TabIndex        =   10
  100.       Top             =   1680
  101.       Width           =   2895
  102.    End
  103.    Begin VB.TextBox txtDefaultValue 
  104.       Height          =   285
  105.       Left            =   3120
  106.       TabIndex        =   11
  107.       Top             =   2280
  108.       Width           =   2895
  109.    End
  110.    Begin VB.CheckBox chkRequired 
  111.       Caption         =   "
  112.       Height          =   255
  113.       Left            =   240
  114.       MaskColor       =   &H00000000&
  115.       TabIndex        =   7
  116.       Top             =   3360
  117.       Width           =   2379
  118.    End
  119.    Begin VB.CommandButton cmdOK 
  120.       Caption         =   "
  121. (&O)"
  122.       Default         =   -1  'True
  123.       Enabled         =   0   'False
  124.       Height          =   375
  125.       Left            =   3480
  126.       MaskColor       =   &H00000000&
  127.       TabIndex        =   12
  128.       Top             =   2760
  129.       Width           =   2175
  130.    End
  131.    Begin VB.CommandButton cmdClose 
  132.       Cancel          =   -1  'True
  133.       Caption         =   "
  134. (&C)"
  135.       Height          =   375
  136.       Left            =   3480
  137.       MaskColor       =   &H00000000&
  138.       TabIndex        =   13
  139.       Top             =   3240
  140.       Width           =   2175
  141.    End
  142.    Begin VB.Label lblLabels 
  143.       AutoSize        =   -1  'True
  144.       Caption         =   "
  145.       Height          =   195
  146.       Index           =   0
  147.       Left            =   120
  148.       TabIndex        =   20
  149.       Top             =   120
  150.       Width           =   555
  151.    End
  152.    Begin VB.Label lblLabels 
  153.       AutoSize        =   -1  'True
  154.       Caption         =   "
  155.       Height          =   195
  156.       Index           =   2
  157.       Left            =   120
  158.       TabIndex        =   19
  159.       Top             =   720
  160.       Width           =   510
  161.    End
  162.    Begin VB.Label lblLabels 
  163.       AutoSize        =   -1  'True
  164.       Caption         =   "
  165.       Height          =   195
  166.       Index           =   3
  167.       Left            =   120
  168.       TabIndex        =   18
  169.       Top             =   1320
  170.       Width           =   435
  171.    End
  172.    Begin VB.Label lblLabels 
  173.       AutoSize        =   -1  'True
  174.       Caption         =   "
  175.       Height          =   195
  176.       Index           =   4
  177.       Left            =   3120
  178.       TabIndex        =   17
  179.       Top             =   120
  180.       Width           =   1170
  181.    End
  182.    Begin VB.Label lblLabels 
  183.       AutoSize        =   -1  'True
  184.       Caption         =   "
  185.       Height          =   195
  186.       Index           =   5
  187.       Left            =   3120
  188.       TabIndex        =   16
  189.       Top             =   720
  190.       Width           =   1125
  191.    End
  192.    Begin VB.Label lblLabels 
  193.       AutoSize        =   -1  'True
  194.       Caption         =   "
  195.       Height          =   195
  196.       Index           =   6
  197.       Left            =   3120
  198.       TabIndex        =   15
  199.       Top             =   1320
  200.       Width           =   1110
  201.    End
  202.    Begin VB.Label lblLabels 
  203.       AutoSize        =   -1  'True
  204.       Caption         =   "
  205.       Height          =   195
  206.       Index           =   7
  207.       Left            =   3120
  208.       TabIndex        =   14
  209.       Top             =   2040
  210.       Width           =   1020
  211.    End
  212. Attribute VB_Name = "frmAddField"
  213. Attribute VB_GlobalNameSpace = False
  214. Attribute VB_Creatable = False
  215. Attribute VB_PredeclaredId = True
  216. Attribute VB_Exposed = False
  217. Option Explicit
  218. '>>>>>>>>>>>>>>>>>>>>>>>>
  219. Const FORMCAPTION = "
  220. Const BUTTON1 = "
  221. (&O)"
  222. Const BUTTON2 = "
  223. (&C)"
  224. Const MSG1 = "
  225. '>>>>>>>>>>>>>>>>>>>>>>>>
  226. Private Sub cmdClose_Click()
  227.   Unload Me
  228. End Sub
  229. Sub Form_Load()
  230.   Me.Caption = FORMCAPTION
  231.   cmdOK.Caption = BUTTON1
  232.   cmdClose.Caption = BUTTON2
  233.   cboFieldType.AddItem "Boolean"
  234.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbBoolean
  235.   cboFieldType.AddItem "Byte"
  236.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbByte
  237.   cboFieldType.AddItem "Integer"
  238.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbInteger
  239.   cboFieldType.AddItem "Long"
  240.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbLong
  241.   cboFieldType.AddItem "Currency"
  242.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbCurrency
  243.   cboFieldType.AddItem "Single"
  244.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbSingle
  245.   cboFieldType.AddItem "Double"
  246.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbDouble
  247.   cboFieldType.AddItem "Date/Time"
  248.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbDate
  249.   cboFieldType.AddItem "Text"
  250.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbText
  251.   cboFieldType.AddItem "Binary"
  252.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbLongBinary
  253.   cboFieldType.AddItem "Memo"
  254.   cboFieldType.ItemData(cboFieldType.NewIndex) = dbMemo
  255.   SetDefaults
  256.  Microsoft Access 
  257.   If gsDataType <> gsMSACCESS Then
  258.     optFixedField.Enabled = False
  259.     chkAutoInc.Enabled = False
  260.     optVariable.Enabled = False
  261.     txtValidationText.Enabled = False
  262.     txtValidationRule.Enabled = False
  263.     txtDefaultValue.Enabled = False
  264.     chkRequired.Enabled = False
  265.     chkAllowZeroLen.Enabled = False
  266.   End If
  267. End Sub
  268. Private Sub txtFieldName_Change()
  269.   cmdOK.Enabled = (Len(txtFieldName.Text) > 0)
  270. End Sub
  271. Private Sub cboFieldType_Click()
  272.   Dim nFldType As Integer
  273.   txtFieldSize.Text = SetFldProperties(cboFieldType.ItemData(cboFieldType.ListIndex))
  274.   txtFieldSize.Enabled = False
  275.   nFldType = cboFieldType.ItemData(cboFieldType.ListIndex)
  276.   If gsDataType <> gsMSACCESS Then
  277.     If nFldType = dbText Then
  278.       '
  279.       txtFieldSize.Enabled = True
  280.       'Access UI 
  281.       txtFieldSize.Text = "50"
  282.     End If
  283.     '
  284.  MDB 
  285.     Exit Sub
  286.   End If
  287.   If nFldType = dbText Then
  288.     '
  289.     txtFieldSize.Enabled = True
  290.     'Access UI 
  291.     txtFieldSize.Text = "50"
  292.     '
  293.  memo 
  294.  text 
  295.     chkAllowZeroLen.Enabled = True
  296.     '
  297.  text 
  298.     optVariable.Enabled = True
  299.     optFixedField.Enabled = True
  300.     '
  301.     chkAutoInc.Enabled = False
  302.     chkAutoInc.Value = vbUnchecked
  303.   ElseIf nFldType = dbMemo Then
  304.     '
  305.  memo 
  306.  text 
  307.     chkAllowZeroLen.Enabled = True
  308.     '
  309.     optVariable.Enabled = False
  310.     optFixedField.Enabled = False
  311.     chkAutoInc.Enabled = False
  312.     'value 
  313.     optVariable.Value = False
  314.     optFixedField.Value = False
  315.     chkAutoInc.Value = vbUnchecked
  316.   ElseIf nFldType = dbLong Then
  317.     '
  318.     chkAutoInc.Enabled = True
  319.     '
  320.     chkAllowZeroLen.Enabled = False
  321.     optVariable.Enabled = False
  322.     optFixedField.Enabled = False
  323.     'value 
  324.     chkAllowZeroLen.Value = vbUnchecked
  325.     optVariable.Value = False
  326.     optFixedField.Value = False
  327.   Else
  328.     '
  329.     chkAllowZeroLen.Enabled = False
  330.     optVariable.Enabled = False
  331.     optFixedField.Enabled = False
  332.     chkAutoInc.Enabled = False
  333.     'value 
  334.     chkAllowZeroLen.Value = vbUnchecked
  335.     optVariable.Value = False
  336.     optFixedField.Value = False
  337.     chkAutoInc.Value = vbUnchecked
  338.   End If
  339. End Sub
  340. Private Sub cmdOK_Click()
  341.   On Error GoTo OkayErr
  342.   Dim fld As Field     '
  343.   Dim i As Integer
  344. field
  345.   Set fld = gtdfTableDef.CreateField()
  346.   With fld
  347.     .Name = txtFieldName.Text
  348.     .Type = cboFieldType.ItemData(cboFieldType.ListIndex)
  349.     .Size = txtFieldSize.Text
  350.     If Len(txtOrdinalPos.Text) > 0 Then .OrdinalPosition = txtOrdinalPos.Text
  351.     If gsDataType = gsMSACCESS Then
  352.       .Required = IIf(chkRequired.Value = vbChecked, -1, 0)
  353.       If .Type = dbText Then
  354.         '
  355.  text
  356.         .AllowZeroLength = IIf(chkAllowZeroLen.Value = vbChecked, -1, 0)
  357.       End If
  358.       If optFixedField.Value Then
  359.         .Attributes = .Attributes Or dbFixedField
  360.       End If
  361.       If .Type = dbLong Then
  362.         '
  363.  long 
  364.         If chkAutoInc.Value = vbChecked Then
  365.           .Attributes = .Attributes Or dbAutoIncrField
  366.         End If
  367.       End If
  368.       If optVariable.Value Then
  369.         .Attributes = .Attributes Or dbVariableField
  370.       End If
  371.       .ValidationText = txtValidationText.Text
  372.       .ValidationRule = txtValidationRule.Text
  373.       .DefaultValue = txtDefaultValue.Text
  374.     End If
  375.   End With
  376.   If ObjectExists(gtdfTableDef.Fields, fld.Name) Then
  377.     MsgBox "'" & fld.Name & "'" & MSG1
  378.     txtFieldName.SelStart = 0
  379.     txtFieldName.SelLength = Len(txtFieldName.Text)
  380.     txtFieldName.SetFocus
  381.     Exit Sub
  382.   End If
  383.   gtdfTableDef.Fields.Append fld
  384.   frmTblStruct.lstFields.AddItem txtFieldName
  385.   frmTblStruct.lstFields.ListIndex = frmTblStruct.lstFields.NewIndex
  386. add table
  387.   If frmTblStruct.cmdAddTable.Visible Then
  388.     frmTblStruct.cmdAddTable.Enabled = True
  389.   End If
  390.   SetDefaults
  391.   txtFieldName.SetFocus
  392.   Exit Sub
  393. OkayErr:
  394.   ShowError
  395. End Sub
  396. Private Sub SetDefaults()
  397.   txtFieldName.Text = vbNullString
  398.   If gsDataType = gsMSACCESS Then
  399.     optFixedField.Value = False
  400.     chkAutoInc.Value = vbUnchecked
  401.     optVariable.Value = True
  402.     chkRequired.Value = vbUnchecked
  403.     chkAllowZeroLen.Value = vbChecked
  404.   Else
  405.     optFixedField.Value = False
  406.     chkAutoInc.Value = 2
  407.     optVariable.Value = False
  408.     chkRequired.Value = 2
  409.     chkAllowZeroLen.Value = 2
  410.   End If
  411.   cboFieldType.ListIndex = 8             '
  412.  text
  413.   txtFieldSize.Text = 50                 '
  414.   txtValidationText.Text = vbNullString
  415.   txtValidationRule.Text = vbNullString
  416.   txtDefaultValue.Text = vbNullString
  417. End Sub
  418.