Hi, DaniWeb members,

Recently i've been developing a progam that will read in a player database that is stored in plain text if the folling format

name ,age,score,date played

So far i have managed to read in the file and caculate the number of players in the database by

Do Until EOF(1)
    aboutPlayer = LineInput(1)
                    ' For Each line In aboutPlayer
                    numPlayers = numPlayers + 1
                    playerDeatils = aboutPlayer.Split(",")
                    If EOF(1) Then
                        'Removes the top line counting as a player
                        numPlayers = numPlayers - 1
                    End If
                Loop

The program so far dose
1: read in text file
2: count the number of lines
3: -1 for the header
4: split lines into sigle lines

And also manged to turn all the lines that have been read into single lines using the playerDetails = aboutPlayer.split(",")

So im woundering how to trun these split lines into an array of records.

I do have a base structure in place for single elementes to be stored, the problem is how to turn the stringsplit into the array of records within the structure.

Module Module1

    'Describe the information read in form the "playerDB.txt"
    Structure playerInfo
        Dim Name As String
        Dim Age As String
        Dim Score A String
        Dim datePlayed As String
      End Structure

    Public aboutPlayer As String
    Public playerDeatils As String
    Public numPlayers As Long = 0
    Public onPlayer(0 To numPlayers) As playerInfo
    Public Player As Short = 0
End Module

Any help will be appricated
Thanks
KingGold171

I havent used DaniWeb for a while, so this post will be edited a few times to use the code snippit tools correctly and clean up the layout

If you store the player name as part of the structure then you have to do a search to find the record corresponding with a particular name. If you use a dictionary then you can get at any player by indexing with the player name.

    Structure PlayerInfo
        Dim Age As String
        Dim Score As String
        Dim datePlayed As String
    End Structure

    Private Sub btnPlayers_Click(sender As System.Object, e As System.EventArgs) Handles btnPlayers.Click

        Dim players As New Dictionary(Of String, PlayerInfo)
        Dim details() As String = "Jim,53,11209,2012-06-02".Split(",")

        Dim info As New PlayerInfo
        info.Age = Trim(details(1))
        info.Score = Trim(details(2))
        info.datePlayed = Trim(details(3))
        players.Add(Trim(details(0)), info)

    End Sub

To refer to the stats for a particular user you can do

    MsgBox(players("Jim").Age)

You can check if a player exists by

    If players.ContainsKey("Jim") Then
commented: The base of the dictionary storage helped implemted for the use within a structure. +0

Thank you, Reverand Jim,
Ican see how the structure and the theory of the dicotnary stroage works as apposed to a array of reconds in a structure, so i will try and implment into the starting structure, as it will need to more onto the next players details on btnNext_click and go back on btnPrevious_Click. and then hopefully if the design works it it also work with the display lables.

The use of the program wont be needed to check is player exists as this is where how the playerDB is created it just ned to read, split, stored and displayed.

If you would like the full project folder please let me know.

Thanks
KingGold171

Dim info As New PlayerInfo
info.Age = Trim(details(1))
info.Score = Trim(details(2))
info.datePlayed = Trim(details(3))
players.Add(Trim(details(0)), info)

Reverend Jim
Ok after using you code structure as a base I have managed to produce a work design of what i was wanting the program todo.

 Module Module1
'Describe the information read in form the "playerDB.txt"
Structure playerInfo
    Dim playerName As String
    Dim playerAge As String
    Dim playerScore As String
    Dim datePlayedAs String

End Structure
Public aboutPlayer As String
Public playerDetails As String
Public numPlayers As Long = 0
Public onPlayer(0 To numPlayers) As playerInfo
Public Player As Short = 0
 End Module





  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Store the file path location for debug folder
    Dim file_path As String = My.Application.Info.DirectoryPath()

    'Check to see if file exists
    If System.IO.File.Exists(file_path & "/playerDB.txt") Then

        'Open if file exists = true
        FileOpen(1, file_path & "/playerDB.txt", OpenMode.Input)

        'Read in information from the text file and store
        'Loop until end of file

        ' ''Dim playerDetails() As String
        Do Until EOF(1)
            Dim NumberOfPlayer As Integer
            Dim aboutPlayer(0 To numPlayers) As String
            For d = 0 To NumberOfPlayer
                Dim details() As String = LineInput(1).Split(",")
                onPlayer(Player).playerName = Trim(details(1))
                onPlayer(Player).playerAge = Trim(details(2))
                onPlayer(Player).playerScore = Trim(details(3))
                onPlayer(Player).datePlayed = Trim(details(4))

            Next d

        If EOF(1) Then
           'Removes the top line counting as a player
            numPlayers = numPlayers - 1
        End If
        Loop
        'Close the file
        FileClose(1)
    Else
        'If the file dose not exist or cannot be found then
        'display error message
        MsgBox("File does not exist")
    End If

    lblName.Text = onPlayer(Player).playerName
    lblAge.Text = onPlayer(Player).playerAge
    lblScore.Text = onPlayer(Player).playerScore
    lblDatePlayed.Text = onPlayer(Player).datePlayed


    lblNumPlayers.Text = numPlayers
End Sub

All thats left todo now is to implment the next and back buttons to display the lat and nexts players info from the structure. normally this is just

btnNext_click
lblplayerName = onPlayer(player).name + 1

btnPrevious_click
lblplayerName = onPlayer(player).name + 1

I will have play and see if i can get it to work.

Thanks
KingGold171
[RESOLVED]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.