VB作业 求教..
来源:百度知道 编辑:UC知道 时间:2024/09/21 00:42:28
求教 解题过程
Private Sub Command1_Click()
CommonDialog1.InitDir = "D:" '设置默认路径
CommonDialog1.CancelError = True ' 设置“CancelError”为 True
On Error GoTo ErrHandler
CommonDialog1.Flags = cdlOFNHideReadOnly ' 设置标志
CommonDialog1.Filter = "All Files (*.*)|*.*|(*.frm;*.vbp)|*.frm;*.vbp" ' 设置过滤器
CommonDialog1.FilterIndex = 2 ' 指定缺省的过滤器
CommonDialog1.ShowOpen ' 显示“打开”对话框
MsgBox CommonDialog1.FileName ' 显示选定文件的名字
Command1.Caption = Getfilename(CommonDialog1.FileName) '更改按钮名
Me.Caption = Left(Getfilename(CommonDialog1.FileName), 3) '更改标题名 细节自行修改
Exit Sub
ErrHandler:
Exit Sub ' 用户按了“取消”按钮
End Sub
Private Sub Form_Load()
Command1.Caption = "姓名"
End Sub
Function Getfilename(FPath)
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FPath) = True Then
Set pname =