Page 1 of 1

Strange error to converte a file

Posted: Mon Jan 04, 2021 8:57 am
by Silvio.Falconi
If I compile a run the test it run ok

If insert the test on my application give me an error at this line

if cBuf[ -1 ] == 26 // check and remove Ctrl-Z



Function test()
local cFile:= cGetFile( "Timbrature (*.csv) | *.csv", "Selezionare un file", 1, )
local aData:={}
aData:= Csv_To_Data(cfile)

xbrowser adata
return nil




Function Csv_To_Data(cfile)
local cBuf, i,nFLines
local aTmp, aHeaders

// carico file csv
nFLines := FLineCount( cFile )
i := 1

cBuf := MemoRead( cFile )
cBuf := STRTRAN(cBuf,",",";")
cBuf := STRTRAN(cBuf,'"','')

// parse and make a multi dimentional array
if cBuf[ -1 ] == 26 // check and remove Ctrl-Z <--------------------
cBuf := Left( cBuf, Len( cBuf ) - 1 )
endif

if Right( cBuf, 2 ) != CRLF
// pad with CRLF if needed, not to miss the last line
cBuf += CRLF
endif
cBuf := StrTran( cBuf, CRLF, Chr( 10 ) )
aTmp := hb_aTokens( cBuf, Chr(10) )
AEval( aTmp, { |c,i| aTmp[ i ] := hb_aTokens( c, ';' ) } )
aHeaders := aTmp[ 1 ]
aTmp := ADel( aTmp, 1 )
aSize( aTmp, Len( aTmp ) - 1 )
return aTmp


the file csv

Code: Select all

"UserName","Activity","Work Date","Time Worked"
"Falconi Silvio","In","30-12-2020","08:07"
"Falconi Silvio","Out","30-12-2020","14:12"
"Falconi Silvio","In","29-12-2020","08:05"
"Falconi Silvio","Out","29-12-2020","14:22"
"Falconi Silvio","In","28-12-2020","08:02"
"Falconi Silvio","Out","28-12-2020","14:02"
"Falconi Silvio","In","23-12-2020","07:57"
"Falconi Silvio","Out","23-12-2020","14:01"
"Falconi Silvio","In","22-12-2020","08:04"
"Falconi Silvio","Out","22-12-2020","14:02"
"Falconi Silvio","In","21-12-2020","08:10"
"Falconi Silvio","Out","21-12-2020","14:00"
"Falconi Silvio","In","18-12-2020","08:10"
"Falconi Silvio","Out","18-12-2020","14:09"
"Falconi Silvio","In","17-12-2020","08:11"
"Falconi Silvio","Out","17-12-2020","14:03"
"Falconi Silvio","In","16-12-2020","08:01"
"Falconi Silvio","Out","16-12-2020","14:04"
"Falconi Silvio","In","15-12-2020","08:02"
"Falconi Silvio","Out","15-12-2020","14:05"
"Falconi Silvio","In","14-12-2020","07:56"
"Falconi Silvio","Out","14-12-2020","14:11"
"Falconi Silvio","In","12-12-2020","08:18"
"Falconi Silvio","Out","12-12-2020","14:05"
"Falconi Silvio","In","11-12-2020","07:58"
"Falconi Silvio","Out","11-12-2020","14:02"
"Falconi Silvio","In","10-12-2020","08:09"
"Falconi Silvio","Out","10-12-2020","14:10"
"Falconi Silvio","In","9-12-2020","08:15"
"Falconi Silvio","Out","9-12-2020","14:03"
"Falconi Silvio","In","7-12-2020","07:59"
"Falconi Silvio","Out","7-12-2020","14:03"
"Falconi Silvio","In","5-12-2020","08:07"
"Falconi Silvio","Out","5-12-2020","14:13"
"Falconi Silvio","In","4-12-2020","07:59"
"Falconi Silvio","Out","4-12-2020","14:04"
"Falconi Silvio","In","3-12-2020","07:56"
"Falconi Silvio","Out","3-12-2020","14:00"
"Falconi Silvio","In","2-12-2020","08:11"
"Falconi Silvio","Out","2-12-2020","14:00"
"Falconi Silvio","In","1-12-2020","07:59"
"Falconi Silvio","Out","1-12-2020","14:02"
 

