Trying to access "deleted" records inside a dBase III database-VBForums
Results 1 to 9 of 9

Thread: Trying to access "deleted" records inside a dBase III database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    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?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,656

    Re: Trying to access "deleted" records inside a dBase III database

    Quote Originally Posted by ClarkVent View Post
    I'm writing a program in VB5
    My heart-felt sympathy to you.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,119

    Re: Trying to access "deleted" records inside a dBase III database

    Not sure if this would be of use?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Trying to access "deleted" records inside a dBase III database

    Quote Originally Posted by jmcilhinney View Post
    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Trying to access "deleted" records inside a dBase III database

    Quote Originally Posted by Nightwalker83 View Post
    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?

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,119

    Re: Trying to access "deleted" records inside a dBase III database

    I think I misunderstood what was happpening with this code:

    vb Code:
    1. 'Store the indexes.
    2.        For i = 0 To db.TableDefs(tblname).Indexes.Count - 1
    3.          ReDim Preserve idxs(i + 1)
    4.          idxs(i).Name = db.TableDefs(tblname).Indexes(i).Name
    5.          idxs(i).Fields = db.TableDefs(tblname).Indexes(i).Fields
    6.          idxs(i).Primary = db.TableDefs(tblname).Indexes(i).Primary
    7.          idxs(i).Unique = db.TableDefs(tblname).Indexes(i).Unique
    8.        Next

    I was thinking you could somehow use that to retrieve the deleted info?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Trying to access "deleted" records inside a dBase III database

    Quote Originally Posted by Nightwalker83 View Post

    I think I misunderstood what was happpening with this code:
    Yes, that simply enumerates the index files...

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    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?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    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:
    1. Dim DBF As clsDBase
    2.  
    3.   Set DBF = New clsDBase
    4.  
    5.   DBF.Use "F:\DataFiles\CUSTOMER.dbf"
    6.  
    7.   DBF.SetDeleted DELETED_OFF
    8.   DBF.GoTop
    9.   Debug.Print DBF.RecNo()   ' Prints 1
    10.  
    11.   DBF.SetDeleted DELETED_ON
    12.   DBF.GoTop
    13.   Debug.Print DBF.RecNo()   ' Prints 3
    14.  
    15.   Do While Not DBF.IsEOF()
    16.     Debug.Print DBF.RecordSet.Fields("DB_NAME")
    17.     DBF.Skip  ' Automatically skips over deleted records
    18.   Loop
    19.  
    20.   DBF.Use  ' Closes the Database
    Last edited by ClarkVent; Mar 13th, 2012 at 04:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.