⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 VB
字号:
Imports VB = Microsoft.VisualBasic
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
	Public Sub New()
		MyBase.New()
        '此调用是 Windows 窗体设计器所必需的。
		InitializeComponent()
	End Sub
	'窗体重写处置,以清理组件列表。
	Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
		If Disposing Then
			If Not components Is Nothing Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(Disposing)
	End Sub
	'Windows 窗体设计器所必需的
	Private components As System.ComponentModel.IContainer
	Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents lstTables As System.Windows.Forms.ListBox
	Public WithEvents cdlTableData As AxMSComDlg.AxCommonDialog
	Public WithEvents lblRecords As System.Windows.Forms.Label
	Public WithEvents lblModified As System.Windows.Forms.Label
	Public WithEvents lblCreated As System.Windows.Forms.Label
	Public WithEvents _lblTableData_2 As System.Windows.Forms.Label
	Public WithEvents _lblTableData_1 As System.Windows.Forms.Label
	Public WithEvents _lblTableData_0 As System.Windows.Forms.Label
	Public WithEvents lblTableData As Microsoft.VisualBasic.Compatibility.VB6.LabelArray
	'注意: 以下过程是 Windows 窗体设计器所必需的
	'可以使用 Windows 窗体设计器来修改它。
	'不要使用代码编辑器修改它。
    Public WithEvents Button1 As System.Windows.Forms.Button
    Public WithEvents Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.lstTables = New System.Windows.Forms.ListBox
        Me.cdlTableData = New AxMSComDlg.AxCommonDialog
        Me.lblRecords = New System.Windows.Forms.Label
        Me.lblModified = New System.Windows.Forms.Label
        Me.lblCreated = New System.Windows.Forms.Label
        Me._lblTableData_2 = New System.Windows.Forms.Label
        Me._lblTableData_1 = New System.Windows.Forms.Label
        Me._lblTableData_0 = New System.Windows.Forms.Label
        Me.lblTableData = New Microsoft.VisualBasic.Compatibility.VB6.LabelArray(Me.components)
        CType(Me.cdlTableData, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.lblTableData, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.SystemColors.Control
        Me.Button1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button1.Location = New System.Drawing.Point(16, 184)
        Me.Button1.Name = "Button1"
        Me.Button1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button1.Size = New System.Drawing.Size(89, 37)
        Me.Button1.TabIndex = 8
        Me.Button1.Text = "打开数据库"
        '
        'Button2
        '
        Me.Button2.BackColor = System.Drawing.SystemColors.Control
        Me.Button2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Button2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button2.Location = New System.Drawing.Point(192, 184)
        Me.Button2.Name = "Button2"
        Me.Button2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button2.Size = New System.Drawing.Size(89, 37)
        Me.Button2.TabIndex = 7
        Me.Button2.Text = "退出程序"
        '
        'lstTables
        '
        Me.lstTables.BackColor = System.Drawing.SystemColors.Window
        Me.lstTables.Cursor = System.Windows.Forms.Cursors.Default
        Me.lstTables.ForeColor = System.Drawing.SystemColors.WindowText
        Me.lstTables.ItemHeight = 12
        Me.lstTables.Location = New System.Drawing.Point(6, 6)
        Me.lstTables.Name = "lstTables"
        Me.lstTables.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lstTables.Size = New System.Drawing.Size(283, 76)
        Me.lstTables.Sorted = True
        Me.lstTables.TabIndex = 0
        '
        'cdlTableData
        '
        Me.cdlTableData.Enabled = True
        Me.cdlTableData.Location = New System.Drawing.Point(8, 234)
        Me.cdlTableData.Name = "cdlTableData"
        Me.cdlTableData.OcxState = CType(resources.GetObject("cdlTableData.OcxState"), System.Windows.Forms.AxHost.State)
        Me.cdlTableData.Size = New System.Drawing.Size(32, 32)
        Me.cdlTableData.TabIndex = 9
        '
        'lblRecords
        '
        Me.lblRecords.BackColor = System.Drawing.SystemColors.Control
        Me.lblRecords.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblRecords.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblRecords.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblRecords.Location = New System.Drawing.Point(146, 150)
        Me.lblRecords.Name = "lblRecords"
        Me.lblRecords.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblRecords.Size = New System.Drawing.Size(73, 17)
        Me.lblRecords.TabIndex = 6
        Me.lblRecords.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblModified
        '
        Me.lblModified.BackColor = System.Drawing.SystemColors.Control
        Me.lblModified.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblModified.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblModified.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblModified.Location = New System.Drawing.Point(146, 120)
        Me.lblModified.Name = "lblModified"
        Me.lblModified.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblModified.Size = New System.Drawing.Size(143, 17)
        Me.lblModified.TabIndex = 5
        '
        'lblCreated
        '
        Me.lblCreated.BackColor = System.Drawing.SystemColors.Control
        Me.lblCreated.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblCreated.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblCreated.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblCreated.Location = New System.Drawing.Point(146, 98)
        Me.lblCreated.Name = "lblCreated"
        Me.lblCreated.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblCreated.Size = New System.Drawing.Size(143, 17)
        Me.lblCreated.TabIndex = 4
        '
        '_lblTableData_2
        '
        Me._lblTableData_2.AutoSize = True
        Me._lblTableData_2.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(192, Byte))
        Me._lblTableData_2.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblTableData_2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblTableData.SetIndex(Me._lblTableData_2, CType(2, Short))
        Me._lblTableData_2.Location = New System.Drawing.Point(96, 152)
        Me._lblTableData_2.Name = "_lblTableData_2"
        Me._lblTableData_2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblTableData_2.Size = New System.Drawing.Size(60, 17)
        Me._lblTableData_2.TabIndex = 3
        Me._lblTableData_2.Text = "记录数目:"
        '
        '_lblTableData_1
        '
        Me._lblTableData_1.AutoSize = True
        Me._lblTableData_1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(192, Byte))
        Me._lblTableData_1.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblTableData_1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblTableData.SetIndex(Me._lblTableData_1, CType(1, Short))
        Me._lblTableData_1.Location = New System.Drawing.Point(72, 123)
        Me._lblTableData_1.Name = "_lblTableData_1"
        Me._lblTableData_1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblTableData_1.Size = New System.Drawing.Size(85, 17)
        Me._lblTableData_1.TabIndex = 2
        Me._lblTableData_1.Text = "最后修改时间:"
        '
        '_lblTableData_0
        '
        Me._lblTableData_0.AutoSize = True
        Me._lblTableData_0.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(192, Byte))
        Me._lblTableData_0.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblTableData_0.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblTableData.SetIndex(Me._lblTableData_0, CType(0, Short))
        Me._lblTableData_0.Location = New System.Drawing.Point(99, 100)
        Me._lblTableData_0.Name = "_lblTableData_0"
        Me._lblTableData_0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblTableData_0.Size = New System.Drawing.Size(60, 17)
        Me._lblTableData_0.TabIndex = 1
        Me._lblTableData_0.Text = "创建时间:"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(192, Byte))
        Me.CancelButton = Me.Button2
        Me.ClientSize = New System.Drawing.Size(296, 227)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.lstTables)
        Me.Controls.Add(Me.cdlTableData)
        Me.Controls.Add(Me.lblRecords)
        Me.Controls.Add(Me.lblModified)
        Me.Controls.Add(Me.lblCreated)
        Me.Controls.Add(Me._lblTableData_2)
        Me.Controls.Add(Me._lblTableData_1)
        Me.Controls.Add(Me._lblTableData_0)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Location = New System.Drawing.Point(99, 175)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "获得数据库的信息"
        CType(Me.cdlTableData, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.lblTableData, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 

    Public DAODBEngine_definst As New DAO.DBEngine
	Private colTableData As Collection
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

	End Sub
	Private Sub GetDatabase()
		Dim dbfTableData As DAO.Database
		Dim tdfTables As DAO.TableDefs
		Dim tdfSelectedTable As DAO.TableDef
		Dim objTable As clsTableData
		Dim strDatabaseName As String
        Dim x As Integer
        x = 0
		On Error GoTo NoDatabaseError
        cdlTableData.ShowOpen()
		On Error GoTo GetDatabaseError
		strDatabaseName = cdlTableData.FileName
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
        '打开选择的数据库
		dbfTableData = DAODBEngine_definst.Workspaces(0).OpenDatabase(strDatabaseName, False, True)
        '取得表格并存储在一个当地变量中
		tdfTables = dbfTableData.TableDefs
        '调用的新的类
		colTableData = New Collection
        '获得表格的属性
		For	Each tdfSelectedTable In tdfTables
			If VB.Left(tdfSelectedTable.Name, 4) <> "MSys" Then
				objTable = New clsTableData
				objTable.ExtractStatusData(tdfSelectedTable)
				colTableData.Add(objTable)
                With lstTables
                    x = .Items.Add(objTable.Name)
                    VB6.SetItemData(lstTables, x, colTableData.Count())

                End With
            End If
		Next tdfSelectedTable
        dbfTableData.Close()
		On Error GoTo 0
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		On Error GoTo 0
		Exit Sub
		
NoDatabaseError: 
        '如果用户没有选择数据库,则退出程序
		End
		
GetDatabaseError: 
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
		MsgBox(Err.Description, MsgBoxStyle.Exclamation)
		End
	End Sub
    Private Sub lstTables_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lstTables.SelectedIndexChanged
        Dim objTable As clsTableData
        Dim intPosition As Short

        intPosition = VB6.GetItemData(lstTables, lstTables.SelectedIndex)
        objTable = colTableData.Item(intPosition)

        '赋予标签表格的属性
        lblCreated.Text = VB6.Format(objTable.WhenCreated, "General Date")
        lblModified.Text = VB6.Format(objTable.WhenModified, "General Date")
        lblRecords.Text = CStr(objTable.NumRecords)
    End Sub
    Private Sub Button1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button1.Click
        '清除列表框中的选项
        lstTables.Items.Clear()
        lblCreated.Text = "" : lblModified.Text = "" : lblRecords.Text = ""
        colTableData = Nothing

        '调用"打开文件"对话框
        cdlTableData.FileName = "*.MDB"
        GetDatabase()
    End Sub
    Private Sub Button2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -