Computing.Net > Forums > Programming > Txt doc and Dat files using VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Txt doc and Dat files using VB

Reply to Message Icon

Name: basicdos
Date: January 3, 2008 at 17:35:20 Pacific
OS: WinMe/XP
CPU/Ram: int III / 255Mb
Product: 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.

TIA



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: January 3, 2008 at 18:01:11 Pacific
Reply:

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.


0

Response Number 2
Name: Razor2.3
Date: January 4, 2008 at 19:06:07 Pacific
Reply:

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...


0

Response Number 3
Name: basicdos
Date: January 5, 2008 at 13:41:00 Pacific
Reply:

Thanks for the replies guys

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?

Thanks for the input


0

Response Number 4
Name: wizard-fred
Date: January 5, 2008 at 14:40:02 Pacific
Reply:

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.


0

Response Number 5
Name: basicdos
Date: January 6, 2008 at 16:30:03 Pacific
Reply:

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 ?

Thanks


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: January 6, 2008 at 17:32:19 Pacific
Reply:

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.


0

Response Number 7
Name: basicdos
Date: January 7, 2008 at 17:45:27 Pacific
Reply:

Thank You Both Very Much

I think Ill do a little reading up and experimenting with the records and arrays


Rob


0

Response Number 8
Name: wizard-fred
Date: January 9, 2008 at 21:12:05 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Txt doc and Dat files using VB

Opening specific files using vb www.computing.net/answers/programming/opening-specific-files-using-vb-/4263.html

VB Formatting Arrays for .dat file www.computing.net/answers/programming/vb-formatting-arrays-for-dat-file/15952.html

vb read and write file www.computing.net/answers/programming/vb-read-and-write-file/6672.html