text files and arrays...
Author |
Message |
Duncan
|
Posted: Thu May 01, 2008 2:14 am Post subject: text files and arrays... |
|
|
Hey guys
I have a little project on my hands and im trying to get this text file stuff to work. What im tryin to do is take information i get with variables, put that information into a text file with a difinitive name, then at a later date bring up that same file and put the information back into variable format from where is came. Its for work orders at my shop and this sure would beat haveing to write everything down. for example
Work order : 195487
Name : Joe Blow
Address: 123 Stupid Street
Phone: 999-555-5412
and so on and so forth
so i want to take just the information, not the name and phone number words, just the information and save it as a text file using the work order number at the file name. Then say i want to see it up again, i punch in the number and poof, there everything is ready to edit. any helpwould be awesome, just stuck on the read andwrite and converting proccess. ill post what i have so far too'
Thanks guys
Duncan
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
NewOrder.t |
Filesize: |
2.79 KB |
Downloaded: |
90 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Expirant
|
Posted: Thu May 01, 2008 7:30 am Post subject: Re: text files and arrays... |
|
|
What you've done so far seems to work. Now you're just having problems reading everything back in from the text file?
In the current format of your file, you could just open the text file with a certain variable in mind (Name/Number/Address/Order) then use the get command repeatedly. For example, you have a text file that looks like this:
Quote:
Name
Phone Number
Address
Order Number
To get 'Address' from that file, you could do this:
code: |
for i : 1 .. 3
get : fn, foo : *
end for
put foo
|
Or change the 3 to whatever line the string you want exists on.
Alternatively, you could change the entire layout of your program to include records, or even classes (and linked lists too, though those are slightly more complicated, so I'll avoid using them in my example). There should exist a tutorial for both of these for Turing. If you use a record, however, it makes what you'd like to do extremely simple. If I have some time later I'll find those tutorials and write something up for you.
EDIT: I've added an attachment using a class, record, and read/write. If you can learn to understand those concepts, it will make creating a database much easier, both for coding and the format of your data files.
Classes: http://compsci.ca/v3/viewtopic.php?t=10904&highlight=objects
Records: http://compsci.ca/v3/viewtopic.php?t=2325&highlight=records
File I/O (including read/write): http://compsci.ca/v3/viewtopic.php?t=12972&highlight=read+write
Cheers,
Expirant
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Example.t |
Filesize: |
3.46 KB |
Downloaded: |
78 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|
|