我已经在文件的一行中添加了多个字符串,因此它们被链接在一起,我尝试了多种方式,例如使用循环,我想知道是否有人可以帮助我,谢谢。
文件中的:swagman(用户名),samfisher34(密码),sam fisher(全名)
Private Sub btn_login_Click(sender As Object, e As EventArgs) Handles btn_login.Click
Dim Student As New StreamReader("student.txt")
Dim newline As String
Dim login As Boolean
Dim line1 As String
Dim line2 As String
' Reads the files to a string and write the string to the console.
Dim count As Integer = 20
For i = 1 To count
newline = Student.ReadLine
If txt_login.Text = newline And txt_password.Text = newline Then
'Checks to see if text is the same in the Files.
login = True
End If
If login = True Then
Me.Hide()
StudentMenu.Show()
End If
Next
If login = False Then
MsgBox("login or password is incorrect")
End If
Student.Close()
End Sub
答案 0 :(得分:0)
这是我做的一个非常基本的代码示例:
首先,您需要为StreamReader导入System.IO
Dim objStreamReader As StreamReader
Dim strLine As String
objStreamReader = New StreamReader(File)
Dim splitresult As Array
'read the file line for line
Do Until objStreamReader.Peek = -1
strLine = objStreamReader.ReadLine
'split the results (user,pwd,name)
splitresult = strLine.Split(",")
If splitresult(0) = user Then
If splitresult(1) = pwd Then
MsgBox("Welcome " & splitresult(2))
End If
Loop
另外,请不要将您的密码以纯文本形式存储。