(完整word版)vb读取txt文件.pdf
《(完整word版)vb读取txt文件.pdf》由会员分享,可在线阅读,更多相关《(完整word版)vb读取txt文件.pdf(12页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、vb 读取 txt 文件1.怎么通过代码创建一个文本文件,并读取,更新内容以上为随即方式打开的文本文件dim gfilenum as integer gfilenum=FreeFile Open 文件路径及文件名 For Random As gfilenum len=3 以随即方式打开一文件如果文件不存在就新建用 get#gfilenum,记录在文件中位置,要放取得的数据的变量 读取操作用 put#gfilenum,记录在文件中位置,要放着要写入数据的变量 写操作close#filenum关闭文件以下为顺序方式打开的文件dim gfilenum as integer gfilenum=Free
2、File Open 文件路径及文件名 For output As gfilenum 以写入方式打开文本print#gfilenum,要写入的文本write#filenum,要写入的文本dim gfilenum as integer gfilenum=FreeFile Open 文件路径及文件名 For input As gfilenum 以读出方式打开文本input#gfilenum,用来放读取的内容的内存变量名还可用 line input#,input()等读取更详细的查msdn 2.VB 读取文本文件时,调用TextStream 对象中使用 OpenTextFile 报错了。如果是Set
3、f=fs.OpenTextFile(E:tabletrace.txt,forreading,True,TristateUseDefault)出现错误:Run-time error 5:Invalid procedure call or argument 如果是Set f=fs.OpenTextFile(E:tabletrace.txt)则不会报错。用文件对象啊 FileSystemControl操作就好了啊再加上一个 TextStream 读取文件第一行就好了啊。3.VB 通过 FileSystemObject,可以读取文本文件(.txt)。对于.bat 文件,VB可否直接读取?bat 也属于
4、文本类文件可以读取不用 FSO也行:把文本文件内容读取TextBox:Dim TempFile As Long Dim LoadBytes()As Byte TempFile=FreeFile Open 文件名 For Binary As#TempFile Redim LoadBytes(1 To Lof(TempFile)As Byte Get#TempFile,LoadBytes Close TempFile Text1.Text=StrConv(LoadBytes,vbUniCode)把 TextBox 内容写入文本文件:Dim TempFile As Long Dim SaveByte
5、s()As Byte SaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile Open 文件名 For Binary As#TempFile Put#TempFile,SaveBytes Close TempFile 4.打开文本文件open app.path&/你的文本文件名.txt for output as#1 Message.Name=text1.text Message.Phone=text2.text .message.PostCode=text5.text Put#1,i,Message (此处 i=1,如要多次写
6、入,可用循环设置 i 的值)close#1 写入的同时即已保存查询的话就取出文本里的内容,用 instr()函数就可实现了5.查找 vbCrLf、vbLf 换行标记6.怎样读取一个文本文件的全部内容dim lenfile as integer 文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8
7、P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6
8、G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2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编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9dim filenu
13、m as integer filenum=freefile()open file.dat for input as filenum lenfile=lof(#filenum)strfile=input(lenfile,#filenum)将所有数据放入变量strfile中close filenum Private Sub Form_Load()Const ForReading=1,ForWriting=2 Dim fso,f Dim SkipLineInFile As String Set fso=CreateObject(Scripting.FileSystemObject)Set f=fso
14、.OpenTextFile(c:testfile.txt,ForWriting,True)f.Write Hello world!&vbCrLf&VB Script is fun!Set f=fso.OpenTextFile(c:testfile.txt,ForReading)SkipLineInFile=f.readall Debug.Print SkipLineInFile End Sub 7.把文本文件内容读取TextBox:Dim TempFile As Long Dim LoadBytes()As Byte TempFile=FreeFile Open 文件名 For Binary
15、As#TempFile Redim LoadBytes(1 To Lof(TempFile)As Byte Get#TempFile,LoadBytes Close TempFile Text1.Text=StrConv(LoadBytes,vbUniCode)8.把 TextBox 内容写入文本文件:Dim TempFile As Long Dim SaveBytes()As Byte SaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile Open 文件名 For Binary As#TempFile Put#TempFil
16、e,SaveBytes Close TempFile 9.已知文本文件,要从中搜索一段特定的字符串信息。如搜索MAGIC_DATABASES,该怎么做?文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM
17、2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ
18、6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码
19、:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 H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im str as string open commondialog1.filename for input#
23、1 input#1,str dim where as integer where=instr(str,magic_databases)10.Line Input#语句示例本示例使用 Line Input#语句从顺序文件中读入一行数据,并将该行数据赋予一个变量。本示例假设 TESTFILE 文件内含数行文本数据。Dim TextLine Open TESTFILE For Input As#1 打开文件。Do While Not EOF(1)循环至文件尾。Line Input#1,TextLine 读入一行数据并将其赋予某变量。Debug.Print TextLine 在立即窗口中显示数据。Lo
24、op Close#1 关闭文件。11.如何操作“文本文件”fso(Filesystemobject)对象集中的文件集合里有readline方法。Dim of As Object Dim fs as Object dim TextLine as string Set fs=createobject(scripting.Filesystemobject)set of=fs.OpenTextFile(app,path+myfile.aaa)/myfile.aaa 是一个文本文件textling=of.readline/如果你要读取第 14 行,可以用一个循环,跳过前面的13 行,如下dim lop
25、as integer for lop=0 to 12 of.skip next/然后再读取12.搜索了一下,大家主要用两种方法对文本文件加密。1.对文本文件的 ASC码加减2.用 XOR 函数我发现都有问题举例1.代码Public Function nnnn(ByVal s As String)As String 解密文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8 HM2Q2Y10K6G8 ZQ6H6D8O6B9文档编码:CS1Y3J2E8P8
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整 word vb 读取 txt 文件
限制150内