VB程序学习代码记录20160729

这篇博客详细介绍了VB编程中涉及的文件系统控件,包括驱动器列表框、目录列表框和文件列表框的使用,并探讨了PathChange及PatternChange事件,揭示了这些控件间的联动机制。

驱动器列表框(DriveListBox控件)

Private Sub Command1_Click()
    Dim i As Integer
    Dim s As String
    For i = 0 To Drive1.ListCount - 1
        s = s & vbCrLf & Drive1.List(i)
        Label2.Caption = s
    Next i
End Sub

Private Sub Command2_Click()
    Unload Me
End Sub

目录列表框(DirListBox控件)

Private Sub Dir1_Change()
    Label1.Caption = Dir1.Path
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub

文件列表框(FileListBox控件)

Private Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()
    If Right(File1.Path, 1) = "\" Then
        Label1.Caption = "选择的文件的路径是:  " & vbCrLf & File1.Path & File1.FileName
    Else
        Label1.Caption = "选择的文件的路径是:  " & vbCrLf & File1.Path & "\" & File1.FileName
    End If
End Sub

pathchange事件

Private Sub dir1_change()
    File1.Path = Dir1.Path
End Sub
Private Sub drive1_change()
    Dir1.pth = dirve1.dirve
End Sub
Private Sub file1_pathchange()
    Label1.Caption = "路径为: " & File1.Path
End Sub
Private Sub form_load()
    Label1.Caption = "路径为:   " & Dir1.Path
End Sub

FileListBox(PatternChange事件)

Private Sub Combo1_click()
    File1.Pattern = Combo1.Text
End Sub
Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    Label2.Caption = "文件的路径是: " & File1.Path
End Sub
Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_patternchange()
    File1.Pattern = Combo1.Text
    Label2.Caption = "文件的路径是: " & File1.Path
End Sub
Private Sub Form_Load()
    File1.Path = Dir1.Path
    File1.Pattern = Combo1.Text
    Label2.Caption = "文件的路径是: " & File1.Path
End Sub

文件系统控件的联动

Private Sub Combo1_click()
    File1.Pattern = Combo1.Text
End Sub
Private Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
    Dim st As String, fpath As String
    If Right(Dir1.Path, 1) = "\" Then
        fpath = Dir1.Path & File1.FileName
    Else
        fpath = Dir1.Path & "\" & File1.FileName
    End If
    Text1.Text = ""
    Open fpath For Input As #1
    Do While Not EOF(1)
        Line Input #1, st
        Text1.Text = Text1.Text + st + vbCrLf
    Loop
    Close #1
End Sub
Private Sub File1_PatternChange()
    File1.Pattern = Combo1.Text
End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值