Page 1 of 1
Help! with corruption of random file
Posted: Thu Mar 10, 2005 1:44 pm
I'm using Qbasic with a copyright date of 1992 (a bit old). PC with Windows ME. Haven't had any problems with my Qbasic programs until recently.
Problem is with some random-access files of numbers I've created. Typical file is 400 records long, each one consisting of 10 variables, most single-precision. (You can see, I don't want to have to recreate these files if I don't have to.)
The last time I tried to open the files with another Qbasic program, which then operates on the numbers, I got "overflow" error. So ran a third Qbasic program that prints the records and out came hieroglyphics! A few of the first records were recognizable alphanumeric, but then started drifting astray, and last 300 records were completely unrecognizable.
I don't know otherwise of any viruses on my machine. One particular file that I carried home from work 5 years ago on a floppy is still good, so the problem seems confined to my harddisk. Does anyone have a suggestion for what might have happened, or better, how I might recover these files?
Posted: Fri Mar 11, 2005 9:10 pm
Your files might be in a damaged, or errored portion of you hard drive. Leave your comp on over night in SafeMode running ScanDisk and it might move the file, or repair the error and you should be able to retreive the file..
Restart computer, when it turns off and just b4 it comes back on. press and hold "Ctrl".. Your givin a menu, pick "3 Safe Mode".. and your takin to a 256 color mode that allows programs like ScanDisk to run unbothered by windows Apps.
Start|Program Files|Assesories|System Tools|Scan Disk
Hope this helps! Good luck..
Posted: Sat Mar 12, 2005 1:10 am
In reality, it sounds like you're reading an incorrect number of bytes. If you're using a TYPE to do it, it's probably the wrong size. If the data starts out mostly readable but then drifts off into garbage, that's a surefire sign that the datafile isn't being read correctly. The chance of it being a corrupt file with the evidence you've presented here is highly unlikely.
Posted: Sun Mar 13, 2005 8:20 pm
Kevin: I'll try running Scandisk tonight, although have run it in the past(but not since problem appeared) without it fixing any shortcomings.
Nekrophidius: yes, this is the sort of thing I vaguely felt might be happening. Do you know, when a random file is opened for printing (not editing), is it then re-written when the program closes? or does the original remain untouched while the program operates on a copy? If it is re-written, then over time I could imagine some kind of error creeping in.
Any suggestions for curing this, other than to just keep more backups?
Thanks to both. xcskier
Posted: Sun Mar 13, 2005 8:36 pm
If you rewrite data incorrectly to ANY file, it's going to become "corrupt". Scandisk isn't going to help much if the file was corrupted no matter how it became that way. The file buffers are flushed when you CLOSE the file. That's when the file is physically written to the disk. I'm not sure about RANDOM mode, but in BINARY mode, you can use ACCESS READ and ACCESS WRITE to specificy access rules. BINARY mode supercedes RANDOM mode anyways, and you might want to start using it.
Posted: Sun Mar 13, 2005 9:09 pm
Confirmed by the other old fella of this group. lol you can specify read and write access to a Random Access File
Posted: Mon Mar 14, 2005 8:28 pm
Okay, ScanDisk is for errors on the disk not files.
If the file is currupt, ScanDisk wount help, but if your file is in a damaged part of the disk, ScanDisk should work, I mean I've had this happen with Floppies, cept it said the file was on a errored part of the disk so, it might be your file..
Posted: Fri Mar 18, 2005 2:59 pm
OK, I ran Scandisk and had no errors or corrections.
Steph: what does "lol" in your reply mean?
All: I'll research the Read/Write access stuff for future reference. Most of the time I open this file, it's not to add to it or to modify it, only to operate on the numbers. So if I've been re-writing it each time I close the operating program (rather than the program that writes the file, which does re-write the file each time), I may be needlessly exposing myself to write errors.
Posted: Fri Mar 18, 2005 9:24 pm
Nekrophidius: I looked in Feldman and Rugg's manual "Using Quickbasic 4" and I don't see an advantage for binary over random files. Can I impose the same record structure on binary as for random? Ie, each of my records is a separate sample having up to 10 measurements: can I keep the measurements separated in a binary file even where some are zero?
In short, I thought the structure of a random file was made for this kind of database. What are the advantages of a binary file in this case where my file structure seems to have "drifted astray"?
Posted: Mon Mar 21, 2005 5:10 pm
OK, over the weekend I tried some things and here's the current situation.
The older datafile on my floppy disk works fine when I open it using Qbasic from my harddrive. That is, I start Qbasic on the harddrive, then tell the program to run the datafile "a:\xxx". Works fine.
BUT WHEN I COPY IT USING WINDOWS EXPLORER TO THE SAME FOLDER AS QBASIC ON THE HARDDRIVE, and then try to open it from the harddrive, it then acts as if corrupted, that is, I get the hieroglyphics.
So the problem may have something to do with using Explorer to move the datafiles around?