the error.log

Code: Select all

Application
===========
   Path and name: C:\Work\Prg\TimeCard\Timecard.Exe (32 bits)
   Size: 7,936,512 bytes
   Compiler version: Harbour 3.2.0dev (r1904111533)
   FiveWin  version: FWH 20.12
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.1, Build 7600 

   Time from start: 0 hours 0 mins 12 secs 
   Error occurred at: 04-01-2021, 09:37:10
   Error description: Error BASE/1068  Parametro errato: accesso all'array
   Args:
     [   1] = C   UserName;Activity;Work Date;Time Worked
Falconi Silvio;In;30-12-2020;08:07
Falconi Silvio;Out;30-12-2020;14:12
Falconi Silvio;In;29-12-2020;08:05
Falconi Silvio;Out;29-12-2020;14:22
Falconi Silvio;In;28-12-2020;08:02
Falconi Silvio;Out;28-12-2020;14:02
Falconi Silvio;In;23-12-2020;07:57
Falconi Silvio;Out;23-12-2020;14:01
Falconi Silvio;In;22-12-2020;08:04
Falconi Silvio;Out;22-12-2020;14:02
Falconi Silvio;In;21-12-2020;08:10
Falconi Silvio;Out;21-12-2020;14:00
Falconi Silvio;In;18-12-2020;08:10
Falconi Silvio;Out;18-12-2020;14:09
Falconi Silvio;In;17-12-2020;08:11
Falconi Silvio;Out;17-12-2020;14:03
Falconi Silvio;In;16-12-2020;08:01
Falconi Silvio;Out;16-12-2020;14:04
Falconi Silvio;In;15-12-2020;08:02
Falconi Silvio;Out;15-12-2020;14:05
Falconi Silvio;In;14-12-2020;07:56
Falconi Silvio;Out;14-12-2020;14:11
Falconi Silvio;In;12-12-2020;08:18
Falconi Silvio;Out;12-12-2020;14:05
Falconi Silvio;In;11-12-2020;07:58
Falconi Silvio;Out;11-12-2020;14:02
Falconi Silvio;In;10-12-2020;08:09
Falconi Silvio;Out;10-12-2020;14:10
Falconi Silvio;In;9-12-2020;08:15
Falconi Silvio;Out;9-12-2020;14:03
Falconi Silvio;In;7-12-2020;07:59
Falconi Silvio;Out;7-12-2020;14:03
Falconi Silvio;In;5-12-2020;08:07
Falconi Silvio;Out;5-12-2020;14:13
Falconi Silvio;In;4-12-2020;07:59
Falconi Silvio;Out;4-12-2020;14:04
Falconi Silvio;In;3-12-2020;07:56
Falconi Silvio;Out;3-12-2020;14:00
Falconi Silvio;In;2-12-2020;08:11
Falconi Silvio;Out;2-12-2020;14:00
Falconi Silvio;In;1-12-2020;07:59
Falconi Silvio;Out;1-12-2020;14:02
     [   2] = N   -1

Stack Calls
===========
   Called from: source\PWeb.prg => TIMEIMPORT( 82 )
   Called from: source\PWeb.prg => (b)WEBCONVERSIONE( 39 )
   Called from: .\source\classes\DIALOG.PRG => (b)TDIALOG( 97 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:DISPLAY( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 1127 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 304 )
   Called from: source\PWeb.prg => WEBCONVERSIONE( 40 )
   Called from: source\Main.prg => (b)TAPPLICATION_BUILDBTNBAR( 765 )
   Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:CLICK( 713 )
   Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:LBUTTONUP( 999 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1817 )
   Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:HANDLEEVENT( 2051 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3559 )
   Called from:  => WINRUN( 0 )
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 1097 )
   Called from: source\Main.prg => TAPPLICATION:ACTIVATE( 407 )
   Called from: source\Main.prg => MAIN( 52 )

