Computer Science Canada text file help please (i stil need help)saving arrays of #'s |
Author: | skier [ Thu Nov 11, 2004 6:26 pm ] |
Post subject: | text file help please (i stil need help)saving arrays of #'s |
i am trying to make a database and i am wondering if there is any way to save info to a file so that when you close the program it saves everything you changed, then when you reopen the database it shows the saved in fo and allows you to modify it. |
Author: | wtd [ Thu Nov 11, 2004 6:30 pm ] | ||
Post subject: | |||
Absolutely. This is known as a "flat file database". The basic format is one record to a line. Consider a piece of info about an employee for a payment system. You have name, hours worked, and payrate. So each line in your file looks like:
Then when you want to get the data back, you read in the line and split it up into its three components, and store each component in the right place. |
Author: | skier [ Thu Nov 11, 2004 6:39 pm ] |
Post subject: | |
you lost me at "This is known as a "flat file database". " |
Author: | wtd [ Thu Nov 11, 2004 6:44 pm ] |
Post subject: | |
Well, real relational databases (Postgres, Oracle, DB2, etc.) don't just use text files. But you can use text files for this, as long as your data is relatively simple. Real databases have "records", which store a bunch of info about one "thing". Text files have lines, which can function similarly. |
Author: | skier [ Thu Nov 11, 2004 6:45 pm ] | ||
Post subject: | |||
heres what i have:
Now how do i save things to a text file so they can be called later(when program is run next) |
Author: | wtd [ Thu Nov 11, 2004 6:50 pm ] |
Post subject: | |
Well, looking at your code, there are a few things you should learn (or learn more about) first:
Hit the Turing Tutorials forum and do some research. |
Author: | Mr. Glib [ Thu Nov 11, 2004 6:50 pm ] | ||||
Post subject: | |||||
You'll probably want to store your info in an array of records. User defined types are going to be very handy here.
And your record for person 1 will be stored to a binary file. To retrieve it and add to it...
|
Author: | wtd [ Thu Nov 11, 2004 6:57 pm ] |
Post subject: | |
Interesting approach, though a plain text serialization of the data would be rather more flexible. Ideally, you'd use something like YAML, but writing a decent YAML interface for Turing would be an exercise in masochism. |
Author: | skier [ Thu Nov 11, 2004 7:52 pm ] |
Post subject: | |
i have no idea what your talkin about. is there a tutorial about this stuff or can u explain about this a little more binary file? record? |
Author: | wtd [ Thu Nov 11, 2004 8:05 pm ] |
Post subject: | |
skier wrote: i have no idea what your talkin about. is there a tutorial about this stuff
or can u explain about this a little more binary file? There are two kinds of files on a computer: text and binary. Both are made up of bits. That's just how computers think. The difference is basically in how the files are terminated. A text file generally terminates when the processors runs into a byte (set of 8 bits) that's equal to zero. "Binary files" don't have that limitation. The trouble with binary files is that you can't just open them up in a text editor and see what's going on. Text files are much more portable between different computers and different applications, and thus far more flexible. skier wrote: record?
A record is essentially just a set of related pieces of data that, when considered together, describe a single "thing". |
Author: | skier [ Thu Nov 11, 2004 8:20 pm ] |
Post subject: | |
so how do i go about seting up a text file |
Author: | zylum [ Thu Nov 11, 2004 8:59 pm ] | ||
Post subject: | |||
|
Author: | skier [ Thu Nov 11, 2004 9:56 pm ] |
Post subject: | |
how do i get it to write to the text file is there a tutorial for this |
Author: | Hikaru79 [ Thu Nov 11, 2004 10:25 pm ] |
Post subject: | |
Read zylum's post above. That's just what his program does. |
Author: | Mr. Glib [ Thu Nov 11, 2004 10:29 pm ] |
Post subject: | |
wtd wrote: Interesting approach, though a plain text serialization of the data would be rather more flexible.
True...I like have the option of dumping the entire record to the .bin file without having to write each individual component. I also like the flexibility the binary file gives you with the tell statement to keep track of where individual records are located for editing later on. |
Author: | Mr. Glib [ Thu Nov 11, 2004 10:48 pm ] | ||||
Post subject: | |||||
skier wrote: record? skier, a record is another data type much like arrays and variables. A record has more than one component. A variable or an array holds just one type of data (strings, boolean, int, real). A record can hold all of those types. They're really usefull when you have data of disimilar types that are related to one another. Take for instance your data base that you are planning. Each person will have a record that consists of different types of info. Lets say we are making a student database. Each student's record would be comprised of a student #, last name, first name, age, sex, grades, and so on...To have seperate arrays or variables to hold all of these pieces of info (fields) would be really cumbersome. Wouldn't it be hand to have a data type that could hold all of these? Hence the record!
If you want you can create your own user defined data types. Turing gives us a few but we can make more than suit our needs. In the case above, I'm probably gonna have about 1000+ students at my school. I sure as hell don't want to declare 1000 different records!!! I could really use an array or a list of 1000 students. The problem is that I need to create a new data type. Using the "type" key word you can make your own data types! Oh yes! The power! :Mr. Glib salivates:
If you're not sure what an array does...well, it is a data type that holds a list of similar data. In the case above the array is holding all students data type. The (1) tells the program that the info you are typing goes in the first spot. Replace all the (1)s with (2)s and then you'll be assigning values to the 2nd spot of the array. Thus, each kid has its own spot in the array. Notice how much cleaner this is than using a bunch of related arrays? Okay, I hope this helps...I'm going to bed! |
Author: | skier [ Fri Nov 12, 2004 8:54 am ] |
Post subject: | |
im starting to get this but i have hit a wall, in the program zylum wrote he used words to be saved in the text file. i need to do it for numbers to. i have got it to acsept variables with a single number but it wont save and array full of numbers any thoughts. also when you create the text file it some times goes to my desktop and sometimes goes to my documents. what part of the code decides that. |
Author: | Mr. Glib [ Fri Nov 12, 2004 6:09 pm ] | ||||
Post subject: | |||||
skier wrote: im starting to get this but i have hit a wall, in the program zylum wrote he used words to be saved in the text file. i need to do it for numbers to. i have got it to acsept variables with a single number but it wont save and array full of numbers any thoughts.
Easy... instead of put : stream , "lotsa text" re-write it to appear as:
Turing stores the data file in the same folder as your source code. If you want to change the path of this file...
Does that help? |
Author: | skier [ Fri Nov 12, 2004 6:22 pm ] |
Post subject: | |
yep thanks |