To Nages : Conversion txt into xbrowse bad

To Nages : Conversion txt into xbrowse bad

Postby Silvio.Falconi » Tue Nov 23, 2021 12:47 pm

I made

Code: Select all  Expand view  RUN

local csvfile:=".\csv\PianoDeiConti.csv"
Local  cSymbol := ","
Local  cText := StrTran( MemoRead( csvfile ), CHR( 10 ), Chr(1) )
Local   aData := HB_ATokens( cText, Chr(1), .t., .t. )
AEval( aData, { |c,i| c := StrTran( c, Chr(1), CRLF ), aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )

      if len( ATail( aData ) ) < 2
           ASize( aData, Len( aData ) - 1 )
        endif

        XBROWSER aData
 



it save on array the first line
Image

How I can resolve ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : Conversion txt into xbrowse bad

Postby Silvio.Falconi » Wed Nov 24, 2021 10:28 am

If I made

local csvfile:=".\csv\PianoDeiConti.csv"
Local cSymbol := ","
Local cText := StrTran( MemoRead( csvfile ), CHR( 10 ), Chr(1) )
Local aData := HB_ATokens( cText, Chr(1), .t., .t. )
AEval( aData, { |c,i| c := StrTran( c, Chr(1), CRLF ), aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )

if len( ATail( aData ) ) < 2
ASize( aData, Len( aData ) - 1 )
endif
Adel(aData,1) <----------------

erase the first line

But when I save aData on Archive, inserts an empty record as you can see here

Image

Now you see it at the bottom because the dbf is indexed but I thing the procedure insert the Empty record at init
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : Conversion txt into xbrowse bad

Postby Antonio Linares » Wed Nov 24, 2021 11:45 am

Dear Silvio,

Mr. Rao will help you on this. He is the right one to do it
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: To Nages : Conversion txt into xbrowse bad

Postby Silvio.Falconi » Wed Nov 24, 2021 4:25 pm

Antonio Linares wrote:Dear Silvio,

Mr. Rao will help you on this. He is the right one to do it


thanks, in the example I had I didn't have to delete the first line, now I have a file that in the first line of the csv file I have the database fields and I was able to delete with adel (adata, 1) but later when I use oDbf: fw_ArrayToDBF (aData, , bProgress) to save aData in the dbf archive, the procedure inserts a first empty record and then in any case inserts all the other records

for a sample here pubblish a little csv fille
Code: Select all  Expand view  RUN

CodUM,DescrUM,Molt,NumDec,Tipo,CodDescrUM
CF10,Confezione 10 pezzi,10,0,Numero,CF10 - Confezione 10 pezzi
CF2,Confezione 2 pezzi,2,0,Numero,CF2 - Confezione 2 pezzi
CF20,Confezione 20 pezzi,20,0,Numero,CF20 - Confezione 20 pezzi
CF24,Confezione 24 pezzi,24,0,Numero,CF24 - Confezione 24 pezzi
CF3,Confezione 3 pezzi,3,0,Numero,CF3 - Confezione 3 pezzi
CF4,Confezione 4 pezzi,4,0,Numero,CF4 - Confezione 4 pezzi
CF5,Confezione 5 pezzi,5,0,Numero,CF5 - Confezione 5 pezzi
CF6,Confezione 6 pezzi,6,0,Numero,CF6 - Confezione 6 pezzi
KG,Chilogrammi,1,3,Peso,KG - Chilogrammi
LT,Litri,1,3,Volume,LT - Litri
MC,Metri cubi,1,3,Volume,MC - Metri cubi
MQ,Metri quadri,1,3,Lunghezza,MQ - Metri quadri
MT,Metri,1,3,Lunghezza,MT - Metri
NR,Numero,1,0,Numero,NR - Numero
PZ,Pezzi,1,0,Numero,PZ - Pezzi
 


Fields
CodUM (C, 4, 0)
DescrUM (C, 86, 0)
Molt (N, 13, 6)
NumDec (N, 1, 0)
Tipo (C, 10, 0)
CodDescrUM (C, 86, 0)





local csvfile:=".\csv\test.csv"
Local cSymbol := ","
Local cText := StrTran( MemoRead( csvfile ), CHR( 10 ), Chr(1) )
Local aData := HB_ATokens( cText, Chr(1), .t., .t. )

// load csv to aData
AEval( aData, { |c,i| c := StrTran( c, Chr(1), CRLF ), aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )

if len( ATail( aData ) ) < 2
ASize( aData, Len( aData ) - 1 )
endif

Adel(aData,1) // erase first line

// save to dbf
oMisura:= TDatabase():Open( , cPath+"Unitamisura", "DBFCDX", .T. )
SET DELETED ON
oMisura:setorder(0)
oMisura:gotop()
oMisura:fw_ArrayToDBF( aData,,bProgress)
DbCloseAll()
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : Conversion txt into xbrowse bad

Postby Silvio.Falconi » Thu Nov 25, 2021 9:04 am

with ASize( aData, Len( aData ) - 1 )
I can erase that line but How I can Know that line is empty ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : Conversion txt into xbrowse bad

Postby nageswaragunupudi » Fri Nov 26, 2021 4:55 pm

Silvio.Falconi wrote:
Antonio Linares wrote:Dear Silvio,

Mr. Rao will help you on this. He is the right one to do it


thanks, in the example I had I didn't have to delete the first line, now I have a file that in the first line of the csv file I have the database fields and I was able to delete with adel (adata, 1) but later when I use oDbf: fw_ArrayToDBF (aData, , bProgress) to save aData in the dbf archive, the procedure inserts a first empty record and then in any case inserts all the other records

for a sample here pubblish a little csv fille
Code: Select all  Expand view  RUN

CodUM,DescrUM,Molt,NumDec,Tipo,CodDescrUM
CF10,Confezione 10 pezzi,10,0,Numero,CF10 - Confezione 10 pezzi
CF2,Confezione 2 pezzi,2,0,Numero,CF2 - Confezione 2 pezzi
CF20,Confezione 20 pezzi,20,0,Numero,CF20 - Confezione 20 pezzi
CF24,Confezione 24 pezzi,24,0,Numero,CF24 - Confezione 24 pezzi
CF3,Confezione 3 pezzi,3,0,Numero,CF3 - Confezione 3 pezzi
CF4,Confezione 4 pezzi,4,0,Numero,CF4 - Confezione 4 pezzi
CF5,Confezione 5 pezzi,5,0,Numero,CF5 - Confezione 5 pezzi
CF6,Confezione 6 pezzi,6,0,Numero,CF6 - Confezione 6 pezzi
KG,Chilogrammi,1,3,Peso,KG - Chilogrammi
LT,Litri,1,3,Volume,LT - Litri
MC,Metri cubi,1,3,Volume,MC - Metri cubi
MQ,Metri quadri,1,3,Lunghezza,MQ - Metri quadri
MT,Metri,1,3,Lunghezza,MT - Metri
NR,Numero,1,0,Numero,NR - Numero
PZ,Pezzi,1,0,Numero,PZ - Pezzi
 


Fields
CodUM (C, 4, 0)
DescrUM (C, 86, 0)
Molt (N, 13, 6)
NumDec (N, 1, 0)
Tipo (C, 10, 0)
CodDescrUM (C, 86, 0)





local csvfile:=".\csv\test.csv"
Local cSymbol := ","
Local cText := StrTran( MemoRead( csvfile ), CHR( 10 ), Chr(1) )
Local aData := HB_ATokens( cText, Chr(1), .t., .t. )

// load csv to aData
AEval( aData, { |c,i| c := StrTran( c, Chr(1), CRLF ), aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )

if len( ATail( aData ) ) < 2
ASize( aData, Len( aData ) - 1 )
endif

Adel(aData,1) // erase first line

// save to dbf
oMisura:= TDatabase():Open( , cPath+"Unitamisura", "DBFCDX", .T. )
SET DELETED ON
oMisura:setorder(0)
oMisura:gotop()
oMisura:fw_ArrayToDBF( aData,,bProgress)
DbCloseAll()


Code: Select all  Expand view  RUN

cText    := RemRight( MemoRead( csvFile ), CHR(26) )
cText    := StrTran( cText, CRLF, CHR(10) )
cText    := RemRight( cText, CHR(10) )
aData    := HB_ATokens( cText, CHR(10), .t., .t. )
AEval( aData, { |c,i| c := StrTran( c, CHR(10), CRLF ), ;
              aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )
aHead    := aData[ 1 ]
HB_ADel( aData, 1, .t. )
AEval( aData, { |a| a[ 3 ] := Val( a[ 3 ] ), a[ 4 ] := Val( a[ 4 ] ) } )
             
XBROWSER aData SETUP ( oBrw:cHeaders := aHead )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: To Nages : Conversion txt into xbrowse bad

Postby Silvio.Falconi » Sat Nov 27, 2021 2:53 pm

nageswaragunupudi wrote:
Silvio.Falconi wrote:
Antonio Linares wrote:Dear Silvio,

Mr. Rao will help you on this. He is the right one to do it


thanks, in the example I had I didn't have to delete the first line, now I have a file that in the first line of the csv file I have the database fields and I was able to delete with adel (adata, 1) but later when I use oDbf: fw_ArrayToDBF (aData, , bProgress) to save aData in the dbf archive, the procedure inserts a first empty record and then in any case inserts all the other records

for a sample here pubblish a little csv fille
Code: Select all  Expand view  RUN

CodUM,DescrUM,Molt,NumDec,Tipo,CodDescrUM
CF10,Confezione 10 pezzi,10,0,Numero,CF10 - Confezione 10 pezzi
CF2,Confezione 2 pezzi,2,0,Numero,CF2 - Confezione 2 pezzi
CF20,Confezione 20 pezzi,20,0,Numero,CF20 - Confezione 20 pezzi
CF24,Confezione 24 pezzi,24,0,Numero,CF24 - Confezione 24 pezzi
CF3,Confezione 3 pezzi,3,0,Numero,CF3 - Confezione 3 pezzi
CF4,Confezione 4 pezzi,4,0,Numero,CF4 - Confezione 4 pezzi
CF5,Confezione 5 pezzi,5,0,Numero,CF5 - Confezione 5 pezzi
CF6,Confezione 6 pezzi,6,0,Numero,CF6 - Confezione 6 pezzi
KG,Chilogrammi,1,3,Peso,KG - Chilogrammi
LT,Litri,1,3,Volume,LT - Litri
MC,Metri cubi,1,3,Volume,MC - Metri cubi
MQ,Metri quadri,1,3,Lunghezza,MQ - Metri quadri
MT,Metri,1,3,Lunghezza,MT - Metri
NR,Numero,1,0,Numero,NR - Numero
PZ,Pezzi,1,0,Numero,PZ - Pezzi
 


Fields
CodUM (C, 4, 0)
DescrUM (C, 86, 0)
Molt (N, 13, 6)
NumDec (N, 1, 0)
Tipo (C, 10, 0)
CodDescrUM (C, 86, 0)





local csvfile:=".\csv\test.csv"
Local cSymbol := ","
Local cText := StrTran( MemoRead( csvfile ), CHR( 10 ), Chr(1) )
Local aData := HB_ATokens( cText, Chr(1), .t., .t. )

// load csv to aData
AEval( aData, { |c,i| c := StrTran( c, Chr(1), CRLF ), aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )

if len( ATail( aData ) ) < 2
ASize( aData, Len( aData ) - 1 )
endif

Adel(aData,1) // erase first line

// save to dbf
oMisura:= TDatabase():Open( , cPath+"Unitamisura", "DBFCDX", .T. )
SET DELETED ON
oMisura:setorder(0)
oMisura:gotop()
oMisura:fw_ArrayToDBF( aData,,bProgress)
DbCloseAll()


Code: Select all  Expand view  RUN

cText    := RemRight( MemoRead( csvFile ), CHR(26) )
cText    := StrTran( cText, CRLF, CHR(10) )
cText    := RemRight( cText, CHR(10) )
aData    := HB_ATokens( cText, CHR(10), .t., .t. )
AEval( aData, { |c,i| c := StrTran( c, CHR(10), CRLF ), ;
              aData[ i ] := HB_ATokens( c, cSymbol, .t., .t. ) } )
aHead    := aData[ 1 ]
HB_ADel( aData, 1, .t. )
AEval( aData, { |a| a[ 3 ] := Val( a[ 3 ] ), a[ 4 ] := Val( a[ 4 ] ) } )
             
XBROWSER aData SETUP ( oBrw:cHeaders := aHead )
 



Thanks Rao.
I understood that there is no way, you must necessarily set all the fields if they are numeric, logical, character or date
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : Conversion txt into xbrowse bad

Postby nageswaragunupudi » Sat Nov 27, 2021 4:27 pm

you must necessarily set all the fields if they are numeric, logical, character or date

FW_ArrayToDBF() does the conversion automatically depending on the DBF field type.
But it is highly desirable that we do it ourselves.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 84 guests