How would i read this text file in
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: How would i read this text file in

  1. #1
    Join Date
    Jan 2011
    Posts
    8

    How would i read this text file in

    I am trying to create a simple banking system that reads in data from a text file.

    Attached is a copy of the text file and another text file explaining the layout.

    How would i read this information in. I need a class for customers, accounts and transactions and an arraylist to store the information.

    What i know is that the customer class will have 14 items in it. However what confuses me is that a customer could have 2,3 or more accounts with a handful of transactions on each account. How would i read this information in.

    Attached is the Text files.
    Attached Files Attached Files

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,247

    Re: How would i read this text file in

    Use a TextReader and read the file line by line.

    There are about 3 different record types in the file: customer, account, and transaction. The instructions tell you that each record type is a fixed length and that there is a field that tells you the number of records.

    Customer contains Account which contains Transactions. So the Customer record will contain a field that tells you how many account records to read. Each account record will tell you how many transactions for that account.

    Starting at the beginning of the file you read the first account record info line by line until you get to the #0f accounts field you put that into a Customer class object, then given the #ofaccounts, you start reading them into Account class objects until you hit the #oftrans and then start reading the transactions and so on.

    You'll have to create objects of each type with properties and create the objects and set the properties.

    It's a good homework assignment.

  3. #3
    Join Date
    Jan 2011
    Posts
    8

    Re: How would i read this text file in

    Thanks for the reply.

    How would i tell it to start reading from the right point and tell it to stop reading when it reaches the end of accounts.

    I have attached a text file with the code i have got at the moment which reads upto the end of all the customer details and stores it into an array.

    Im super confused a the moment. Any help really appreciated.
    Attached Files Attached Files

  4. #4
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,247

    Re: How would i read this text file in

    Quote Originally Posted by gunnerone View Post
    How would i tell it to start reading from the right point and tell it to stop reading when it reaches the end of accounts.
    Because each record type is a fixed length and each record type has a count of the next record, all you need to do is keep track of the number of lines to read.

  5. #5
    Join Date
    Oct 2010
    Posts
    42

    Re: How would i read this text file in

    Hey, I think you need to create a pattern for each lines of text that you want to read...

  6. #6
    Join Date
    Jan 2011
    Posts
    8

    Re: How would i read this text file in

    Hi thanks for the replys,

    I have got this at the moment. However the transaction output seems to output only the last transaction for the customer. I think it goes through to the end and overwriting the previous transactions. How do i stop it from over writing and returning each transaction loop.

    Attached is a zip of my program so far. (The list box and button is used just so i can see what is happening).
    Attached Files Attached Files

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center