System
======
   CPU type: Intel(R) Core(TM) i7 CPU       Q 740  @ 1.73GHz 1850 Mhz
   Hardware memory: 8117 megs

   Free System resources: 90 %
        GDI    resources: 90 %
        User   resources: 90 %

   Windows total applications running: 5
      1 ,                                                                                                     
      2 , C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16385_none_421189 
      3 , C:\Windows\syswow64\SHLWAPI.dll                                                                     
      4 , C:\Work\Prg\TimeCard\Timecard.Exe                                                                   
      5 GDI+ Window, C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7600.16385_none_72fc7cbf861225 

Variables in use
================
   Procedure     Type   Value
   ==========================
   TIMEIMPORT
     Param   1:    O    Class: ERROR
   (b)WEBCONVERSIONE
     Param   1:    O    Class: TPROGRESS
     Param   2:    O    Class: TSAY
     Param   3:    C    "C:\Users\silvio\Downloads\timbrature_2021-01-04.csv"
     Local   1:    C    "UserName;Activity;Work Date;Time Worked
Falconi Silvio;In;30-12-2020;08:07
Falconi Silvio;Out;30-12-2020;14:12
Falconi Silvio;In;29-12-2020;08:05
Falconi Silvio;Out;29-12-2020;14:22
Falconi Silvio;In;28-12-2020;08:02
Falconi Silvio;Out;28-12-2020;14:02
Falconi Silvio;In;23-12-2020;07:57
Falconi Silvio;Out;23-12-2020;14:01
Falconi Silvio;In;22-12-2020;08:04
Falconi Silvio;Out;22-12-2020;14:02
Falconi Silvio;In;21-12-2020;08:10
Falconi Silvio;Out;21-12-2020;14:00
Falconi Silvio;In;18-12-2020;08:10
Falconi Silvio;Out;18-12-2020;14:09
Falconi Silvio;In;17-12-2020;08:11
Falconi Silvio;Out;17-12-2020;14:03
Falconi Silvio;In;16-12-2020;08:01
Falconi Silvio;Out;16-12-2020;14:04
Falconi Silvio;In;15-12-2020;08:02
Falconi Silvio;Out;15-12-2020;14:05
Falconi Silvio;In;14-12-2020;07:56
Falconi Silvio;Out;14-12-2020;14:11
Falconi Silvio;In;12-12-2020;08:18
Falconi Silvio;Out;12-12-2020;14:05
Falconi Silvio;In;11-12-2020;07:58
Falconi Silvio;Out;11-12-2020;14:02
Falconi Silvio;In;10-12-2020;08:09
Falconi Silvio;Out;10-12-2020;14:10
Falconi Silvio;In;9-12-2020;08:15
Falconi Silvio;Out;9-12-2020;14:03
Falconi Silvio;In;7-12-2020;07:59
Falconi Silvio;Out;7-12-2020;14:03
Falconi Silvio;In;5-12-2020;08:07
Falconi Silvio;Out;5-12-2020;14:13
Falconi Silvio;In;4-12-2020;07:59
Falconi Silvio;Out;4-12-2020;14:04
Falconi Silvio;In;3-12-2020;07:56
Falconi Silvio;Out;3-12-2020;14:00
Falconi Silvio;In;2-12-2020;08:11
Falconi Silvio;Out;2-12-2020;14:00
Falconi Silvio;In;1-12-2020;07:59
Falconi Silvio;Out;1-12-2020;14:02"
     Local   2:    N    1
     Local   3:    N    42
     Local   4:    U    
     Local   5:    U    
     Local   6:    A    Len:    2
     Local   7:    U    
     Local   8:    U    
     Local   9:    U    
     Local  10:    U    
     Local  11:    U    
     Local  12:    U    
     Local  13:    U    
     Local  14:    U    
     Local  15:    U    
     Local  16:    L    .F.
     Local  17:    L    .F.
     Local  18:    C    "UserName;Activity;Work Date;Time Worked
