home *** CD-ROM | disk | FTP | other *** search
- db4vbpk1.zip Feb. 10, 1994
-
- Darryl J. Buchanan
- Buchanan & Associates
- 6120 E. 77 St.
- Tulsa, OK 74136
- (918)491-9590 (Answering machine)
- CompuServe 71435,1442
-
- dBASE IV file packer application for Visual Basic 3.0.
-
- A while back I wrote a Visual Basic application using dBASE IV data
- files. I needed to include the ability for users to perform periodic
- maintenance on the files. This included packing the files to get rid of
- records marked for deletion. Visual Basic does not include a
- function to pack dBASE files, so I wrote a subroutine called
- PackTable to do the job.
-
- PackTable works by:
-
- 1. Opening the database for exclusive access.
-
- 2. Reading the structure of the existing file and index.
-
- 3. Renaming the previous .dbf, .mdx, and .dbt files to the temporary
- names XXXXXXXX.DBF, XXXXXXXX.MDX, and (if the .DBT file exists)
- XXXXXXXX.DBT. This function assumes that you are using maintained
- indexes and therefore have a .MDX index file. If you don't have
- maintained indexes, then you can comment out or remove the code having
- to do with creating the indexes. I think I trapped everything ok
- so if you don't have a maintained index file it still works. I
- never create .DBF files without indexes so I haven't really given
- it a good test.
-
- 4. Creating new .DBF, .MDX, and (if needed) .DBT files using the
- original names.
-
- 5. Open the old .DBF file (that has been renamed to XXXXXXXX.DBF).
- Read all the records from it and write it to the new .DBF file
- while also indexing the file. The records that have been marked
- for deletion are not read in and therefore are effectively
- 'packed' out of the new files.
-
- 6. Finally, kill the old, renamed XXXXXXXX.* files.
-
- Misc:
-
- It was necessary to rename the old file to the temp files, then
- create the new files using the old file names in that order.
- dBASE IV .MDX index files maintain an original table name in the
- header of the index file. Therefore, it was necessary that the new
- file have the old original name when it was created. My first try at
- this I created a new XXXXXXXX.DBF file, read the records from the old
- .DBF file while writing them to the XXXXXXXX.DBF file. Then I deleted
- the old file and renamed the XXXXXXXX.* files to the original file names.
- This works fine on Visual Basic. But when I tried to read the tables with
- Paradox For Windows, it claimed the index (.MDX) file was corrupt.
- After much head scratching and binary file comparing I finally found
- that the file name is saved in the index when the index is first
- created. The Visual Basic database engine seems to ignore this. But
- Paradox For Windows must use this as some kind of integrity check.
-
- I'm not sure if this works for dBASE III or dBASE III+ files. I
- don't use those kind of files so I haven't bothered testing with
- them. I think it will work ok for the .DBF file, but I'm not sure
- what it will do with the .NDX files.
-
- Caveats: (Did I spell that right?)
-
- 1. This function works by creating a copy of your original file.
- You must have enough disk space to hold what could be a file as
- large as your original. If you have lots of deleted records,
- your new file will be smaller.
-
- 2. I haven't thoroughly tested this with files with .DBT (memo)
- files. I think it works, but test before you leap.
-
- 3. ALWAYS!!! ALWAYS!!! BACK UP YOUR DATA FILE, INDEXES, AND .DBT
- FILES BEFORE RUNNING PACKTABLE. RUN THIS AT YOUR OWN RISK!!!
- TEST THOROUGHLY!!
-
- 4. You may freely include this subroutine in your Visual Basic
- programs. All I ask is if you find a bug, PLEASE send me an
- E-MAIL note about it. I'm on CompuServe : 71435,1442.
- Friendly notes are of course also welcome.
-
- 5. There is, of course, no warranty or guarantee of ANY kind
- whatsoever with this code. Use at your own risk.
-
- HELP!!!
-
- I am looking for a good set of C routines that will let me access
- dBASE IV indexed tables with a DOS program. I've found a set of
- routines that work with dBASE III files. But so far I haven't had
- any luck with routines that will work with dBASE IV tables with .MDX
- maintained indexes. If you have any such routines, or know where I
- can get some, please send me a message on CompuServe. If I haven't
- found them by 6/1/94, I probably won't need them anymore. Thanks.
-
- The files:
-
- PACKTABL BAS 10295 02-10-94 2:14p The PackTable subroutine.
- PACKTABL EXE 9031 02-10-94 2:14p Sample Exe file.
- PACKTABL MAK 413 02-10-94 2:14p Mak file for the sample exe.
- FRMPACKT FRM 1973 02-10-94 10:56a The form for the sample exe.
- README.TXT This file.
-
- Enjoy.
-
- Darryl J. Buchanan
- Buchanan & Associates
- 6120 E. 77 St.
- Tulsa, OK 74136
- (918)491-9590 (answering machine)
- CompuServe 71435,1442
-
-