【VB】VB文件系统操作
针对txt,Word,Execl都可以使用
顺序文件:
(1)创建:
Open "D:\test.doc" For Output As #1 //创建
Output 写入
Append写入
Input 读取
(2)写入
Print #1, "ASDFREWFGH" //写入
Write #1,"aaaaaaaaaa" //写入
(3)读取
Input #2, inputdate
Text1.Text = inputdate
Line Input #2,inputdate
Input(Number,#1)
(4)关闭
Close
随机文件:
(1)创建:
Open "D:\test.doc" For Random Access Read As #1 Len=100 //创建
(2)写入
Put #1, 2,Rec //写入
用变量Rec来替代位置为2的记录
(3)读取
Get #2,2, Rec
将一个记录从#2 文件中复制到变量Rec中,2是要读取的记录号
(4)关闭
Close
二进制文件
(1)创建:
Open "D:\test.doc" For Binary As #1 //创建
(2)写入
Put #1, 2,Rec //写入
用变量Rec来替代位置为2的记录
(3)读取
Get #2,2, Rec
将一个记录从#2 文件中复制到变量Rec中,2是要读取的记录号
(4)关闭
Close
VB文件系统控件
1.驱动器列表框(DriveListBox) Drive1
2.目录列表框(DirListBox) Dir1
3.文件列表框(FileListBox) File1
设置对应关系过程:
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
VB FSO对象模型
应用 "Microsoft Scripting Runtime"
Drive对象,Folder对象,File对象,TextStream对象
创建FSO对象:
(1)Dim MyFSO As New FileSystemObject
(2)Set MyFSO = CreateObject("Scripting.FileSystemObject")
Dim MyFSO As New FileSystemObject
Dim MyFolder As Folder
Dim MyFile As File
Set MyFolder = MyFSO.CreateFolder("D:\Test") //创建文件夹
Print "Create:"; MyFolder.Name
Set MyFile = MyFSO.CreateTextFile("D:\Test1.txt", True)//创建文件
- 上一篇 »vb文件操作函数
- 下一篇 »第九章 VB的数据库操作