VB中读取TXT文件的问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 17:55:31
在TXT文件中保存了用户名和密码,单行为用户名,下一行是对应的密码,现在VB中要求在TEXT1中输入的用户名与TXT中单行的用户名进行对比,相同则通过,不同则继续读取下个单行的用户名进行对比,一直到文件末,如果没有则提示不存在,密码亦相同。这个代码应该怎么写啊?高人指点下!!谢谢!

dim Filename,Users(),Passs(),ls,tmp
redim users(0),passs(0)
ls=0
filename="c:\a.txt"'密码文件--最好先加密
open Filename for input as #1
do while not eof(1)
line input #1,tmp
if trim(tmp)="" then goto nxt else
tmp=trim(tmp) '去处空行的,如果允许空用户名、密码,可以去掉此行
ls=ls+1
if int(ls/2)=ls/2 then
redim Preserve Passs(ubound(passs)+1)
Passs(ubound(passs)+1)=tmp
else
redim Preserve users(ubound(users)+1)
users(ubound(users)+1)=tmp
end if
nxt:
loop
close
for fo=1 to ubound(users)
if users(fo)=text1.text then goto Allo
'不分大小写if lcase(users(fo))=lcase(text1.text) then goto Allo
next
msgbox "No User"
end
allo:
if passs(fo)<>text1.text then msgbox "ErrPassWord":end
'不分大小写if lcase(passs(fo))<>lcase(text1.text) then msgbox "ErrPassWord":end
msgbox "Yes"

附:加、解密函数 运行一次加密、再运行一