Falconi Silvio;In;30-12-2020;08:07
Falconi Silvio;Out;30-12-2020;14:12
Falconi Silvio;In;29-12-2020;08:05
Falconi Silvio;Out;29-12-2020;14:22
Falconi Silvio;In;28-12-2020;08:02
Falconi Silvio;Out;28-12-2020;14:02
Falconi Silvio;In;23-12-2020;07:57
Falconi Silvio;Out;23-12-2020;14:01
Falconi Silvio;In;22-12-2020;08:04
Falconi Silvio;Out;22-12-2020;14:02
Falconi Silvio;In;21-12-2020;08:10
Falconi Silvio;Out;21-12-2020;14:00
Falconi Silvio;In;18-12-2020;08:10
Falconi Silvio;Out;18-12-2020;14:09
Falconi Silvio;In;17-12-2020;08:11
Falconi Silvio;Out;17-12-2020;14:03
Falconi Silvio;In;16-12-2020;08:01
Falconi Silvio;Out;16-12-2020;14:04
Falconi Silvio;In;15-12-2020;08:02
Falconi Silvio;Out;15-12-2020;14:05
Falconi Silvio;In;14-12-2020;07:56
Falconi Silvio;Out;14-12-2020;14:11
Falconi Silvio;In;12-12-2020;08:18
Falconi Silvio;Out;12-12-2020;14:05
Falconi Silvio;In;11-12-2020;07:58
Falconi Silvio;Out;11-12-2020;14:02
Falconi Silvio;In;10-12-2020;08:09
Falconi Silvio;Out;10-12-2020;14:10
Falconi Silvio;In;9-12-2020;08:15
Falconi Silvio;Out;9-12-2020;14:03
Falconi Silvio;In;7-12-2020;07:59
Falconi Silvio;Out;7-12-2020;14:03
Falconi Silvio;In;5-12-2020;08:07
Falconi Silvio;Out;5-12-2020;14:13
Falconi Silvio;In;4-12-2020;07:59
Falconi Silvio;Out;4-12-2020;14:04
Falconi Silvio;In;3-12-2020;07:56
Falconi Silvio;Out;3-12-2020;14:00
Falconi Silvio;In;2-12-2020;08:11
Falconi Silvio;Out;2-12-2020;14:00
Falconi Silvio;In;1-12-2020;07:59
Falconi Silvio;Out;1-12-2020;14:02"
     Local  19:    N    -1
     Local  20:    U    
     Local  21:    U    
   (b)TDIALOG
     Param   1:    U    
   TDIALOG:DISPLAY
     Param   1:    O    Class: TDIALOG
   TDIALOG:HANDLEEVENT
   DIALOGBOXINDIRECT
     Param   1:    N    15
     Param   2:    N    0
     Param   3:    N    0
   TDIALOG:ACTIVATE
     Param   1:    N    4194304
     Param   2:    C    "€ È€       ñ e     U n   m o m e n t o   p e r   f a v o r e       V        m T B I T M A P            P       q  n S T A T I C   I m p o r t a n d o   f i l e   R e p o r t . . .          P     / Z  o S T A T I C                                                                     P     9 È  p m s c t l s _ p r o g r e s s 3 2         "
     Param   3:    N    5506110
     Param   4:    O    Class: TDIALOG
   WEBCONVERSIONE
     Param   1:    U    
     Param   2:    U    
     Param   3:    U    
     Param   4:    L    .T.
     Param   5:    U    
     Param   6:    L    .T.
     Param   7:    U    
     Param   8:    U    
     Param   9:    U    
     Param  10:    U    
     Param  11:    U    
     Param  12:    L    .F.
     Param  13:    O    Class: TDIALOG
     Param  14:    U    
     Local   1:    N    5506110
     Local   2:    S    
     Local   3:    O    Class: TDIALOG
   (b)TAPPLICATION_BUILDBTNBAR
     Local   1:    O    Class: TDIALOG
     Local   2:    O    Class: TBITMAP
     Local   3:    O    Class: TSAY
     Local   4:    O    Class: TPROGRESS
     Local   5:    C    "C:\Users\silvio\Downloads\timbrature_2021-01-04.csv"
   TBTNBMP:CLICK
     Param   1:    O    Class: TBTNBMP
   TBTNBMP:LBUTTONUP
   TCONTROL:HANDLEEVENT
     Param   1:    N    32
     Param   2:    N    21
     Param   3:    N    0
     Local   1:    L    .T.
     Local   2:    N    0
     Local   3:    S    
   TBTNBMP:HANDLEEVENT
     Param   1:    N    514
     Param   2:    N    0
     Param   3:    N    2097173
     Local   1:    U    
   _FWH
     Param   1:    N    514
     Param   2:    N    0
     Param   3:    N    2097173
   WINRUN
     Param   1:    N    2097173
     Param   2:    N    514
     Param   3:    N    0
     Param   4:    N    2097173
     Param   5:    N    8
     Local   1:    O    Class: TBTNBMP
   TWINDOW:ACTIVATE
     Param   1:    N    5506110
   TAPPLICATION:ACTIVATE
     Param   1:    C    "NORMAL"
     Param   2:    U    
     Param   3:    U    
     Param   4:    U    
     Param   5:    B    {|| ... }
     Param   6:    B    {|| ... }
     Param   7:    U    
     Param   8:    B    {|| ... }
     Param   9:    U    
     Param  10:    U    
     Param  11:    U    
     Param  12:    U    
     Param  13:    U    
     Param  14:    U    
     Param  15:    U    
     Param  16:    U    
     Param  17:    B    {|| ... }
     Param  18:    U    
     Param  19:    U    
     Param  20:    L    .F.
     Local   1:    O    Class: TWINDOW
     Local   2:    U    
     Local   3:    U    
   MAIN
     Local   1:    O    Class: TAPPLICATION

