Tools Links Login

Read DBF structure and Record count

Returns instant record count, structure of DBF files

Original Author: Yves Allaire

Inputs

Fine lame

Returns

Record count, structure , number of fields

Code

Function dbfStru(file As String) As Double
  Dim fileno As Integer, txtin As Variant, bit(0 To 31) As Double
  Dim posRec As Single, recSize As Single, nmbFiel As Single, fieldName As String
  Dim fieldlength As Single
  Dim test As Single
  fileno = FreeFile
  Open file For Binary As #fileno
  'reads first 31 bites
  For x = 0 To 31
    txtin = Asc(Input(1, #fileno))
    Select Case x
      'record count
      Case 4 To 11
        bit(x) = txtin
    End Select
  Next
  dbfRecCount = bit(4) + (bit(5) * 256) + (bit(6) * 65536) + (bit(7) * 16777216)
  posRec = bit(8) + bit(9) * 256
  nmbfield = (posRec - 33) / 32
  recSize = bit(10) + bit(11) * 256
    For i = 32 To posRec - 1
    'field name
    For n = 0 To 10
      txtin = Input(1, #fileno)
      fieldName = fieldName + txtin
    Next
    fieldName = Trim(fieldName)
    'field type byte 11
    fieldType = Input(1, #fileno)
    'byte 12 to 15
    txtin = Input(4, #fileno)
    
    'byte 16
    fieldlength = Asc(Input(1, #fileno))
    'byte 17
    fieldDeci = Asc(Input(1, #fileno))
    
    For n = 18 To 31
      txtin = Input(1, #fileno)
    Next
    fieldName = ""
  Next
  Close fileno
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 106 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Comments

No comments have been added for this post.

You must be logged in to make a comment.