2022年VB文件操作小结 .pdf
《2022年VB文件操作小结 .pdf》由会员分享,可在线阅读,更多相关《2022年VB文件操作小结 .pdf(4页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、*文件统计替换字符Private Sub Form_Load() On Error Resume Next Dim Handle As Integer, Filetext As String Handle = FreeFile Open C:MYDIRDATA.TXT For Binary As #Handle 打开一个文件(二进制形式打开)Filetext = Space(LOF(Handle) Get #Handle, , Filetext Close #Handle 读取文件Dim A As Long, B As Long A = FileLen(C:MYDIRDATA.TXT) B =
2、 Len(Replace(Filetext, $, ) 计算差值Handle = FreeFile Open C:Mydirres.txt For Output As #Handle Print #Handle, A - B Close #Handle 保存End Sub *读取文件内容到字符串变量Private Sub Command1_Click() Dim s As String Open c:sql.txt For Binary As #1 s=space(lof(1) get #1,1, s Close #1 Debug.Print s end sub *把一个文件复制dim buf
3、 as string Open C:test.txt for Input as #1 line input#1,buf 当用过后指针本来就是自动到下一行的!你还可以用二进制方式打开文件并自己定义读入或写入多少! dim buf()as byte Open C:test.exe for binary as #1 redim buf(1 to lof(1) get#1,buf close #1 open D:test.exe for binary as #1 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - -
4、- - - - 第 1 页,共 4 页 - - - - - - - - - put #1,buf close#1 这个程序实现把C:test.exe 复制到 D 盘*寻找字符1.Private Sub Command1_Click() 2.Dim i As Long 3.Dim b As Byte 4.5.Open c:demo.dat For Binary As #1 6.7.Do While Not EOF(1) 8. i = i + 1 9. Get #1, , b 10. If b = Asc(A) Then Print i 11.Loop 12.Close 13. End Sub *
5、直接读文件最后一行Private Sub Command1_Click() Dim Bool As Boolean Dim NextChar As Integer Dim MaxSize As Long Dim Mychar As String Bool = False Open e:123.txt For Input As #1 Open file for input. MaxSize = LOF(1) Get size of file in bytes. The loop reads all characters starting from the last. For NextChar =
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年VB文件操作小结 2022 VB 文件 操作 小结
限制150内