Linked RDDs
===========
   DBF
   DBFFPT
   DBFBLOB
   DBFCDX
   DBFNTX

DataBases in use
================

  1:    TI                                 RddName: DBFCDX
     ==============================
     RecNo    RecCount    BOF   EOF
          1            0      .T.   .T.

     Indexes in use                        TagName
        => VAL(Codice)                        PRCODIGO

     Relations in use

  2:    PR                                 RddName: DBFCDX
     ==============================
     RecNo    RecCount    BOF   EOF
          1            4      .F.   .F.

     Indexes in use                        TagName
        => VAL(Codice)                        PRCODIGO
           UPPER(Descri)                      PRDESC

     Relations in use

  3: => PE                                 RddName: DBFCDX
     ==============================
     RecNo    RecCount    BOF   EOF
          3            3      .F.   .F.

     Indexes in use                        TagName
        => CODICE                             DPCODICE
           NOMEINTERO                         DPNOME

     Relations in use

Classes in use:
===============
     1 ERROR
     2 HBCLASS
     3 HBOBJECT
     4 TAPPLICATION
     5 TFONT
     6 TWINDOW
     7 TCONTROL
     8 TBITMAP
     9 TIMAGE
    10 TINI
    11 TRECT
    12 TGET
    13 TMULTIGET
    14 TCOMBOBOX
    15 TICON
    16 TBRUSH
    17 TMENU
    18 TREG32
    19 TMENUITEM
    20 TMSGBAR
    21 TMSGITEM
    22 TTIMER
    23 TCURSOR
    24 TBAR
    25 TBTNBMP
    26 TDIALOG
    27 TSAY
    28 TPROGRESS
    29 TSTRUCT

Memory Analysis
===============
      736 Static variables

   Dynamic memory consume:
      Actual  Value:    1769472 bytes
      Highest Value:    1769472 bytes
Any solution pls ?

Re: Strange error to converte a file

Posted: Mon Jan 04, 2021 10:07 am
by cnavarro
Try with

Code: Select all

AEval( aTmp, { |c,i| aTmp[ i ] := hb_aTokens( c, ',' ) } )
 

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 11:10 am
by Silvio.Falconi
cnavarro wrote:Try with

Code: Select all

AEval( aTmp, { |c,i| aTmp[ i ] := hb_aTokens( c, ',' ) } )
 

Sorry the error in here

