【VB】VB文件系统操作


针对txt,Word,Execl都可以使用
顺序文件:
(1)创建:
    Open "D:\test.doc" For Output As #1 //创建
    Output 写入
    Append写入
     Inp ut 读取
 (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)//创建文件


 
 



转载于:https://www.cnblogs.com/cuishao1985/archive/2009/07/25/1530998.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值