<VB数理统计实用算法>书中的算法源程序
源代码在线查看: 数据库_通用f3.frm
VERSION 5.00
Begin VB.Form frmIndex
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "索引"
ClientHeight = 3705
ClientLeft = 60
ClientTop = 450
ClientWidth = 7995
LinkTopic = "Form1"
ScaleHeight = 3705
ScaleWidth = 7995
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtDelName
Appearance = 0 'Flat
Height = 375
Left = 1920
TabIndex = 16
Top = 3240
Width = 1815
End
Begin VB.ListBox lstIDType
Appearance = 0 'Flat
Height = 2010
Left = 3840
TabIndex = 11
Top = 720
Width = 855
End
Begin VB.OptionButton optOut
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "外键"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 495
Left = 6600
TabIndex = 9
Top = 480
Value = -1 'True
Width = 975
End
Begin VB.CommandButton cmdCancel
Caption = "退 出"
Height = 375
Left = 6000
TabIndex = 8
Top = 3120
Width = 855
End
Begin VB.OptionButton OptMain
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "主键"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 495
Left = 5400
TabIndex = 7
Top = 480
Width = 975
End
Begin VB.TextBox txtFieldName
Appearance = 0 'Flat
Height = 375
Left = 120
TabIndex = 6
Top = 3240
Width = 1695
End
Begin VB.CommandButton cmdDelIndex
Caption = "删除索引"
Height = 375
Left = 5760
TabIndex = 5
Top = 2400
Width = 1215
End
Begin VB.CommandButton cmdAddIndex
Caption = "添加索引"
Height = 375
Left = 5760
TabIndex = 4
Top = 1080
Width = 1215
End
Begin VB.ListBox lstIDName
Appearance = 0 'Flat
Height = 2010
Left = 1920
TabIndex = 3
Top = 720
Width = 1815
End
Begin VB.ListBox lstFDName
Appearance = 0 'Flat
Height = 2010
Left = 120
TabIndex = 2
Top = 720
Width = 1695
End
Begin VB.Line Line1
X1 = 4920
X2 = 4920
Y1 = 0
Y2 = 3720
End
Begin VB.Label lblDelNotice
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "删除索引时,应先在索引表选择"
ForeColor = &H80000008&
Height = 255
Left = 5040
TabIndex = 17
Top = 2040
Width = 2775
End
Begin VB.Label lblDel
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "将删除的索引"
ForeColor = &H80000008&
Height = 255
Left = 1920
TabIndex = 15
Top = 3000
Width = 1815
End
Begin VB.Label lblSelect
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "将添加为索引"
ForeColor = &H80000008&
Height = 255
Left = 120
TabIndex = 14
Top = 3000
Width = 1695
End
Begin VB.Label lblPoint
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "添加索引时,应先确定键的类型"
ForeColor = &H80000008&
Height = 255
Left = 5040
TabIndex = 13
Top = 120
Width = 2775
End
Begin VB.Label lblNotice
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "“添加索引”先选择字段,“删除索引”先选择索引"
ForeColor = &H80000008&
Height = 255
Left = 480
TabIndex = 12
Top = 120
Width = 4215
End
Begin VB.Label lblIDType
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 3840
TabIndex = 10
Top = 480
Width = 855
End
Begin VB.Label lblIDName
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 1920
TabIndex = 1
Top = 480
Width = 1815
End
Begin VB.Label lblFDName
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Left = 120
TabIndex = 0
Top = 480
Width = 1695
End
End
Attribute VB_Name = "frmIndex"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'窗体frmIndex
'索引处理
Option Explicit
Private Sub Form_Load()
lblFDName = td.Name & "所包括的字段"
'在列表框显示字段
For Each fd In td.Fields
lstFDName.AddItem fd.Name
Next
lblIDName = td.Name & "所包括的索引"
lblIDType = "类型"
'在列表框显示索引
For Each id In td.Indexes
If id.Required Then
lstIDName.AddItem id.Name
lstIDType.AddItem "主键"
Else
lstIDName.AddItem id.Name
lstIDType.AddItem "外键"
End If
Next
End Sub
'添加索引
Private Sub cmdAddIndex_Click()
On Error Resume Next
Set id = td.CreateIndex(txtFieldName)
If OptMain.Value Then '添加主键
With id
Set fd = .CreateField(txtFieldName.Text)
.Required = True
.Primary = True
.Fields.Append fd
End With
td.Indexes.Append id
Else '添加外键
With id
Set fd = .CreateField(txtFieldName.Text)
.Required = False
.Primary = False
.Fields.Append fd
End With
td.Indexes.Append id
End If
lstIDName.Clear
txtFieldName.Text = ""
'在列表框显示索引
lstIDType.Clear
For Each id In td.Indexes
lstIDName.AddItem id.Name
If id.Required Then
lstIDType.AddItem "主键"
Else
lstIDType.AddItem "外键"
End If
Next
End Sub
'删除索引
Private Sub cmdDelIndex_Click()
On Error GoTo errDel
td.Indexes.Delete (txtDelName.Text)
'在列表框显示删除后的索引
lstIDName.Clear
lstIDType.Clear
For Each id In td.Indexes
lstIDName.AddItem id.Name
If id.Required Then
lstIDType.AddItem "主键"
Else
lstIDType.AddItem "外键"
End If
Next
txtDelName.Text = ""
Exit Sub
errDel:
MsgBox "非索引,不能删除!"
End Sub
'取消
Private Sub cmdCancel_Click()
Unload Me
Load frmDatabase
frmDatabase.Visible = True
End Sub
'选出将添加为索引的字段
Private Sub lstFDName_Click()
txtFieldName = lstFDName '将选中的字段送到用于添加索引的文本框
End Sub
'选出将删除的索引
Private Sub lstIDName_Click()
txtDelName = lstIDName '将选中的字段送到用于删除索引的文本框
End Sub