Here is the function, to create a DBF from the CSV-headline.
It creates a new file like < __CUSTOMER.dbf > ( double underline from original )
Adding the text-data from the CSV, I'm still working on :
Der nächste Schritt, der REVERSE-teil => CSV nach DBF.
Die Funktion zum Erzeugen der DBF aus der CSV-kopfzeile.
Es wird eine neue Datei erzeugt < __CUSTOMER.dbf > ( doppelt Underline vom Original )
Das Hinzufügen von Text aus der CSV-datei ist in Arbeit :
- Code: Select all Expand view RUN
FUNCTION MAKE_DBF()
LOCAL oText, aStru := {}, N, X, I, nTimes
// CSV-headline-sample, to create the DBF
// LAST-C-20-0;FIRST-C-20-0;HIREDATE-D-8-0;NOTES1-C-10-0;MEMO-M-10-0;NOTES2-C-30-0
oText := TTxtFile():New( cCSV ) // open CSV-file
FOR N = 1 to oText:RECCOUNT() // count textlines
IF N = 1 // only headline
nTimes := STRCHARCOUNT( oText:READLINE(), cDELIM ) // count sections of delimiter
FOR I := 1 TO nTimes // for each delimiter
cField = STRTOKEN( oText:READLINE(), I, cDELIM )
// MsgAlert( cField, "Field" )
X := 1
FOR X := 1 TO 3 // -C-20-0
cName = STRTOKEN( cField, X, "-" )
//MsgAlert( cName, "Name" )
X++
cType = STRTOKEN( cField, X, "-" )
//MsgAlert( cType, "Type" )
X++
nLen = VAL( STRTOKEN( cField, X, "-" ) )
//MsgAlert( nLen, "Len" )
X++
nDec = VAL( STRTOKEN( cField, X, "-" ) )
//MsgAlert( nDec, "Dec" )
X++
AADD( aStru, { cName, cType, nLen, nDec } )
NEXT
NEXT
DBCREATE( CFILEPATH( cDBF ) + "__" + cFileNoExt( cDBF ) + ".dbf", aStru ) // uses original name with __
ELSE
// Adding records from CSV under construction !!!
ENDIF
// MsgInfo( oText:ReadLine() )
oText:Skip()
NEXT
oText:Close()
RETURN NIL
best regards
Uwe