Vb.net 当我尝试以教师身份登录时,会出现错误:EndOfStreamException Unhandled
以下是教师登录的代码,一旦运行并尝试使用有效帐户登录到系统,就会出现错误:EndOfStreamException Unhandled 如果您能帮助解决此问题,我们将不胜感激Vb.net 当我尝试以教师身份登录时,会出现错误:EndOfStreamException Unhandled,vb.net,Vb.net,以下是教师登录的代码,一旦运行并尝试使用有效帐户登录到系统,就会出现错误:EndOfStreamException Unhandled 如果您能帮助解决此问题,我们将不胜感激 Private Sub BtnTLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTLogin.Click If TxtUsername.Text = "" Or TxtPassword.Tex
Private Sub BtnTLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTLogin.Click
If TxtUsername.Text = "" Or TxtPassword.Text = "" Then
MsgBox("Please enter all the Login details for the account")
End If'
Filenamet = "TeacherAccounts.txt"
FileOpenStatusT = False
Dim Filefound As Boolean
Filefound = False
FileOpen(1, Filenamet, OpenMode.Input)
While Filefound = False
Input(1, Username)
Input(1, Password)
Input(1, namet)
Input(1, surnamet)
If Username = TxtUsername.Text And Password = TxtPassword.Text Then
Filefound = True
End If
End While
If Filefound = False Then
MsgBox("Username and Password were not a match,please try again")
Else
TeacherMenu.Show()
Me.Hide()
End If
FileClose(1)
End Sub
代码中存在一些潜在的问题。我发现可能与您的问题有关的是:
If TxtUsername.Text = "" Or TxtPassword.Text = "" Then
MsgBox("Please enter all the Login details for the account")
End If'
如果任一文本框为空,将显示消息框,但随后将继续尝试查找文件中的空用户名或密码
Dim Filefound As Boolean
Filefound = False
FileOpen(1, Filenamet, OpenMode.Input)
While Filefound = False
Input(1, Username)
Input(1, Password)
Input(1, namet)
Input(1, surnamet)
If Username = TxtUsername.Text And Password = TxtPassword.Text Then
Filefound = True
End If
End While
If Filefound = False Then
...
Filefound在while循环结束时永远不会为False。将找到匹配项,因此Filefound为True,或者找不到匹配项。由于没有结束文件检查,这可能会导致您看到的EndOfStream异常。由于您使用的是较旧的文件系统方法,因此可以使用EOF1检查您是否位于文件的末尾
Dim Filefound As Boolean
Filefound = False
FileOpen(1, Filenamet, OpenMode.Input)
While Filefound = False
Input(1, Username)
Input(1, Password)
Input(1, namet)
Input(1, surnamet)
If Username = TxtUsername.Text And Password = TxtPassword.Text Then
Filefound = True
End If
End While
If Filefound = False Then
...
您最好的选择可能是逐步完成循环,每次迭代都检查用户名和密码变量,以查看您是否正在阅读预期的内容。这是升级的VB6应用程序吗?它使用了很多旧的功能。一般来说,EndOfStreamException表示您试图读取超过文件结尾的内容。从这个例程的编码方式来看,只要文件中没有给定的用户名和密码,就会发生这种情况。我不认为这是一个升级的应用程序,我不太明白你的意思。学生登录工作正常,并且是刚刚更改的代码,以适应教师变量。文本文件包含输入的用户名和密码,因此在文件中存在。