if cBuf[ -1 ] == 26 / // check and remove Ctrl-Z Line 3800
cBuf := Left( cBuf, Len( cBuf ) - 1 )
endif

log file

Code: Select all

Application
===========
   Path and name: C:\Work\Prg\TimeCard\Timecard.Exe (32 bits)
   Size: 7,934,464 bytes
   Compiler version: Harbour 3.2.0dev (r1904111533)
   FiveWin  version: FWH 20.12
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.1, Build 7600 

   Time from start: 0 hours 0 mins 58 secs 
   Error occurred at: 05-01-2021, 12:05:52
   Error description: Error BASE/1068  Parametro errato: accesso all'array
   Args:
     [   1] = C   UserName;Activity;Work Date;Time Worked
Falconi Silvio;In;30-12-2020;08:07
Falconi Silvio;Out;30-12-2020;14:12
Falconi Silvio;In;29-12-2020;08:05
Falconi Silvio;Out;29-12-2020;14:22
Falconi Silvio;In;28-12-2020;08:02
Falconi Silvio;Out;28-12-2020;14:02
Falconi Silvio;In;23-12-2020;07:57
Falconi Silvio;Out;23-12-2020;14:01
Falconi Silvio;In;22-12-2020;08:04
Falconi Silvio;Out;22-12-2020;14:02
Falconi Silvio;In;21-12-2020;08:10
Falconi Silvio;Out;21-12-2020;14:00
Falconi Silvio;In;18-12-2020;08:10
Falconi Silvio;Out;18-12-2020;14:09
Falconi Silvio;In;17-12-2020;08:11
Falconi Silvio;Out;17-12-2020;14:03
Falconi Silvio;In;16-12-2020;08:01
Falconi Silvio;Out;16-12-2020;14:04
Falconi Silvio;In;15-12-2020;08:02
Falconi Silvio;Out;15-12-2020;14:05
Falconi Silvio;In;14-12-2020;07:56
Falconi Silvio;Out;14-12-2020;14:11
Falconi Silvio;In;12-12-2020;08:18
Falconi Silvio;Out;12-12-2020;14:05
Falconi Silvio;In;11-12-2020;07:58
Falconi Silvio;Out;11-12-2020;14:02
Falconi Silvio;In;10-12-2020;08:09
Falconi Silvio;Out;10-12-2020;14:10
Falconi Silvio;In;9-12-2020;08:15
Falconi Silvio;Out;9-12-2020;14:03
Falconi Silvio;In;7-12-2020;07:59
Falconi Silvio;Out;7-12-2020;14:03
Falconi Silvio;In;5-12-2020;08:07
Falconi Silvio;Out;5-12-2020;14:13
Falconi Silvio;In;4-12-2020;07:59
Falconi Silvio;Out;4-12-2020;14:04
Falconi Silvio;In;3-12-2020;07:56
Falconi Silvio;Out;3-12-2020;14:00
Falconi Silvio;In;2-12-2020;08:11
Falconi Silvio;Out;2-12-2020;14:00
Falconi Silvio;In;1-12-2020;07:59
Falconi Silvio;Out;1-12-2020;14:02
     [   2] = N   -1

Stack Calls
===========
   Called from: source\PCartellino.prg => CSV_TO_DATA( 3800 )
   Called from: source\PCartellino.prg => CARICOFROMWEB( 3535 )
   Called from: source\PCartellino.prg => (b)CARTELLINO( 614 )

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 1:15 pm
by karinha
Legal! No me genera error.

https://i.imgur.com/2Lyllej.png

Image

Regards.

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 3:21 pm
by FranciscoA
karinha wrote:Legal! No me genera error.
Regards.
Here it does not generate errors either.

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 3:30 pm
by karinha
FranciscoA wrote:
karinha wrote:Legal! No me genera error.
Regards.
Here it does not generate errors either.
Teste este también Francisco, porfa.

Code: Select all

#include "FiveWin.ch"

FUNCTION test()

   LOCAL cFile := cGetFile( "Timbrature (*.csv) | *.csv", "Selezionare un file", 1, )
   LOCAL aData := {}

   aData := Csv_To_Data( cfile )

   xBrowse( adata )

