Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim FILE_NAME As String = Cashierpath
System.IO.File.Exists(FILE_NAME) ' current
Dim objReader As StreamReader
Dim user As String = TextBox1.Text
Dim password As String = TextBox2.Text
Dim check As String
'Global Variable
'Dim DirPath7 As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Scrap Data\Cashier Info\Cashiers\")
For Each filename As String In IO.Directory.EnumerateFiles(DirPath7, "*.txt")
Dim fName As String = IO.Path.GetFileName(filename)
If user = fName & ".txt" Then
objReader = New StreamReader(fName)
check = objReader.ReadToEnd()
If password = check Then
MessageBox.Show("Welcome " & user & "!")
Close()
My.Forms.Home.Show()
Else
MessageBox.Show("Username or Password is incorrect")
End If
End If
Next
End Sub
当用户在文本框中输入“用户名”和“密码”并单击此按钮时,我希望此按钮检查是否存在带有输入用户名名称的文本文件,以及是否存在具有该用户名的文件然后必须阅读它,并检查密码是否与文件中的字符串匹配。如果不匹配,则必须显示一个消息框,提示“用户名或密码不正确”,但是当我单击此按钮时,什么也没有发生。也没有错误消息出现。有人可以看一下我的代码,然后告诉我我做错了什么吗?
Dim objReader As StreamReader
Dim user As String = TextBox1.Text
Dim password As String = TextBox2.Text
Dim check As String
Dim fname = Path.Combine(DirPath7, String.Format("{0}.txt", user))
If File.Exists(fname) Then
Using objreader As New StreamReader(fname)
'objReader = StreamReader(fname)
check = objreader.ReadToEnd()
password = check
MessageBox.Show("Welcome " & user & "!")
Close()
My.Forms.Home.Show()
End Using
Else : MessageBox.Show("file not found, no user exists")
End If
删除了多余的“ .txt”
添加了“使用”。。。“最终使用”
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句