VB text1对比TXT里的内容,高手进

来源:百度知道 编辑:UC知道 时间:2024/05/24 11:28:56
form1中有text1和command1,c盘下有个txt文档。text1输入一些字母,按下command1后如果判断text1里的字母如果与txt文档里的字母相同,删除txt文档里相同的那些内容。如果没有相同的字母,刚跳出错误提示。
看不懂。 1 2 3 要写在哪?

1.
Open "c:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
b = b & a & vbCrLf
Loop
Close #1

2.
if instr(b,text1)<>0 then
b=replace(b,text1,"")
else
msgbox "错误!"
exit sub
end if

3.
Open "c:\1.txt" For output As #1
print #1,b
Close #1

呵呵,不难,就是现在有点儿懒,不想写

1、3的另一种方法:
1.
dim a() as byte,b as string
redim a(filelen("c:\1.txt")-1)
Open "c:\1.txt" For binary As 1
get 1,,a()
Close 1
b=a

3、
kill "c:\1.txt"
Open "c:\1.txt" For binary As 1
put 1,,a()
Close 1