RETURN nil

FUNCTION Csv_To_Data( cfile )

   LOCAL cBuf, i, nFLines, aTmp, aHeaders

   // carico file csv
   nFLines := FLineCount( cFile )

   i := 1

   cBuf := MemoRead( cFile )

   cBuf := TiraTraco( cBuf )

   // parse and make a multi dimentional array
   IF cBuf[ -1 ] == 26 // check and remove Ctrl-Z <--------------------

      cBuf := Left( cBuf, Len( cBuf ) - 1 )

   ENDIF

   IF Right( cBuf, 2 ) != CRLF

      // pad with CRLF if needed, not to miss the last line
      cBuf += CRLF

   ENDIF

   cBuf := StrTran( cBuf, CRLF, Chr( 10 ) )

   aTmp := hb_aTokens( cBuf, Chr( 10 ) )

// AEval( aTmp, { |c, i| aTmp[ i ] := hb_aTokens( c, ';' ) } )
   AEval( aTmp, { |c, i| aTmp[ i ] := hb_aTokens( c, ',' ) } )

   aHeaders := aTmp[ 1 ]

   aTmp := ADel( aTmp, 1 )

   aSize( aTmp, Len( aTmp ) - 1 )

RETURN aTmp

Function TiraTraco(xStr)

   xStr := StrTran(xStr,"-","")
   xStr := StrTran(xStr,",",";")
   xStr := StrTran(xStr, '"', '' )
   xStr := StrTran(xStr,";",",")

Return(xStr)
 
Regards, Saludos.

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 3:58 pm
by Silvio.Falconi
karinha wrote:Legal! No me genera error.

https://i.imgur.com/2Lyllej.png

Image

Regards.
as I explain above it create error on my application , it not create error if i use it alone

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 4:56 pm
by FranciscoA
karinha wrote:
FranciscoA wrote:
karinha wrote:Legal! No me genera error.
Regards.
Here it does not generate errors either.
Teste este también Francisco, porfa.

Code: Select all

#include "FiveWin.ch"

FUNCTION test()

   LOCAL cFile := cGetFile( "Timbrature (*.csv) | *.csv", "Selezionare un file", 1, )
   LOCAL aData := {}

   aData := Csv_To_Data( cfile )

   xBrowse( adata )

RETURN nil

FUNCTION Csv_To_Data( cfile )

   LOCAL cBuf, i, nFLines, aTmp, aHeaders

   // carico file csv
   nFLines := FLineCount( cFile )

   i := 1

   cBuf := MemoRead( cFile )

   cBuf := TiraTraco( cBuf )

   // parse and make a multi dimentional array
   IF cBuf[ -1 ] == 26 // check and remove Ctrl-Z <--------------------

      cBuf := Left( cBuf, Len( cBuf ) - 1 )

   ENDIF

   IF Right( cBuf, 2 ) != CRLF

      // pad with CRLF if needed, not to miss the last line
      cBuf += CRLF

   ENDIF

   cBuf := StrTran( cBuf, CRLF, Chr( 10 ) )

   aTmp := hb_aTokens( cBuf, Chr( 10 ) )

// AEval( aTmp, { |c, i| aTmp[ i ] := hb_aTokens( c, ';' ) } )
   AEval( aTmp, { |c, i| aTmp[ i ] := hb_aTokens( c, ',' ) } )

   aHeaders := aTmp[ 1 ]

   aTmp := ADel( aTmp, 1 )

   aSize( aTmp, Len( aTmp ) - 1 )

RETURN aTmp

Function TiraTraco(xStr)

   xStr := StrTran(xStr,"-","")
   xStr := StrTran(xStr,",",";")
   xStr := StrTran(xStr, '"', '' )
   xStr := StrTran(xStr,";",",")

Return(xStr)
 
Regards, Saludos.
Karinha:
Your code reproduces the error mentioned by Silvio.
Error description: Error BASE/1070 Argument error: ==
Args:
[ 1] = C
[ 2] = N 26

Regards.

