VB提取txt文件的内容

来源:百度知道 编辑:UC知道 时间:2024/05/09 14:04:46
如何提取同一目录下的txt文件里的内容在在VB显示?
在VB保存还可以把输入的内容保存到那个txt文件里?

保存:open "文件" for output as #1
print #1,"aa"
print #1,"bb"
close #1

读写 有字符读和行读写 具体+我QQ 490241327

Dim a As String
Dim b As String
open App.Path & "\文件名.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
b = b + a + Chr(13) + Chr(10)
text1.Text = b '在text1中显示其内容
Loop
Close #1
---------------------
保存:
open App.Path & "\文件名.txt" For output As #1
print #1,text1.text '保存text1中的内容
close #1

记得把text1的MultiLine设为True

调用 LoadTxt(文件名)将会返回该文件内容
调用 SaveToTxt(文件名,内容)将会把内容写入文件中
我在网吧写的,没有运行过,如果有什么问题自己改改就行了

Function LoadTxt(byval FileName as string) as string
dim i as integer,cl as string
i=FreeFile
open FileName for input as i
do while not eof(i)
line input i,cl
if not LoadTxt="" then LoadTxt=LoadTxt & vbcrlf
LoadTxt=LoadTxt & cl
loop
c