vb中关于逐行对比txt文本数据的问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 16:41:16
Private Sub Form_Load()
a = GetSetting("hlmm", "sys", "syskey")
Open "c:\123.txt" For Input As #1
Line Input #1, nextline '1行读入
x = nextline
Line Input #1, nextline '2行读入
y = nextline
If Val(a) <> Val(x) And Val(a) <> Val(y) Then
Unload Me
Form2.Show
Else
Unload Me
Form0.Caption = "你的注册码已被列入黑名单"
Form0.Show
Close #1
End If
End Sub

'代码中a是读取注册表中的字符串,X和Y是读取c:\123.txt中的第一行和第二行,谁能帮我完善一下,如果123.txt有N行该怎么比较啊

Private Sub Form_Load()
Dim flag As Boolean
a = GetSetting("hlmm", "sys", "syskey")
Open "c:\123.txt" For Input As #1
Do Until EOF(1)
Line Input #1, nextline '1行读入
x = nextline
If Val(a) = Val(x) Then
Unload Me
Form0.Caption = "你的注册码已被列入黑名单"
Form0.Show
flag = True
Exit Do
End If
Loop
Close #1
If flag = False Then
Unload Me
Form2.Show
End If
End Sub

'有什么不妥的请给我留言。

有一个办法,呵呵
在文件第一行写上行数,然后读取它并转换成integer,之后把它赋值到一个字母(如n)上,限制读取1到n行是不是会好一些..