FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Fieldname limit to 10 char. giving problem
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Fieldname limit to 10 char. giving problem
Posted: Sun Oct 23, 2016 01:11 PM
Hello,

I convert csv files to dbf files by code.

I have the fieldnames in a array adata from a other piece of code, and want to make a dbf out of it.
The problem is that the fieldnames in csv are often longer than 10 characters.

adata contains example :

ID
Name
Price
information1
information2
information3
...

The routine below will do

ID
Name
Price
informatio
informatio
informatio

I need something like (2 digits to be save, so 8 from the fieldname and 2 incremental)

informat01
informat02
informat03

I'm working on Ascan and so, but so far no luck...

Code (fw): Select all Collapse
function Builddbf(adata,Alengte,cDbf)
   LOCAL aStru := {}

//   msginfo(atostr(adata))

   for i = 1 to len(adata)
     cField = STRTRAN(aData[i], '"', '')
     aAdd( aStru, { cField , "C", alengte[i]+1 , 0 } )
   next
   dbCreate( cDbf , aStru )

return
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Fieldname limit to 10 char. giving problem
Posted: Sun Oct 23, 2016 04:25 PM
Marc

Question .. do you know the structure of the CSV file ? If so, you may be able to use the SDF append from option ..

Code (fw): Select all Collapse
..  create your temp database.. the .dbf fields must be in the same order as the .csv 

Select 1
Append from yourfile.csv SDF delimited by ","


Not very elegant but it should work or you can use Ole and Ado to take an .Xls(x) to .Dbf .. lots of examples in this forum on how to import Excel.

Rick Lipkin
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Fieldname limit to 10 char. giving problem
Posted: Sun Oct 23, 2016 06:46 PM

Hey,

The append from is no option.

I read the csv files and change some values while importing. The csv's are never the same as the master data and there are many csv files to process trough time.

I only know some what of DBF's, so other struff like sql, .... are no option on this moment. (time limit) in order to learn the rest.

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Fieldname limit to 10 char. giving problem
Posted: Sun Oct 23, 2016 10:36 PM

Marc,

This is one reason why I suggested changing the header of the CSV file before it is imported into a DBF. If you change the header to use the standard fieldnames in the master DBF, then importing and processing it will be much easier.

Another possibility is to just read in the lines of the CSV file one at a time, then move the data to an array then process the array.

There are other possibilities too.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Re: Fieldname limit to 10 char. giving problem
Posted: Tue Oct 25, 2016 09:31 AM
James,

Is this what you need ?

Code (fw): Select all Collapse
if len( cField ) > 10
   n++
   cField := substr( cField, 1, 10 - len ( alltrim( str( n, 0 ) ) ) ) + ;
                    padl( alltrim( str( n, 0) ), 2, "0" )
endif
Regards

Antonio H Ferreira
Posts: 88
Joined: Wed Apr 28, 2010 06:34 PM
Re: Fieldname limit to 10 char. giving problem
Posted: Tue Oct 25, 2016 03:04 PM

LOCAL cFileCSV := "c:\dircvs\name.cvs"

oTxtFile := TTxtFile():New( cFileCSV, 0 )
oTxtFile:Skip() //skip the first line of the header

while !oTxtFile:lEoF()

?StrToken( oTxtFile:cLine, 1, ";" )
?StrToken( oTxtFile:cLine, 2, ";" )
?StrToken( oTxtFile:cLine, <n>, ";" )

oTxtFile:Skip()

ENDDO

oTxtFile:Close()

that's how I read the .csv files or any other

Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Fieldname limit to 10 char. giving problem
Posted: Tue Oct 25, 2016 05:54 PM
AHF wrote:

Code (fw): Select all Collapse
if len( cField ) > 10
   n++
   cField := substr( cField, 1, 10 - len ( alltrim( str( n, 0 ) ) ) ) + ;
                    padl( alltrim( str( n, 0) ), 2, "0" )
endif


Hey,

This was exactly what I needed. Thanks.

Marc
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Fieldname limit to 10 char. giving problem
Posted: Tue Oct 25, 2016 06:15 PM
aferra wrote:LOCAL cFileCSV := "c:\dircvs\name.cvs"

oTxtFile := TTxtFile():New( cFileCSV, 0 )
oTxtFile:Skip() //skip the first line of the header

while !oTxtFile:lEoF()

?StrToken( oTxtFile:cLine, 1, ";" )
?StrToken( oTxtFile:cLine, 2, ";" )
?StrToken( oTxtFile:cLine, <n>, ";" )

oTxtFile:Skip()

ENDDO

oTxtFile:Close()

that's how I read the .csv files or any other


This is interesting, and so much clearer and easy !!
A total other way as I do, but very nice.

Can you point me to an information page where this is more explaned ? I would like to look into this more.

Marc
Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion