背景:                 
[本书目录] [图书首页] [本书讨论区]  
链接地址:http://www.17xie.com/read-40.html    注册17xie 一起来写书 实现您的出书梦想!

提示:

@        在程序运行的过程中,用户还可以通过选择下拉式列表框中的内容来决定在文件控件中显示的类型,如所有文件、以*.txt为文件后缀的文本文件、以*.bmp为文件后缀的图像文件等。

附程序完整源代码如下所示:

程序清单

VERSION 6.00

Begin Visual Basic.Form Form1

     BorderStyle         =       3

     Caption      =       "Form1"

     MaxButton         =       0

     MinButton          =       0

     Moveable   =       0

     ScaleHeight         =       4590

     ScaleWidth =       6885

     StartUpPosition  =       2

End

Attribute Visual Basic_Name = "Form1"

Attribute Visual Basic_GlobalNameSpace = False

Attribute Visual Basic_Creatable = False

Attribute Visual Basic_PredeclaredId = True

Attribute Visual Basic_Exposed = False

 

Private Sub Combo1_Click()

Form1.File1.Pattern = Form1.Combo1.Text

End Sub

 

Private Sub Dir1_Change()

Form1.File1.Path = Form1.Dir1.Path

End Sub

 

Private Sub Dir1_Click()

Fname = Form1.Dir1.Path

Result = GetAttr(Fname) And vbDirectory

If Result <> 0 Then

   Form1.Text2.Text = "目录"

End If

Form1.Text1.Text = ""

Form1.Text3.Text = ""

End Sub

 

Private Sub Dir1_DragDrop(Source As Control, X As Single, Y As Single)

If Mid(File1.Path, Len(File1.Path)) = "\" Then

   Fname = File1.Path & File1.FileName

   '如果被单击的文件在根目录,就追加文件名

Else

   Fname = File1.Path & "\" & File1.FileName

   '如果被单击的文件不在根目录,就追加 "\" 和文件名

End If

Kill Fname

Form1.File1.Refresh

End Sub

 

Private Sub Dir1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)

Select Case State

    Case 0

        ' ""进入""区域内时,显示一个新图标。

        File1.DragIcon = Dir1.DragIcon

    Case 1

        ' ""离开""区域时,显示原来的 DragIcon 图标。

        File1.DragIcon = Drive1.DragIcon

    End Select

End Sub

 

Private Sub Drive1_Change()

    On Error GoTo DriveErrs

    '错误处理

    Dir1.Path = Drive1.Drive

    '设置目录显示路径

Exit Sub

DriveErrs:

'错误处理

    Select Case Err

        Case 68

            MsgBox prompt:="驱动器未准备好。请在驱动器内插入磁盘。", _

            buttons:=vbExclamation

            ' 将路径重置为先前使用的驱动器。

            Drive1.Drive = Dir1.Path

            Exit Sub

        Case Else

            MsgBox prompt:="应用程序错误。", buttons:=vbExclamation

    End Select

End Sub

 

Private Sub File1_Click()

Form1.Text2.Text = ""

If Mid(File1.Path, Len(File1.Path)) = "\" Then

   Fname = File1.Path & File1.FileName

   '如果被单击的文件在根目录,就追加文件名。

Else

   Fname = File1.Path & "\" & File1.FileName

   '如果被单击的文件不在根目录,就追加 "\" 和文件名。

End If

Form1.Text1.Text = FileLen(Fname) & "Byte"

If (GetAttr(Fname) And 32) <> 0 Then

   Form1.Text2.Text = Form1.Text2.Text & " 存档"

End If

If (GetAttr(Fname) And 2) <> 0 Then

   Form1.Text2.Text = Form1.Text2.Text & " 隐藏"

End If

If (GetAttr(Fname) And 1) <> 0 Then

   Form1.Text2.Text = Form1.Text2.Text & " 只读"

End If

If (GetAttr(Fname) And 4) <> 0 Then

   Form1.Text2.Text = Form1.Text2.Text & " 系统"

End If

Form1.Text3.Text = FileDateTime(Fname)

End Sub

 

Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

File1.DragIcon = Drive1.DragIcon

File1.Drag

End Sub

5.4   

文件是计算机的基本概念,也是计算机进行运算和存储的基础,在Visual Basic 6.0中处理文件可以通过以下几个途径,如通过文件处理控件、调用系统函数和利用Visual Basic 6.0自定义文件函数等方式。

在本章中将会通过几个示例程序向读者介绍有关Visual Basic 中处理文件的基本技术和常用技巧,如利用文件类控件处理文件、制作文件查询程序和利用文件函数处理文件等。


字数:4844    最后更新:1年以前 [08-17 22:08]我爱钱 修改
本页编辑者:我爱钱  
[前一页]:第五章  [后一页]:第六章
[在本页中加入书签] [收藏本书] [推荐本书]
  17xie论坛 > 本书讨论区 > 本页评论   (共0条)
发表评论

用户名称 匿名发表
评论内容
验证码

关于我们 | 版权声明 | 免责声明 | 诚聘英才 | 联系我们 | 合作伙伴 | 友情链接 | 广告合作 | 提交意见
Copyright © 2007 17xie.com 互联网协同写书平台 京ICP备08002671号