Name: basicdos Date: January 3, 2008 at 17:35:20 Pacific Subject: Txt doc and Dat files using VB OS: WinMe/XP CPU/Ram: int III / 255Mb Model/Manufacturer: E -machine
Comment:
Hello all Happy New Year
Ive created a telephone number and info program it works fine but here is the question. I wrote this program and used a simple text file as the storage space for all my information. I cycle through it using readline statements I had no problem with this method writing, appending and deleting all works fine. the problem I encountered is that the file had an over run of some type. I surmised the problem to be a limit to the length of simple text files. I did some experimentatiion and found I can very easily save the info as a simple doc file there doesnt seem to be a problem with length here...Am I Right?
Ok but I realize this system im using is amateurish, but it does work. I Should probably be using arrays in Ram and saveing to disk as a .dat file but im not really sure what is going on with dat files.
any simple explaination or sugestion of how to work with a dat file is appreciatted.
Im looking for the overall concept of what they are as compared to the text file.
my confusion is that, as we all are familiar with working with text files and doc files. we open and close them in everyday computing, Im just not used to working with dat files or fully understand why a dat file would be better then saving as a doc file.
By your description a 'dat' file is a database or random access file. The advantages is that you can add, modify, or delete a record in the file without rewriting all of it. When the file becomes larger you see the advantages. Some study of databases might give you insight of the management of how they handle data.
I did some experimentatiion and found I can very easily save the info as a simple doc file there doesnt seem to be a problem with length here...Am I Right? Depends. If you're launching MS-Word, then yes (but it's quite sloppy). If you're just saving the text file as a .DOC, then no. Or we could both be wrong; I can't find any documentation on the limits of text files in VB6.
Im looking for the overall concept of what they are as compared to the text file. Instead of taking binary data and turning them into human readable text, it keeps the data as binary data.
fully understand why a dat file would be better then saving as a doc file. Well, you're requiring your client to have MS Word installed and operating correctly. That adds overhead, decreases speed, and can leave errant copies of WINWORD.EXE floating in memory if your program crashes.
Compared to text files, the equivalent binary file tends to be smaller; an Integer can be up to 5 bytes in a text file, but will always take up 2 bytes in a binary file. I also suspect binary files have a larger upper limit, but as I said, I can't find any documentation to back up that statement up.
any simple explaination or sugestion of how to work with a dat file is appreciatted. Instead of Open "whatever" For [Input|Output] As #1 use Open "whatever" [For Random] As #1 Len = Len(Rec) Then, at the module level, add this:
[Private] Type Rec Name As String * 5 Phone As String * 10 'I suggest you separate 'formatting from data; increase as needed 'if you disagree. Note: All strings must be 'of fixed size. 'Whatever else you store goes here. End Type
Then, instead of Input #1/Write #1, use Put #1,,/Get #1,,. Easy, no?
EDIT: Sometimes I'm surprised English is my first language...
No im not opening winword at all. I just replace the file extention when the file is created by the open command -with open as .doc instead of open as .txt and the file is created seems to use the same commands as if i opened a text file
The program worked fine and I accumulated a long list of contact information, then one day it got scrambeled and wouldnt take any more info and I received an end of file message the program is dependent upon the line count as multiples of each saved file such as every fifth line would be a first name, every sixth line a zip code etc... so an uneven save of lines made the whole file out of whack.. because I used the line count to save and retreive information and to re-alphabetize the list when new entries were made
:::I Should have said this first:::
"What Im trying to do"... is create a voting program that saves the users choice to a file on the hard drive and im trying to decide the best way or file type to use with visual basic programming to be run on a windows computer.
the text file system was limited by length ...or do you think it was just a programming glitch that took a while to show up?
the doc file system is limited to Windows Word
Ive never worked using dat or bin files etc
I used the text file because they were the easiest for me to understand and work with.
I can work with and learn the dat file, record and array commands Do you think that would be the best choice?, or is there another method You guys sugest?
The .txt file is probably limited to the maximum size of the version of the OS. Don't know why you lost sync. I have used BASIC to handle files to about 10 MB in size. All files are bin. Txt files are just a special case. You probably should learn random files next. Fewest changes to your existing programs. You can even convert your existing data.
Ok, so by working with random files you mean to open the file as random.
please Let me know if i have the following steps right...
create an array determine its record structure put info in it save it as???? a dat file to hard disk same as I would a text file? and then open it same as i would any other file, for later use?
And this file if undimentioned array should be able to handle as much data as i ever put into it ?
Your order's off. You should first create your structure, and make an array of that.
Also, you would open the file to read with the same syntax you used to open the file to write it.
Finally, I suggest you make the first entry specify the amount of data in the file. That way, (a) you know how large to make your array, and (b) you have a (very) crude method of detecting corruption [FileSize / (Len(Rec) + 1) = FirstEntryInFile]. Unless you want to make a self-growing array class. That's possible, too. Even then, the size indicator would be a good idea.
You don't neec to dimension an array to contain the whole file. In a database or random file you typically only handle one record at a time. A pointer keeps track of the current record.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE