Option Explicit
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Label1.Caption = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
Label1.Caption = Drive1.Drive
End Sub
Private Sub File1_Click()
If Right(Dir1.Path,1) = "\" Then红字是right语法;若目录路径最右侧的字符为"\"
Label1.Caption = Dir1.Path & File1.FileName 显示所选择的文件名
Else 若目录路径最右侧的字符不是为"\"
Label1.Caption = Dir1.Path & "\" & File1.FileName在显示的文件名前添加"\"
End If
End Sub
Private Sub Form_Load()
Dir1.Path = Drive1.Drive文件所在的驱动器与目录项符合
File1.FileName = Dir1.Path文件的路径是目录列表中的路径
End Sub
成品图
此题和VB百例48相类似
原文链接:https://www.f2er.com/vb/260402.html