Page 1 of 1

call toDbf() from xbrowser command line

Posted: Tue Nov 24, 2020 10:51 am
by Marc Venken
I want to call Xbrowser with extra functions...
I open the file, must change the colums (prefered with Xbrcolselector function to tag more than 1 field)
and than save the file with the selected fields.

Now it errors out...

Application
===========
Path and name: C:\Programmas\fotoselect\TEST.EXE (32 bits)
Size: 4,928,512 bytes
Compiler version: Harbour 3.2.0dev (r1506171039)
FiveWin version: FWH 19.12
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 16 secs
Error occurred at: 24/11/2020, 11:48:42
Error description: Error BASE/1003 Variable does not exist: CODE

Stack Calls
===========
Called from: => DBUSEAREA( 0 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:TODBF( 10453 )
Called from: => (b)EVAL( 11635 )
Called from: .\source\classes\WINDOW.PRG => TCONTROL:RBUTTONDOWN( 2150 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:RBUTTONDOWN( 5178 )
Called from: => TWINDOW:HANDLEEVENT( 0 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1801 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11223 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3559 )
Called from: => DIALOGBOXINDIRECT( 0 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 304 )
Called from: .\source\function\XBROWSER.PRG => XBROWSE( 278 )
Called from: .\TEST1.PRG => CSVTRANSFORM( 11635 )
Called from: .\TEST1.PRG => (b)BUILDMENU( 5650 )

Code: Select all

//xBrowser("hunt") SETUP (oBrw:bRclicked:={ |r,c,f,o| o:todbf("temp.dbf")})
xBrowser("&cDbf") SETUP (oBrw:bRclicked:={ |r,c,f,o| xbrowse(o), o:todbf("temp.dbf")})

//xBrowser("hunt") SETUP (oBrw:bRclicked:={ |r,c,f,o| XbrColSelector( o )})


//xBrowser("hunt") SETUP (oBrw:bRclicked:={ |r,c,f,o| XbrColSelector( oBrw ),o:todbf(cFile ,,,.t.)})
//xBrowser("hunt") SETUP (oBrw:bRClickHeaders:={|r,c,f,o| XbrColSelector( o ), o:todbf("hunt" ,,,.t.) } )


//oBrw:ToDbf( cFile, bProgress, aCols, lPrompt )

function XbrColSelector( oBrowse )

   local oDlg, oBrw
   local aSave    := aCopy( oBrowse:aCols )
   local cSavefile:="Temp.dbf"

   DEFINE DIALOG oDlg SIZE 300,400 PIXEL TRUEPIXEL

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oBrowse:aCols ;
      COLUMNS "lHide", "cHeader" ;
      HEADERS "", "Header" ;
      COLSIZES 40, 100 ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :nStretchCol   := 2
      WITH OBJECT :aCols[ 1 ]
         :bEditValue    := { |x| If( x == nil, !oBrw:aRow:lHide, oBrw:aRow:lHide := !x ) }
         :SetCheck( nil, .t. )
         :nHeadBmpNo    := 2
      END
      :CreateFromCode()
   END

//   @ 20,05 BTNBMP PROMPT "DBF" SIZE 80,30 FLAT PIXEL OF oDlg ACTION (cSaveFile:=msgget("Filename",,@cSaveFile), oBrowse:todbf( cSaveFile ,,,.t.))
   @ 20,05 BTNBMP PROMPT "DBF" SIZE 80,30 FLAT PIXEL OF oDlg ACTION oBrowse:todbf(cSaveFile,,,.t.)
   @ 20,90 BTNBMP PROMPT "ALL" SIZE 80,30 FLAT PIXEL OF oDlg ACTION (AEval( oBrowse:aCols, { |o| o:lHide := .f. } ),oDlg:End() )
   @ 20,180 BTNBMP PROMPT "Close" SIZE 80,30 FLAT PIXEL OF oDlg ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

   oBrowse:Refresh()

return nil



 

Re: call toDbf() from xbrowser command line

Posted: Mon Nov 30, 2020 10:21 am
by Marc Venken
I'm not using it with xbrowser command, but now from a normal xbrowse()

The browse started with many colums and I reduced them to just the 4 I want.
I reduced them with the function XbrColSelector( oBrowse ) below.


I'm using todbf() the wrong way, because I get not the result i want..
The browse has other column names and the todbf = using fieldnames i guess

There is a post from Mr. Rao that there are 3 options (dbf fields, oBrw: columns names) to put in a array, but for me only dbf seems to work.
Any sample from Xbrowse options ? I need the changed headernames to become the fieldnames of the new files.

Image

Code: Select all

@  20,540 BTNBMP oBtn OF oDlg2 SIZE 100, 35 NOBORDER PROMPT "Export Dbf" 2007 ACTION exportdbf(oBrw4) FONT oBold CENTER

function exportdbf(oBrw)
  LOCAL cSavefile:=space(15)
  if msgyesno("Export to dbf")
    cSaveFile:=msgget("Filename + '.dbf'",,@cSaveFile)
    oBrw:todbf("Test.dbf")  //  cSavefile not used for the test..  
  endif
return


 

Re: call toDbf() from xbrowser command line

Posted: Tue Dec 08, 2020 5:15 pm
by nageswaragunupudi
MsgGet() returns .t. or .f. not the new value.
Please change this function

Code: Select all

function exportdbf(oBrw)
  LOCAL cSavefile:=space(15)
  if msgyesno("Export to dbf")
    cSaveFile:=msgget("Filename + '.dbf'",,@cSaveFile)
    oBrw:todbf("Test.dbf")  //  cSavefile not used for the test..  
  endif
return
 
as

Code: Select all

function exportdbf(oBrw)
  LOCAL cSavefile:=space(15)
  if msgyesno("Export to dbf")
    if msgget("Filename + '.dbf'",,@cSaveFile) .and. !Empty( cSaveFile )
    oBrw:todbf(AllTrim( cSaveFile ))  //  cSavefile not used for the test..  
  endif
return nil
 

Re: call toDbf() from xbrowser command line

Posted: Tue Dec 08, 2020 5:24 pm
by nageswaragunupudi
Syntax of ToDbf()

Code: Select all

ToDbf( cFile, ;  // dbf file name
          [ bProgress ], ; For meter
          [ aCols ], ; // Array of column objects
          [ lPrompt ] ; default .f. If .t., a dialog appears for edititing the structure of dbf
)
Even if there are many columns, we can save only selected columns by specifying { oBrw:oCol( "HEADER1" ), oBrw:oCol( "HEADER2" ), ... } as the 3rd parameter.

In the present implementation, column headers are used as field names. There is no provision now to map different field names for the columns. We may consider implementing in the future.

It is possible to specify .T. as the 4th parameter and then edit the structure manually.
Please try.
Please let us know if you need any more clarifications.