vb 文本文件的创建 读取 和修改问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:27:38
如果没有文件,就创建一个
有的话,就读取第一行给Text1,第二行给Text2……
然后在通过修改Text 修改 文本文件

只要把创建,读取,和写入的命令告诉清楚就可以了

假设文件的文件名及路径,存放在S变量中
'下面的是读取
If DIR(S)<>"" Then '存在这个文件
Open s For Input As #1
Line Input #1, s1
Line Input #1, s2
Close #1
Text1.Text = s1
Text2.Text = s2
end if
'下面的是写入'如果没有文件,会自动创建
Open s for output As #1
Print #1,Text1.text
print #1,text2.text
close #1

创建: open "file" for output as #1
读取: line input #1,str
写入: print #1,str