Hi,

For a school assignment, I have to make a game of BlackJack using VB2008 Express. I have decided that in the login screen, the user will select his name from a listbox, and then type his password into a text box in order to get to the game screen. He can then play the game of BlackJack in the game screen. After he exits out of the game screen, his details (wins, losses, draws, cash etc.) will all be saved into a text file. This all works fin except when the gets to the login screen, there are 3 random characters () in front of his name (Eg if his name is bob, it will display as Bob). Here is my code for the game screen.

Dim FindInfo, NewInfo As String
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        FindInfo = lblPlayerName.Text + vbCrLf + lblPassword.Text + vbCrLf + lblWins.Text + vbCrLf + lblDraws.Text + vbCrLf + lblLosses.Text + vbCrLf + lblYourCash.Text + vbCrLf + lblLastPlayed.Text
        End Sub
Private Sub frmGame_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        NewInfo = lblPlayerName.Text + vbCrLf + lblPassword.Text + vbCrLf + lblWins.Text + vbCrLf + lblDraws.Text + vbCrLf + lblLosses.Text + vbCrLf + lblYourCash.Text + vbCrLf + System.DateTime.Now
        'Save player info to text file
        For Each TextFile As String In System.IO.Directory.GetFiles(Environment.CurrentDirectory, "document.txt")
            Dim A As String = My.Computer.FileSystem.ReadAllText(TextFile)
            A = A.Replace(FindInfo, NewInfo)
            My.Computer.FileSystem.WriteAllText(TextFile, A, False)
        Next
    End Sub

Here is he code for reading the text file into the appropriate listbox. (Only lstNames will be visible)

Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Name, Password, Wins, Draws, Losses, Cash As String
        Dim LastPlayed As String
        Dim Filenum As Integer = FreeFile()
        FileOpen(Filenum, "document.txt", OpenMode.Input)
        Do Until EOF(Filenum)
            Name = LineInput(Filenum)
            lstNames.Items.Add(Name)
            Password = LineInput(Filenum)
            lstPassword.Items.Add(Password)
            Wins = LineInput(Filenum)
            lstWins.Items.Add(Wins)
            Draws = LineInput(Filenum)
            lstDraws.Items.Add(Draws)
            Losses = LineInput(Filenum)
            lstLosses.Items.Add(Losses)
            Cash = LineInput(Filenum)
            lstCash.Items.Add(Cash)
            LastPlayed = LineInput(Filenum)
            lstLastPlayed.Items.Add(LastPlayed)
        Loop
    End Sub

Any Suggestions?

Hi,

For a school assignment, I have to make a game of BlackJack using VB2008 Express. I have decided that in the login screen, the user will select his name from a listbox, and then type his password into a text box in order to get to the game screen. He can then play the game of BlackJack in the game screen. After he exits out of the game screen, his details (wins, losses, draws, cash etc.) will all be saved into a text file. This all works fin except when the gets to the login screen, there are 3 random characters () in front of his name (Eg if his name is bob, it will display as Bob). Here is my code for the game screen.

Dim FindInfo, NewInfo As String
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        FindInfo = lblPlayerName.Text + vbCrLf + lblPassword.Text + vbCrLf + lblWins.Text + vbCrLf + lblDraws.Text + vbCrLf + lblLosses.Text + vbCrLf + lblYourCash.Text + vbCrLf + lblLastPlayed.Text
        End Sub
Private Sub frmGame_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        NewInfo = lblPlayerName.Text + vbCrLf + lblPassword.Text + vbCrLf + lblWins.Text + vbCrLf + lblDraws.Text + vbCrLf + lblLosses.Text + vbCrLf + lblYourCash.Text + vbCrLf + System.DateTime.Now
        'Save player info to text file
        For Each TextFile As String In System.IO.Directory.GetFiles(Environment.CurrentDirectory, "document.txt")
            Dim A As String = My.Computer.FileSystem.ReadAllText(TextFile)
            A = A.Replace(FindInfo, NewInfo)
            My.Computer.FileSystem.WriteAllText(TextFile, A, False)
        Next
    End Sub

Here is he code for reading the text file into the appropriate listbox. (Only lstNames will be visible)

Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Name, Password, Wins, Draws, Losses, Cash As String
        Dim LastPlayed As String
        Dim Filenum As Integer = FreeFile()
        FileOpen(Filenum, "document.txt", OpenMode.Input)
        Do Until EOF(Filenum)
            Name = LineInput(Filenum)
            lstNames.Items.Add(Name)
            Password = LineInput(Filenum)
            lstPassword.Items.Add(Password)
            Wins = LineInput(Filenum)
            lstWins.Items.Add(Wins)
            Draws = LineInput(Filenum)
            lstDraws.Items.Add(Draws)
            Losses = LineInput(Filenum)
            lstLosses.Items.Add(Losses)
            Cash = LineInput(Filenum)
            lstCash.Items.Add(Cash)
            LastPlayed = LineInput(Filenum)
            lstLastPlayed.Items.Add(LastPlayed)
        Loop
    End Sub

Any Suggestions?

if ya problem is the listbox,
Just click the property called Items|(Collection)
then ya have to enter each player's name
Press enter to begin the new line
wish it will work...
for each player then click OK.

This article has been dead for over six months. Start a new discussion instead.