vb读取txt的方法写入txt的方法.docx

上传人:小飞机 文档编号:3168383 上传时间:2023-03-11 格式:DOCX 页数:3 大小:37.03KB
返回 下载 相关 举报
vb读取txt的方法写入txt的方法.docx_第1页
第1页 / 共3页
vb读取txt的方法写入txt的方法.docx_第2页
第2页 / 共3页
vb读取txt的方法写入txt的方法.docx_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《vb读取txt的方法写入txt的方法.docx》由会员分享,可在线阅读,更多相关《vb读取txt的方法写入txt的方法.docx(3页珍藏版)》请在三一办公上搜索。

1、vb读取txt的方法写入txt的方法vb读取txt的方法-写入txt的方法 1. Private Sub Command1_Click 2. 写文件示例 3. Dim strFileName As String 文件名 4. Dim lngHandle As Long 句柄 5. Dim strWrite As String 要写入的文本内容 6. 7. strFileName = App.Path & /a.txt 8. App.Path & /a.txt相对路径 9. c:/w.txt绝对路径 10. lngHandle = FreeFile 取得句柄 11. 准备要写入的内容 12. s

2、trWrite = Text1.Text 或者 strWrite = 这些文字将被写入文件。 13. For后面的参数表示以何种方式打开文件,Input是读取,Output是覆盖写入,Append是追加写入 14. append是每次在文件末尾写入,不删除其它已经存在的文件.如果换成output则删除其它文件后再写入 15. print#1,text1.text 如果print换成write则写进txt中后自动加双引号 16. 17. Open strFileName For Output As lngHandle 打开文件 18. Print #lngHandle, strWrite 写入文

3、本 19. Close lngHandle 关闭文件 20. End Sub 21. Private Sub Command2_Click 22. 读文件示例 23. Dim strFileName As String 文件名 24. Dim lngHandle As Long 文件句柄 25. Dim strAll As String 所读取的文本文件的所有内容 26. Dim strLine As String 在循环中存放每行的内容 27. strFileName = App.Path & /a.txt 28. 获得文件的句柄 29. lngHandle = FreeFile 30. F

4、or后面的参数表示以何种方式打开文件,Input是读取,Output是覆盖写入,Append是追加写入 31. Open strFileName For Input As lngHandle 32. 循环直到文件尾 33. Do While Not EOF(lngHandle) 34. 每次读取一行存放在strLine变量中 35. Line Input #lngHandle, strLine 36. 每次读取都把所读到的内容连接到strAll变量,由于Line Input去掉了换行符,所以这里补上 37. strAllstrAll = strAll & strLine & vbCrLf 38. Loop 39. 显示得到的全部分内容 40. MsgBox strAll 41. End Sub 42. 43. Private Sub Command1_Click 44. Open App.Path & /a.txt For Output As #1 45. Print #1, Text1.Text 这里可以是数据本身也可以是目标控件的属性 46. Close #1 关闭打开的文件 47. End Sub 48. For后面的参数表示以何种方式打开文件,Input是读取,Output是覆盖写入,Append是追加写入

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号