它一直返回 null,我希望有人可以为我清理它,看看是否有更简单的方法可以做到这一点。我真的很想开始制作我的游戏。
Public Class frmLogin
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Application.Exit()
End Sub
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim FILE_NAME As String = "C:\Users\Nick\documents\visual studio 2010\Projects\LoginFixed\Accounts\" + Me.txtCUser.Text
If File.Exists(FILE_NAME) Then
Me.lblExists.Text = "Username has already been created!"
Return
End If
If txtCUser.Text.Length < 3 Then
Me.lblExists.Text = "Must have atleast 3 characters."
Return
End If
Dim writeFile As StreamWriter = File.CreateText("C:\Users\Nick\documents\visual studio 2010\Projects\LoginFixed\Accounts\" + Me.txtCUser.Text)
writeFile.WriteLine("User: " + Me.txtCUser.Text) ' user
writeFile.WriteLine("Pass: " + Me.txtCPass.Text) ' pass
writeFile.WriteLine("-------------------")
writeFile.Close()
End Sub
Private Function GetLine(ByVal fileName As String, ByVal line As Integer) As String
Try
If File.Exists(fileName) = False Then
Using sr As New StreamReader("C:\Users\Nick\documents\visual studio 2010\Projects\LoginFixed\Accounts\" + Me.txtUser.Text)
For i As Integer = 1 To line - 1
sr.ReadLine()
Next
Return (sr.ReadLine())
sr.Close()
End Using
End If
Catch ex As Exception
Return ex.Message
End Try
End Function
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim FILE_NAME As String = "C:\Users\Nick\documents\visual studio 2010\Projects\LoginFixed\Accounts\" + Me.txtUser.Text
If File.Exists(FILE_NAME) And Me.txtPassword.Text = (GetLine(FILE_NAME, 2).Substring(6)) Then
Me.lblLoggedIn.Text = "Logged"
ElseIf File.Exists(FILE_NAME) = False Then
Me.lblLoggedIn.Text = "You must create an account! Navigate to TabPage2."
End If
End Sub
结束类
这真的很有帮助。我不久前才开始使用vb,可能大约一两个星期。