Trying to access "deleted" records inside a dBase III database
I'm writing a program in VB5 that needs to access an old DOS program's dBase III files. I have no problem accessing those files but I need to access the "deleted" records as well (as you know, dBase simply marks records for deletion and then hides them until the database is packed).
I don't actually need to know if a record I'm accessing is marked for deletion or not (although that would be a nice bonus), I just need to access the entire database as if "Set Deleted Off" had been set.
More specifically, when I do a SEEK, I want it to include deleted records in the seek as well.
This is the code I'm using:
Code:
Dim TableName As String
Dim DBFDir As String
Dim MyDBF As DAO.Database
Dim MyRecSet As DAO.Recordset
TableName = "ARTICLE.DBF"
DBFDir = "C:\DBFS\"
SearchString = "SOMEARTICLE"
Set MyDBF = DBEngine.OpenDatabase(DBFDir, True, False, "dBase III;")
Set MyRecSet = MyDBF.OpenRecordset(TableName, dbOpenTable)
With MyRecSet
.Index = DBFIndexName
.Seek "=", SearchString
If Not .NoMatch Then
' Found. Do something
End If
End With
MyRecSet.Close
MyDBF.Close
So how can I include the deleted records as well?
Re: Trying to access "deleted" records inside a dBase III database
Quote:
Originally Posted by
ClarkVent
I'm writing a program in VB5
My heart-felt sympathy to you.
Re: Trying to access "deleted" records inside a dBase III database
Not sure if this would be of use?
Re: Trying to access "deleted" records inside a dBase III database
Quote:
Originally Posted by
jmcilhinney
My heart-felt sympathy to you.
I'm sorry, but remarks like these irk me to no end. I use a whole range of programming languages ranging from C (yes, the old flat C), to C#.Net, to VB.Net, VB5, VB6, Perl, PHP, HaXE, x86 ASM, Java, Clipper (yes, S86) and I could probably continue for quite a while.
Every language has its merits and uses - even ancient languages on modern machines.
If I need a simple form based application that's easily deployable (and works on just about all versions of Windows), I use VB5. And I see no reason to change that. Yes, it's 15 year old technology. But it works and it works very well.
I haven't encountered anything yet I can't do in VB5. In fact, one of my programs targeted for XP and Win7 was an official Webby Honoree for three years in a row (in several categories, until I stopped entering it) - and it was written in VB5.
Re: Trying to access "deleted" records inside a dBase III database
Quote:
Originally Posted by
Nightwalker83
Not sure if
this would be of use?
Thanks, but I don't see anything on that page that helps me "see" deleted records? Or am I overlooking something?
Re: Trying to access "deleted" records inside a dBase III database
I think I misunderstood what was happpening with this code:
vb Code:
'Store the indexes.
For i = 0 To db.TableDefs(tblname).Indexes.Count - 1
ReDim Preserve idxs(i + 1)
idxs(i).Name = db.TableDefs(tblname).Indexes(i).Name
idxs(i).Fields = db.TableDefs(tblname).Indexes(i).Fields
idxs(i).Primary = db.TableDefs(tblname).Indexes(i).Primary
idxs(i).Unique = db.TableDefs(tblname).Indexes(i).Unique
Next
I was thinking you could somehow use that to retrieve the deleted info?
Re: Trying to access "deleted" records inside a dBase III database
Quote:
Originally Posted by
Nightwalker83
I think I misunderstood what was happpening with this code:
Yes, that simply enumerates the index files...
Re: Trying to access "deleted" records inside a dBase III database
I'm guessing by the lack of response this is either not possible or incredibly difficult to implement. Either way, it's apparently not something trivial.
I found one way to make deleted records visible and that is by setting the registry value
HKLM\SOFTWARE\Microsoft\Jet\4.0\Engines\XBase\Deleted
to 00. This effectively is the same as "Set Deleted Off" although it's not dynamic. This registry value is only read once and that is during initialization of the Jet Engine meaning at the start of your program. So you can't use it to dynamically turn ON/OFF deleted records. In fact, I'm not even sure if you can use it at all inside your program. Even if it's the first thing you do in your program (change the registry value), chances are the Jet Engine has already initialized and that changing this value has no effect on any database you open subsequently.
So this bring me to another question: Is it at all possible to even recognize deleted records? Say I manually change this registry value so all deleted records are shown too, and I iterate through the database, how can I recognize a deleted record?
Re: Trying to access "deleted" records inside a dBase III database
Hate to make this a one-man show and answer my own questions, but after a few weeks of searching, trying and mostly failing, I decided to abandon the Jet Engine altogether and I wrote my own (set of) class(es) to handle dBase files.
I can now dynamically turn "Deleted" ON or OFF. Not to mention that my classes closely mimick the behavior of the original dBase III.
vb Code:
Dim DBF As clsDBase
Set DBF = New clsDBase
DBF.Use "F:\DataFiles\CUSTOMER.dbf"
DBF.SetDeleted DELETED_OFF
DBF.GoTop
Debug.Print DBF.RecNo() ' Prints 1
DBF.SetDeleted DELETED_ON
DBF.GoTop
Debug.Print DBF.RecNo() ' Prints 3
Do While Not DBF.IsEOF()
Debug.Print DBF.RecordSet.Fields("DB_NAME")
DBF.Skip ' Automatically skips over deleted records
Loop
DBF.Use ' Closes the Database