954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Reading Multiple lines of Code and Storing them in "Records"

Hello,

I'm Rather new to coding, and It seems like I skipped some of the basics, and jumped in the deep end.

I'm having a couple of problems, as I have an ordinary text file called "Orders", and this file stores Orders, placed by users of my program.

The Users write to the Orders.txt file, 5 lines per Order, For Example :

Item Name
Item Quantity
UserName (Of user)
House Number (Of user)
Post Code (Of user)

i.e. (Three Orders Bellow)

PlayStation
2
Tobyjug2222
4
CH75LW
ToyCar
6
Tobyjug1111
5
CH64LW
Holiday
1
TobyJug3333
55
CH14JD

I want to be able to read this file, and store the data in Records, and having a form with a Previous/ Next button, displaying these orders.

Also on that form, a Delete button which will delete the order from the file when it has been processed.

Thanks a lot, Toby.

Tobyjug2222
Newbie Poster
17 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

You will need a class with all of these fields defined.
Like your last project where you used a KeyValuePair, you will need to create a class.
Each field of the "record" will be populated by a row in the file.
When you've collected 5 rows, add that record to a master.

The master can be a List or Array or Dictionary of Orders

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

I suggest that you change the file format so that all info for an order is on the same line. Pick a character like "|" to separate the fields. Each line can be parsed into separate fields by

Dim fields() As String = line.Split("|")

It makes the file I/O much easier.

Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

Thanks for your responses, although:

@thines01, I'm not exactly sure how to do that, I sent you what I interpreted to a private message.

@Reverend Jim, I tried to do this, although the command "Line" is supposedly not supported any more (what my VB told me) ;)

Tobyjug2222
Newbie Poster
17 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

perhaps the code would have been clearer if I had included

dim line as string = "PlayStation|2|Tobyjug2222|4|CH75LW"

then the code

Dim fields() As String = line.Split("|")

would result in fields as an array of 5 elements where

fields(0) = "PlayStation"
fields(1) = "2"
fields(2) = "Tobyjug2222"
fields(3) = "4"
fields(4) = "CH75LW"

Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: