Page 1 of 1

Customer .dbf

Posted: Tue May 12, 2020 8:23 pm
by TimStone
I'm trying to run a sample, and it wants to use CUSTOMER.DBF. However I keep getting the error when trying to USE it that there is an unknown field type. I believe the first field is ID and the type is +. I finally saw this with an ASCII text editor.

The file cannot be opened in any of my file editors, ie. ADS Data Architect or DBU.

I found a Customer.ch in the samples directory and even linked it into the program.

The program I'm trying to test is EREP01.prg which I've linked into my main application. ( This is a pretty easy way I use for testing samples ).

Any ideas on how to get around this. The sample code is unmodified ( except to rename the function other than Main() ).

Tim

Re: Customer .dbf

Posted: Tue May 12, 2020 9:33 pm
by cnavarro
Tim, try with this version of FiveDbu
https://bitbucket.org/fivetech/fivewin- ... IVEDBU.EXE

Re: Customer .dbf

Posted: Tue May 12, 2020 10:56 pm
by TimStone
It opens as a Type +, but trying to use that file in a program built with FWH 20.04, Harbour, and MSVC, when executing, it does not see that field type. Of course, I'm using the RDDADS ...

So I tested it with DBFCDX and it opens the browse ... but the program I wanted to test is still failing ... will look further.

So that + field type is not going to work with ADS ...

Re: Customer .dbf

Posted: Wed May 13, 2020 12:37 am
by cnavarro
TimStone wrote:It opens as a Type +, but trying to use that file in a program built with FWH 20.04, Harbour, and MSVC, when executing, it does not see that field type. Of course, I'm using the RDDADS ...

So I tested it with DBFCDX and it opens the browse ... but the program I wanted to test is still failing ... will look further.

So that + field type is not going to work with ADS ...
I think the field type "+" is not supported with ADS

Re: Customer .dbf

Posted: Wed May 13, 2020 8:24 am
by nageswaragunupudi
AutoIncrement field in DBFCDX/DBFNTX is represented as "+".
AutoInc fields of DBFCDX/DBFNTX are not compatible with autoincrement field of ADS.

Older DBUs and other older DBF maintenance programs may not support recently implemented fieldtypes : +. =. @, V.
Such software need to be updated by their authors.

Re: Customer .dbf

Posted: Wed May 13, 2020 2:06 pm
by Silvio.Falconi
TimStone wrote:It opens as a Type +, but trying to use that file in a program built with FWH 20.04, Harbour, and MSVC, when executing, it does not see that field type. Of course, I'm using the RDDADS ...

So I tested it with DBFCDX and it opens the browse ... but the program I wanted to test is still failing ... will look further.

So that + field type is not going to work with ADS ...
on samples there is a file to build customers.dbf without + field

Re: Customer .dbf

Posted: Wed May 13, 2020 5:13 pm
by MOISES
Hello,

This is the fix for incremental fields:

Code: Select all

function New( cAlias, cFileName )

   local oDlg, oGet, oBrw, oBtn, cTitle, cNewAlias, oBrwNew, lCopy := .F.
   local cFieldName := Space( 10 ), cType := "Character", nLen := 10, nDec := 0
   local aFields := { Array( 4 ) }, cDbfName := Space( 8 ), aTemp
   local oLen, oDec, aType := { "AutoIncr", "Character", "Number", "Date", "Logical", "Memo", "ModTime" }
   local bChange := {|| If( cType == "AutoIncr",  ( nLen := 4,  nDec := 0, oDec:Disable()  ),),;
                        If( cType == "Character", ( nLen := 10, nDec := 0, oDec:Disable() ),),;
                        If( cType == "Number",    ( nLen := 10, nDec := 0, oDec:Enable()  ),),;
                        If( cType == "Date",      ( nLen := 8,  nDec := 0, oDec:Disable() ),),;
                        If( cType == "Logical",   ( nLen := 1,  nDec := 0, oDec:Disable() ),),;
                        If( cType == "Memo",      ( nLen := 10, nDec := 0, oDec:Disable() ),),;
                        If( cType == "ModTime",   ( nLen := 8, nDec := 0, oDec:Disable() ),),;
                        oDlg:Update() }
   local bEdit := {|| IF ( !Empty (aFields[1,1]) ,;
                      (oBtn:Enable (),;
                       cFieldName := aFields[oBrw:nArrayAt,1] ,;
                       cType := aFields[oBrw:nArrayAt,2] ,;
                       cType := aType[ aScan(aType, {|x| Left(x,1) = cType} )],;
                       Eval (bChange) ,;
                       nLen := aFields[oBrw:nArrayAt,3] ,;
                       nDec := aFields[oBrw:nArrayAt,4] ,;
                       oGet:SetPos( 0 ),;
                       oGet:SetFocus(),;
                       oDlg:Update() ) ,) ;
                     }
   local bSave := { || oBtn:Disable (),;
                      aFields[ oBrw:nArrayAt, 1 ] := cFieldname,;
                      aFields[ oBrw:nArrayAt, 2 ] := if( Left( cType, 1 ) = "A", "+", Left( cType, 1 ) ), ;
                      aFields[ oBrw:nArrayAt, 2 ] := if( Left( cType, 3 ) = "Mod", "=", Left( cType, 1 ) ), ;
                      aFields[ oBrw:nArrayAt, 3 ] := nLen,;
                      aFields[ oBrw:nArrayAt, 4 ] := nDec,;
                      oBrw:SetArray( aFields ),;
                      cFieldName := Space( 10 ),;
                      Eval( bChange ) ,;
                      oDlg:Update() ,;
                      oGet:SetPos( 0 ),;
                      oGet:SetFocus(),;
                      oBrw:GoBottom();
                      }

   if ! Empty( cAlias )
      aFields = ( cAlias )->( DbStruct() )
      cTitle = FWString( "Modify DBF structure" )
   else
      cTitle = FWString( "DBF builder" )
   endif

   DEFINE DIALOG oDlg TITLE cTitle SIZE 415, 500

   @ 0.5,  2 SAY FWString( "Field Name" ) OF oDlg SIZE 40, 8
   @ 0.5, 10 SAY FWString( "Type" ) OF oDlg SIZE 40, 8
   @ 0.5, 17 SAY FWString( "Len" )  OF oDlg SIZE 40, 8
   @ 0.5, 22 SAY FWString( "Dec" )  OF oDlg SIZE 20, 8

   @ 1.4, 1 GET oGet VAR cFieldName PICTURE "!!!!!!!!!!" OF oDlg SIZE 41, 11 UPDATE

   @ 1.3, 6.5 COMBOBOX cType ITEMS aType ;
      OF oDlg ON CHANGE Eval (bChange) UPDATE

   @ 1.4, 11.9 GET oLen VAR nLen PICTURE "999" OF oDlg SIZE 25, 11 UPDATE

   @ 1.4, 15.4 GET oDec VAR nDec PICTURE "999" OF oDlg SIZE 25, 11 UPDATE

   @ 0.9, 26 BUTTON FWString( "&Add" ) OF oDlg SIZE 45, 13 ;
      ACTION AddField( @aFields, @cFieldName, @cType, @nLen, @nDec, oGet, oBrw )

   @ 2.4, 26 BUTTON oBtn PROMPT FWString( "&Edit" ) OF oDlg SIZE 45, 13 ;
     ACTION Eval (bSave)

   @ 3.4, 26 BUTTON FWString( "&Delete" ) OF oDlg SIZE 45, 13 ;
     ACTION DelField( @aFields, @cFieldName, oGet, oBrw )

   @ 4.4, 26 BUTTON FWString( "Move &Up" ) OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt > 1,;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt - 1 ],;
                   aFields[ oBrw:nArrayAt - 1 ] := aTemp,;
                   oBrw:GoUp() ),)

   @ 5.4, 26 BUTTON FWString( "Move D&own" ) OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt < Len( aFields ),;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt + 1 ],;
                   aFields[ oBrw:nArrayAt + 1 ] := aTemp,;
                   oBrw:GoDown() ),)

   @ 11.8, 26 BUTTON FWString( "&Cancel" ) OF oDlg SIZE 45, 13 ;
      ACTION oDlg:End()

   @ 2.0, 1.8 SAY "Struct" OF oDlg SIZE 40, 8

   @ 3.0, 1 XBROWSE oBrw ARRAY aFields AUTOCOLS NOBORDER STYLE FLAT ;
      HEADERS FWString( "Name" ), FWString( "Type" ), FWString( "Len" ),;
              FWString( "Dec" ) ;
      COLSIZES 90, 55, 40, 40 ;
      SIZE 138, 183 OF oDlg ;
      ON DBLCLICK Eval (bEdit)

   StyleBrowse( oBrw )
   if lPijama
      oBrw:bClrStd := { || If( oBrw:KeyNo() % 2 == 0, ;
                            { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                            { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
      oBrw:bClrSel := { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }
   else
      oBrw:bClrStd := { || { nClrTxtBrw, nClrBackBrw }  }
      oBrw:bClrSel := { || { nClrBackBrw, RGB( 0x33, 0x66, 0xCC ) } }
   endif
   oBrw:CreateFromCode()

   @ 15.3, 1.4 SAY FWString( "DBF Name:" ) OF oDlg SIZE 40, 8

   if ! Empty( cAlias )
      cDbfName = cGetNewAlias( cAlias )
   endif

   @ 17.7, 6 GET cDbfName PICTURE "!!!!!!!!!!!!" OF oDlg SIZE 100, 11

   @ 12.8, 26 BUTTON If( Empty( cAlias ), FWString( "&Create" ), FWString( "&Save" ) ) ;
      OF oDlg SIZE 45, 13 ;
      ACTION ( If( ! Empty( cDbfName ) .and. Len( aFields ) > 0,;
          DbCreate( AllTrim( cDbfName ), aFields ),), oDlg:End(),;
          lCopy := .T.,;
          oBrwNew := Open( hb_CurDrive() + ":\" + CurDir() + "\" + AllTrim( cDbfName ) ) )

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( Eval ( bChange ), oBtn:Disable() ) ;
      VALID ! GETKEYSTATE( VK_ESCAPE )

   if ! Empty( cAlias ) .and. lCopy
      APPEND FROM ( cFileName )
      oBrwNew:Refresh()
   endif

return nil

//----------------------------------------------------------------------------//

function AddField( aFields, cFieldName, cType, nLen, nDec, oGet, oBrw )

   local cSymbol     := ""
   if Empty( cFieldName )
      oGet:SetPos( 0 )
      return nil
   endif



   /* Harbour extended field types https://vivaclipper.wordpress.com/2012/ ... n-harbour/ */
   if Upper( Left( cType, 1 ) ) = "A"
      cType :=  "+"

   elseif cType == "ModTime"
      cType :=  "="

   else
      cType := Upper( Left( cType, 1 ) )

   endif



   if Len( aFields ) == 1 .and. Empty( aFields[ 1 ][ 1 ] )
      aFields = { { cFieldName, cType, nLen, nDec } }
   else
      AAdd( aFields, { cFieldName, cType, nLen, nDec }  )
   endif

   oBrw:SetArray( aFields )
   oGet:VarPut( cFieldName := Space( 10 ) )
   oGet:SetPos( 0 )
   oGet:SetFocus()
   oBrw:GoBottom()

return nil

//----------------------------------------------------------------------------//