Results 1 to 5 of 5

Thread: School Project - manipulating .txt files

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    4

    School Project - manipulating .txt files

    Any chance of some help with a school project?

    For a project I’ve been set the task of creating an athletics results and reporting system (combining another of my interests) in VB using random access .txt files.

    So far I’ve been able to write data to a file, read the data from a file, and select and read an individual record from a file using its record number. Really basic stuff I know.

    What I want to be able to do is store all the names of the competitors, event, heat, place and time in a single txt file, then from this extract the relevant data and sort all of the competitors in order by time.

    Here is what I already have:
    vb Code:
    1. Private Sub cmdSelect_Click()
    2.  
    3. 'DISPLAY CONTENTS OF FILE
    4.  
    5.  RecordLen = Len(TResults)
    6.  ChanNum = FreeFile
    7.  
    8. userin = InputBox$("Please enter a filename")
    9.  
    10. Filename = userin & ".txt"
    11.  
    12. Open Filename For Random As #1
    13.  
    14. Record = InputBox("Please enter the number of record which you wish to view", "View Record")
    15.  
    16. Get #ChanNum, Record, TResults
    17.  
    18. PicRn.Print TResults.name
    19.  PicRt.Print TResults.time
    20.  
    21.  Close #1
    22.  
    23.  End Sub
    24.  
    25. Private Sub CmdWrite_Click()
    26.  
    27.  RecordLen = Len(TResults)
    28.  'ChanNum = FreeFile
    29.  
    30. userin = InputBox$("Please enter a filename ")
    31.  
    32. Filename = userin & ".txt"
    33. Numero = InputBox("How many competitors in race?", "No People")
    34.  
    35. Open Filename For Random As #1
    36.  
    37. For Reccy = 1 To Numero
    38.  
    39.  Comp1.name = InputBox("Please enter Name for Lane " & Reccy)
    40.  Comp1.time = InputBox("Please enter Time for Lane " & Reccy)
    41.     picc1.Print (Comp1.name)
    42.     pict1.Print (Comp1.time)
    43. Put #1, Reccy, Comp1
    44.  
    45. Next Reccy
    46.  
    47.  Close #1
    48. End Sub
    49.  
    50. Private Sub CmdDisplayFile_Click()
    51.  
    52. 'DISPLAY CONTENTS OF FILE
    53.  
    54. Dim repeats As Integer
    55.  
    56.  RecordLen = Len(TResults)
    57.  ChanNum = FreeFile
    58.  
    59. userin = InputBox$("Please enter a filename ")
    60.  
    61. Filename = userin & ".txt"
    62.  
    63. Open Filename For Random As #1
    64.  
    65. For repeats = 1 To 6
    66.  
    67. Get #ChanNum, repeats, Comp1
    68.  
    69. picc1.Print Comp1.name
    70.  pict1.Print Comp1.time
    71.  
    72. Next repeats
    73.  
    74.  Close #1
    75.  
    76.  End Sub

    Any ideas?

    I know this seems awkward, using text files for a database, but the project has to use some of the stuff from the course and has to be of a specific level so I can’t use VB as a front end for a MS Excel database (I don’t think).

    Any help would be much appreciated
    Last edited by Hack; Apr 8th, 2008 at 08:20 AM. Reason: Added Code Highlight Tags

  2. #2
    Addicted Member
    Join Date
    Dec 2007
    Location
    Atlanta, Georgia
    Posts
    139

    Re: School Project - manipulating .txt files

    Quote Originally Posted by cleaco
    What I want to be able to do is store all the names of the competitors, event, heat, place and time in a single txt file, then from this extract the relevant data and sort all of the competitors in order by time.
    I have seen things like this 25 years ago, but they were bad programs. That's why god made relational data.
    You can still use text tables, but you will need to use a few of them and it will be a nightmare. If you can backend your code with an mdb or almost anything other than text you will be way ahead.
    Can you do this?
    Last edited by GRichG; Apr 8th, 2008 at 10:03 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    4

    Re: School Project - manipulating .txt files

    Quote Originally Posted by GRichG
    I have seen things like this 25 years ago, but they were bad programs. .... If you can backend your code with an mdb or almost anything other than text you will be way ahead.
    Can you do this?
    Yeah, I realise it probably isn't the best way (at all!) to do things!

    I would use a backend database in Access but I'm not sure its up to the required level, or is it? I have to create something of reasonable complexity and use stuff from the computing course. Would using a backend database still be "complex" enough do you think but at the same time easy enough to do?

    Thanks

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    4

    Re: School Project - manipulating .txt files

    Sorry, I realise the original post maybe wasn't the clearest!

    I know how to write to txt files using a record. After data has been written to a txt file I need to be able to read the data from the file back in to some other data structure in the program so that I can sort the data. I can read the data back into a record but what sort of data structure do you think would be the best, and is it able to be sorted?

    This data can be read back into records, but how then do I select the data I want to sort, and sort it.
    For Example:
    Name Person A Person B Person C Person D Person E
    Heat 1 1 1 2 2
    Time 10 15 20 12 18

    I want to select the people in heat 1 (Person A, B and C) and then sort them by Time.What would be the best way to do this?

    Or more simply, if the competitors are already in order by time (with the fields Name, Heat, Position, Time) when written to file, how would I select all the competitors in who have Heat = 1?

    Thanks

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    4

    Re: School Project - manipulating .txt files

    Thanks for your help. I've decided to change the way I'm doing things aa using MS Excel and VBA to create a solution which is proving to be much more sensible.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width