vb 记事本读取问题

来源:百度知道 编辑:UC知道 时间:2024/05/03 02:37:17
command1 保存
command2 读取

'保存的代码
open "c:\1.txt" for output as#1
print#1,text1.text
print#1,text2.text
print#1,text3.text
close#1

'读取的代码
dim tmp as string
dim n as integer

open "c:\1.txt" for input as#1
do while not eof(1)
line input#1,tmp

if n=0 then text1.text=tmp
if n=1 then text2.text=tmp
if n=2 then text3.text=tmp

n=n+1
loop
close#1
如果第一次打开程序时单击command2(读取)按钮时程序出错
如何修改才能使第一次打开程序时不单击command1直接单击commmand2不出错该如何修改,请给出修改后的编码

'读取的代码
on error resume next '加上这句
dim tmp as string
dim n as integer

open "c:\1.txt" for input as#1
do while not eof(1)
line input#1,tmp

if n=0 then text1.text=tmp
if n=1 then text2.text=tmp
if n=2 then text3.text=tmp

n=n+1
loop
close#1