what is DBF4 (dBase IV)(*.dbf)
file fundamental format? And how can create these file in a same word editor as Notepad
with typing?(Update:, or excel VBA?)
What is that's format specifications as:
Delimiter
(Same as:,
ortab
or etc)Separator
(may Same as above!) (If these two are not synonymy)Row End
character: (Same asvbCrLf
)- Defining headers of columns(fields).
Code-Page
ofencoding
: (same as:Unicode - 1256
or etc)- and others...
Please present an algorithm for creating this DB
file format that made us able to create a same file easily by a VBA
method which creates a text file.
(Update Or using built-in VBA or its references methods.)
I using below for creating text file.
Sub CsvExportRange(rngRange As Object, strFileName As String, strCharset, strSeparator As String, strRowEnd As String, NVC As Boolean) 'NVC: _
Null Value Control (If cell contain Null value, suppose reached end of range), d: delimiter
Dim rngRow As Range
Dim objStream As Object
Dim i, lngFR, lngLR As Long 'lngFR: First Row, lngLR: Last Row
lngFR = rngRange.SpecialCells(xlCellTypeVisible).Rows(1).row - rngRange.Rows(1).row + 1
lngLR = rngRange.End(xlDown).row - rngRange.Rows(1).row + 1
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 2
objStream.Charset = strCharset
objStream.Open
For i = lngFR To lngLR
If Not (rngRange.Rows(i).EntireRow.Hidden) Then
If IIf(NVC, (Cells(i + rngRange.Rows(1).row - 1, _
rngRange.SpecialCells(xlCellTypeVisible).Columns(1).column).Value = vbNullString), False) Then Exit For
objStream.WriteText CsvFormatRow(rngRange.Rows(i), strSeparator, strRowEnd)
End If
Next i
objStream.SaveToFile strFileName, 2
objStream.Close
End Sub
Function CsvFormatRow(rngRow As Variant, strSeparator As String, strRowEnd As String) As String
Dim arrCsvRow() As String
ReDim arrCsvRow(rngRow.SpecialCells(xlCellTypeVisible).Cells.Count - 1)
Dim rngCell As Range
Dim lngIndex As Long
lngIndex = 0
For Each rngCell In rngRow.SpecialCells(xlCellTypeVisible).Cells
arrCsvRow(lngIndex) = CsvFormatString(rngCell.Value, strSeparator)
lngIndex = lngIndex + 1
Next rngCell
CsvFormatRow = Join(arrCsvRow, strSeparator) & strRowEnd
End Function
Function CsvFormatString(strRaw, strSeparator As String) As String
Dim boolNeedsDelimiting As Boolean
Dim strDelimiter, strDelimiterEscaped As String
strDelimiter = """"
strDelimiterEscaped = strDelimiter & strDelimiter
boolNeedsDelimiting = InStr(1, strRaw, strDelimiter) > 0 _
Or InStr(1, strRaw, chr(10)) > 0 _
Or InStr(1, strRaw, strSeparator) > 0
CsvFormatString = strRaw
If boolNeedsDelimiting Then
CsvFormatString = strDelimiter & _
Replace(strRaw, strDelimiter, strDelimiterEscaped) & _
strDelimiter
End If
End Function
(Forgotten source)
Because I reached this: I should create a dbf
file from my Excel Range
by hand! After searching founded web sources.
Updated:
How can declare encoding of DBF?
About encoding that needed, considerable ones is Commonplace in this issue is Iran System encoding.
How can I store data with suitable encoding as Iran System in DB table records?
we have joy .... lol
this test code creates a dbf file from data in excel worksheet
creates a table and inserts one record
my research has concluded. the Iran System encoding is actually ascii, it is not unicode. it uses ascii values to represent some of the Persian alphabet.
the problem with converting from unicode to Iran System encoding is that any letter is written completely differently depending where in the word it is positioned. you have "isolated", "initial", "medial" and "final" forms of most of the letters.
it is like upper and lower case on steroids ... lol
ref: https://www.math.nmsu.edu/~mleisher/Software/csets/IRANSYSTEM.TXT
so additional process would be needed to convert unicode text in excel into an equivalent Iran System encoding string before storing in database.
the code creates a table with one text field and stores 3 records