Re: Strange error to converte a file

Posted: Tue Jan 05, 2021 5:05 pm
by FranciscoA
Karinha:
My mistake. Your code works fine.

The error occurs when the .csv file cannot be found.
I had not created it.

Re: Strange error to converte a file

Posted: Wed Jan 06, 2021 11:48 am
by karinha
Entonces, debrias ser asi mi amigo Francisco? Ó Tiéns algo mejor?

Code: Select all

// arquivo c:\fwh\samples\SILVIO.CSV - SILVIOCS.PRG

#include "FiveWin.ch"

FUNCTION SILVIO_CSV()

   LOCAL cFile := cGetFile( "Timbrature (*.csv) | *.csv", "Selezionare un file", 1, )
   LOCAL aData := {}

   IF .NOT. EMPTY( cFile )

      aData := Csv_To_Data( cfile )

      xBrowse( adata )

   ELSE

      MsgInfo( "Selezionare un file", "Selezionare un file" )

   ENDIF

RETURN nil

FUNCTION Csv_To_Data( cfile )

   LOCAL cBuf, i, nFLines, aTmp, aHeaders

   // carico file csv
   nFLines := FLineCount( cFile )

   i := 1

   cBuf := MemoRead( cFile )

   cBuf := TiraTraco( cBuf )

   // parse and make a multi dimentional array
   IF cBuf[ -1 ] == 26 // check and remove Ctrl-Z <--------------------

      cBuf := Left( cBuf, Len( cBuf ) - 1 )

   ENDIF

   IF Right( cBuf, 2 ) != CRLF

      // pad with CRLF if needed, not to miss the last line
      cBuf += CRLF

   ENDIF

   cBuf := StrTran( cBuf, CRLF, Chr( 10 ) )

   aTmp := hb_aTokens( cBuf, Chr( 10 ) )

// AEval( aTmp, { |c, i| aTmp[ i ] := hb_aTokens( c, ';' ) } )
   AEval( aTmp, { |c, i| aTmp[ i ] := hb_aTokens( c, ',' ) } )

   aHeaders := aTmp[ 1 ]

   aTmp := ADel( aTmp, 1 )

   aSize( aTmp, Len( aTmp ) - 1 )

RETURN aTmp

Function TiraTraco(xStr)

   xStr := StrTran(xStr,"-","")
   xStr := StrTran(xStr,",",";")
   xStr := StrTran(xStr, '"', '' )
   xStr := StrTran(xStr,";",",")

Return(xStr)
 
Regards, saludos.

Re: Strange error to converte a file

Posted: Wed Jan 06, 2021 5:56 pm
by Silvio.Falconi
often my name is used in this forum too many times to take the piss out of me, now if I insert something immediately my name becomes a function or you do the chorus to tell me that the function works very well,

but the problem is not the function used alone but in context within an application, that csv file is taken from the internet where I created a small program for the acquisition of work access times for a small company.

As I have already explained above if I use it as a simple test it does not make any errors, if instead I insert it into a program I get that error maybe somewhere there is a cbuf that has another value

Re: Strange error to converte a file

Posted: Wed Jan 06, 2021 8:01 pm
by nageswaragunupudi
if cBuf[ -1 ] == 26
This works in xHarbour but does not work in Harbour.

So, instead of this code (which works with xHarbour, but not with Harbour)

Code: Select all

if cBuf[ -1 ] == 26 // check and remove Ctrl-Z <--------------------
cBuf := Left( cBuf, Len( cBuf ) - 1 )
endif
 
use

Code: Select all

if Right( cBuf, 1 ) == Chr( 26  )// check and remove Ctrl-Z <--------------------
cBuf := Left( cBuf, Len( cBuf ) - 1 )
endif
 
or much simpler

Code: Select all

cBuf := RemRight( cBuf, 26 )
 

Re: Strange error to converte a file

Posted: Wed Jan 06, 2021 9:33 pm
by Silvio.Falconi
It's right
thanks mr Rao the old app was compiled with xharbour

I not saw it
the function of csv was by otto and i taken it on forum

Regards