VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1920
   ClientLeft      =   165
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   1920
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "文件"
      Height          =   495
      Left            =   3000
      TabIndex        =   0
      Top             =   1140
      Width           =   1215
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   540
      Top             =   1200
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      CancelError     =   -1  'True
      Filter          =   "文本文件 | *.Txt"
      InitDir         =   "C:\Windows"
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   495
      Left            =   540
      TabIndex        =   1
      Top             =   300
      Width           =   3615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click()
    On Error GoTo nofile                        ' 设置错误陷阱
    CommonDialog1.InitDir = "C:\Windows"        ' 设置初始目录
    CommonDialog1.Filter = "文本文件 | *.Txt"       ' 过滤文件类型
    CommonDialog1.CancelError = True            ' 控制取消按钮
    ' 以上三行代码可在设计时直接设置
    CommonDialog1.ShowOpen                  ' 或用Action = 1显示文件打开对话框
    Label1.Caption = CommonDialog1.FileName     ' 显示选择的文件名
    Exit Sub                                ' 正常退出本过程
nofile:                                         ' 以下为错误处理
    If Err.Number = 32755 Then                  ' 单击"取消"按钮
    Label1.Caption = "放弃操作"
    Else
    Label1.Caption = "其他错误！"
    End If
End Sub

