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

📄 module1.bas

📁 一个数据库,关于如何在treeview中连接不同的数据库表
💻 BAS
字号:
Attribute VB_Name = "Module1"
Public con As Connection
Public resorg As Recordset
Public rescom As Recordset
Public nod0 As Node
Public nod1 As Node
Public nod2 As Node

Sub connect()
    Set con = New Connection
    Set resorg = New Recordset
    Set rescom = New Recordset
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb"
End Sub
Sub open_close(res As Recordset)                   '声明过程  判断,关掉记录集
    If res.State = 1 Then             '如果开着,就
        res.Close                         '关掉
    End If
End Sub

Sub display()                             '显示文本
    Dim chunks() As Byte '保存文件指针的位置
    Dim totalsize As Long '数据块长度
    Dim offset As Long '文件长度

    If Not rescom.EOF Then
        Dim i As Integer                          '显示文本
        For i = 0 To 16                         '显示文本
            If Not rescom(i).Value = "" Then       '显示文本
                Form1.Text1(i).Text = rescom(i).Value '显示文本
            Else
                Form1.Text1(i).Text = ""
            End If                                 '显示文本
        Next                                    '显示文本
        Form1.Combo2.Text = rescom(17).Value
        Form1.Combo1.Text = Form1.Text1(2).Text
    End If
    
    f = App.Path & "\photo.tmp"                '显示图象
    Open f For Binary Access Write As 1
    totalsize = rescom(18).ActualSize         '保存数据长度
    If totalsize = 0 Then
        Form1.Image1.Picture = Nothing
        Close #1
        Exit Sub
    End If
    Dim fragment As Integer '按单位截取多余部分
    fragment = totalsize Mod 16384
    
    ReDim chunks(fragment) '读取数据
    chunks() = rescom(18).GetChunk(fragment)
    Put 1, , chunks() '写入数据
    
    ReDim chunks(16384) '单位长度的数据块
    offset = offset + fragment '数据指针的位置
    While offset < totalsize
        chunks() = rescom(18).GetChunk(16384)
        Put 1, , chunks()
        offset = offset + 16384
    Wend

    Close #1

    Form1.Image1.Picture = LoadPicture(f) '这一次的地址f = App.Path & "\photo.tmp"
    Kill App.Path & "\photo.tmp"
End Sub

Sub position() '定位
    rescom.MoveFirst
    While Not rescom.EOF
        If Form1.Text1(0).Text = rescom(0).Value Then
            Exit Sub
        Else
            rescom.MoveNext
        End If
    Wend
End Sub
Sub tree_refresh()
'**************建 树************************
    Set nod0 = Form1.TreeView1.Nodes.add(, , "root", "通讯录", 1)
    Dim i As Integer
    resorg.MoveFirst
    While Not resorg.EOF
        Set nod1 = Form1.TreeView1.Nodes.add("root", tvwChild, "r" & resorg(0).Value, resorg(1), 2)
        rescom.MoveFirst
        While Not rescom.EOF
            If rescom("属于") = resorg(1).Value And rescom("性别") = "男" Then
                Set nod2 = Form1.TreeView1.Nodes.add("r" & resorg(0).Value, tvwChild, "r" & rescom(0).Value, rescom(1).Value, 4)
            ElseIf rescom("属于") = resorg(1).Value And rescom("性别") = "女" Then
                Set nod2 = Form1.TreeView1.Nodes.add("r" & resorg(0).Value, tvwChild, "r" & rescom(0).Value, rescom(1).Value, 5)
            End If
            rescom.MoveNext
        Wend
        nod1.EnsureVisible '不需要展开
        resorg.MoveNext
    Wend
End Sub

Sub text_allow()
    Dim i As Integer
    For i = 0 To 16
        Form1.Text1(i).Locked = False
    Next
    Form1.Combo1.Locked = False
    Form1.Combo2.Locked = False
    Form1.Image1.Enabled = True
End Sub
Sub text_disallow()
    Dim i As Integer
    For i = 0 To 16
        Form1.Text1(i).Locked = True
    Next
    Form1.Combo1.Locked = True
    Form1.Combo2.Locked = True
    Form1.Image1.Enabled = False
End Sub

⌨️ 快捷键说明

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