1

それは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 を始めたのはつい最近のことで、おそらく 1 週間か 2 週間ほど前です。

4

1 に答える 1