Page 1 of 1

problem with dbUseArea - resolved -

PostPosted: Thu Apr 13, 2023 9:18 am
by Silvio.Falconi
DbUseArea( .F. ,"DBFCDX", ::aIdx[ i, 1 ],, .F. ) // not work


Error
Code: Select all  Expand view

   Time from start: 0 hours 0 mins 1 secs
   Error occurred at: 04/13/23, 11:21:28
   Error description: Error BASE/1068  Argument error: array access
   Args:
     [   1] = U  
     [   2] = N   1

Stack Calls
===========
   Called from: ut_reindex.PRG => TINDICE:ORDER( 108

 


Line 108 DbUseArea( .F. ,"DBFCDX", ::aIdx[ i, 1 ],, .F. )

I'm using a small class to index dbf files on my app

on test I use customer.dbf
Code: Select all  Expand view


#include 'fivewin.ch'
#include "constant.ch"
#INCLUDE "DIRECTRY.CH"

REQUEST DBFCDX

*MEMVAR oApp

Function Main()
   local cPathDbf:=".\data\"
    TIndice():New(cPathDbf):Activate()
    return nil


CLASS TIndice
   DATA aIdx
   DATA nIdx
   DATA oDlg
   DATA oFont
   DATA oMeter
   DATA cText
   DATA oSay
   DATA oAnimate
   DATA oBmp
   DATA oBtnok
   DATA oBtnExit
   DATA cPathDbf

   METHOD New() CONSTRUCTOR
   METHOD Activate()
   METHOD Order()
   END CLASS


METHOD New(cPathDbf) CLASS TIndice
   

   //test for  demo
   ::aIdx  := { ;
      { "
CUSTOMER" , { { "Upper(First)"                    , "First"  , "Customer"  }     ,;
                       { "
Upper(Last)"                     , "Last"   , "Customer"  }     ,;
                       { "
State"                           , "State"  , "Customer"  } } } ,;
                     }


  // ::cPathDbf  := cPathDbf

RETURN Self


METHOD Activate() CLASS TIndice
   LOCAL QSelf := Self

      local nBottomDlg   := 10
      local nRightDlg    := 40
      local nWd       := Max( nRightDlg * DLG_CHARPIX_W, 180 )
      local nHt       := nBottomDlg * DLG_CHARPIX_H

      ::oFont:= TFont():New( "
Tahoma", 0, 12,, )

   DEFINE DIALOG ::oDlg SIZE nWd, nHt PIXEL TRUEPIXEL  ;
        STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)

   SET FONT TO ::oFont OF ::oDlg

    @ 2,12 SAY ::oSay PROMPT ::cText SIZE 200,20  OF  ::oDlg  COLOR CLR_RED UPDATE

   ::oMeter  := TProgress():New( 4.8, 2, ::oDlg, , , , .f.,, 300, 15, "
", .f., .f. )
   ::oMeter:SetRange( 0, LEN( ::aIdx ) )
   ::oAnimate := TAnimate():New( 2.8, 2,  ::oDlg, .t., , 200, 12)

   @ 110,10  BUTTON ::oBtnOK Prompt "
Conferma" SIZE 55,20 PIXEL OF ::oDlg  ACTION ( ::Order() )
   @ 110,95  BUTTON ::oBtnExit Prompt "
Annulla"  SIZE 55,20 PIXEL OF ::oDlg  ACTION ( ::oDlg:End() )

   ACTIVATE DIALOG ::oDlg CENTERED;
         ON INIT ( QSelf:oAnimate:CopyFile(), QSelf:oAnimate:Play() )
RETURN NIL


METHOD Order() CLASS TIndice
   LOCAL i
   LOCAL k
   LOCAL bCode

    local cfor := "
!Deleted()"
    local bFor := "
{ || " + cfor + "}"

   ::oBtnOk:Disable()
   ::oBtnExit:Disable()


   *xbrowser ::aIdx

   FOR i := 1 TO LEN( ::aIdx )
     //dbUseArea( .t., ::cDriver, ::cFile, ::cAlias, ::lShared, ::lReadOnly )
       DbUseArea( .F. ,"
DBFCDX", ::aIdx[ i, 1 ],, .F. )

      FOR k := 1 TO LEN( ::aIdx[ i, 2 ] )

         bCode := "
{ || " + ::aIdx[ i, 2, k, 1 ] + "}"

         OrdCondSet(cFor,bFor,,,,, RECNO(),,,, )
         OrdCreate( ::aIdx[ i, 2, k, 3 ], ::aIdx[ i, 2, k, 2 ], ::aIdx[ i, 2, k, 1 ], &bCode )

      NEXT

      DbCloseArea()

      ::oMeter:nPosition := ( ( i * 100 ) / Len( ::aIdx ) )

   NEXT

   ::oBtnExit:Enable()

   MsgInfo( "
Azione terminata", "Index" )

   ::oDlg:End()

RETURN NIL



make error , but the procedure create the index good ...
How I can resolve ?

Re: problem with dbUseArea

PostPosted: Fri Apr 14, 2023 9:04 am
by Silvio.Falconi
any solution ?

Re: problem with dbUseArea

PostPosted: Fri Apr 14, 2023 9:07 am
by Antonio Linares
Dear Silvio,

param i seems to be nil

Re: problem with dbUseArea

PostPosted: Fri Apr 14, 2023 10:59 am
by Silvio.Falconi
Antonio Linares wrote:Dear Silvio,

param i seems to be nil


ok but How I can resolve ?
there is for i:= 1 to...

If i>LEN( ::aIdx )
exit
endif

I not understood before it run ok , now suddenly I went to recompile and it doesn't work how is it possible ?

Re: problem with dbUseArea

PostPosted: Fri Apr 14, 2023 12:04 pm
by Jimmy
hi Silvio,

have you try a Macro ?
Code: Select all  Expand view
  xName := ::aIdx[ i, 1 ]
   DbUseArea( .F. ,"DBFCDX", &(xName),, .F. )

Re: problem with dbUseArea

PostPosted: Fri Apr 14, 2023 12:57 pm
by Silvio.Falconi
Jimmy wrote:hi Silvio,

have you try a Macro ?
Code: Select all  Expand view
  xName := ::aIdx[ i, 1 ]
   DbUseArea( .F. ,"DBFCDX", &(xName),, .F. )

error

Re: problem with dbUseArea

PostPosted: Fri Apr 14, 2023 2:37 pm
by alerchster
Hi

The error comes from :: aIdx -> Len (::aIdx) result 2

This code works :-)

Code: Select all  Expand view


#include 'fivewin.ch'
#include "constant.ch"
#INCLUDE "DIRECTRY.CH"

REQUEST DBFCDX

*MEMVAR oApp

Function Main()
   local cPathDbf:=".\data\"
    TIndice():New(cPathDbf):Activate()
    return nil


CLASS TIndice
   DATA aIdx
   DATA nIdx
   DATA oDlg
   DATA oFont
   DATA oMeter
   DATA cText
   DATA oSay
   DATA oAnimate
   DATA oBmp
   DATA oBtnok
   DATA oBtnExit
   DATA cPathDbf

   METHOD New() CONSTRUCTOR
   METHOD Activate()
   METHOD Order()
   END CLASS


METHOD New(cPathDbf) CLASS TIndice
   

   //test for  demo

  ::aIdx  := { ;
      { "
CUSTOMER" , { { "Upper(First)"                    , "First"  , "Customer"  }     ,;
                       { "
Upper(Last)"                     , "Last"   , "Customer"  }     ,;
                       { "
State"                           , "State"  , "Customer"  } } } ,;
                     }


  // ::cPathDbf  := cPathDbf

RETURN Self


METHOD Activate() CLASS TIndice
   LOCAL QSelf := Self

      local nBottomDlg   := 10
      local nRightDlg    := 40
      local nWd       := Max( nRightDlg * DLG_CHARPIX_W, 180 )
      local nHt       := nBottomDlg * DLG_CHARPIX_H

      ::oFont:= TFont():New( "
Tahoma", 0, 12,, )

   DEFINE DIALOG ::oDlg SIZE nWd, nHt PIXEL TRUEPIXEL  ;
        STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)

   SET FONT TO ::oFont OF ::oDlg

    @ 2,12 SAY ::oSay PROMPT ::cText SIZE 200,20  OF  ::oDlg  COLOR CLR_RED UPDATE

   ::oMeter  := TProgress():New( 4.8, 2, ::oDlg, , , , .f.,, 300, 15, "
", .f., .f. )
   ::oMeter:SetRange( 0, LEN( ::aIdx ) )
   ::oAnimate := TAnimate():New( 2.8, 2,  ::oDlg, .t., , 200, 12)

   @ 110,10  BUTTON ::oBtnOK Prompt "
Conferma" SIZE 55,20 PIXEL OF ::oDlg  ACTION ( ::Order() )
   @ 110,95  BUTTON ::oBtnExit Prompt "
Annulla"  SIZE 55,20 PIXEL OF ::oDlg  ACTION ( ::oDlg:End() )

   ACTIVATE DIALOG ::oDlg CENTERED;
         ON INIT ( QSelf:oAnimate:CopyFile(), QSelf:oAnimate:Play() )
RETURN NIL


METHOD Order() CLASS TIndice
   LOCAL i
   LOCAL k
   LOCAL bCode

    local cfor := "
!Deleted()"
    local bFor := "
{ || " + cfor + "}"

   ::oBtnOk:Disable()
   ::oBtnExit:Disable()


   *xbrowser ::aIdx

   FOR i := 1 TO LEN( ::aIdx )-1                                                                                 // NEW is -1
      //dbUseArea( .t., ::cDriver, ::cFile, ::cAlias, ::lShared, ::lReadOnly )
      DbUseArea( .F. ,"
DBFCDX", ::aIdx[ i, 1 ],, .F. )

      FOR k := 1 TO LEN( ::aIdx[ i, 2 ] )

         bCode := "
{ || " + ::aIdx[ i, 2, k, 1 ] + "}"

         OrdCondSet(cFor,bFor,,,,, RECNO(),,,, )
         OrdCreate( ::aIdx[ i, 2, k, 3 ], ::aIdx[ i, 2, k, 2 ], ::aIdx[ i, 2, k, 1 ], &bCode )

      NEXT

      DbCloseArea()

      ::oMeter:nPosition := ( ( i * 100 ) / Len( ::aIdx ) )

   NEXT

   ::oBtnExit:Enable()

   MsgInfo( "
Azione terminata", "Index" )

   ::oDlg:End()

RETURN NIL

Re: problem with dbUseArea

PostPosted: Sat Apr 15, 2023 5:23 am
by alerchster
Code: Select all  Expand view


#include 'fivewin.ch'
#include "constant.ch"
#INCLUDE "DIRECTRY.CH"

REQUEST DBFCDX

*MEMVAR oApp

Function Main()
   local cPathDbf:=".\data\"
    TIndice():New(cPathDbf):Activate()
    //TIndice():Activate()
     return nil


CLASS TIndice
   DATA aIdx
   DATA nIdx
   DATA oDlg
   DATA oFont
   DATA oMeter
   DATA cText
   DATA oSay
   DATA oAnimate
   DATA oBmp
   DATA oBtnok
   DATA oBtnExit
   DATA cPathDbf

   METHOD New() CONSTRUCTOR
   METHOD Activate()
   METHOD Order()
   END CLASS


METHOD New(cPathDbf) CLASS TIndice
   

   //test for  demo
/*
  ::aIdx  := { ;
      { "
CUSTOMER" , { { "Upper(First)"                    , "First"  , "Customer"  }     ,;
                       { "
Upper(Last)"                     , "Last"   , "Customer"  }     ,;
                       { "
State"                           , "State"  , "Customer"  } } } ,;
                     }
*/
  ::aIdx  :=  { ;
      { "
CUSTOMER" , { { "Upper(First)"                    , "First"  , "Customer"  }     ,;
                       { "
Upper(Last)"                     , "Last"   , "Customer"  }     ,;
                       { "
State"                           , "State"  , "Customer"  } } } ;
                     }

//xbrowser(::aIdx)
 
  // ::cPathDbf  := cPathDbf

RETURN Self


METHOD Activate() CLASS TIndice
   LOCAL QSelf := Self

      local nBottomDlg   := 10
      local nRightDlg    := 40
      local nWd       := Max( nRightDlg * DLG_CHARPIX_W, 180 )
      local nHt       := nBottomDlg * DLG_CHARPIX_H

      ::oFont:= TFont():New( "
Tahoma", 0, 12,, )

   DEFINE DIALOG ::oDlg SIZE nWd, nHt PIXEL TRUEPIXEL  ;
        STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)

   SET FONT TO ::oFont OF ::oDlg

    @ 2,12 SAY ::oSay PROMPT ::cText SIZE 200,20  OF  ::oDlg  COLOR CLR_RED UPDATE

   ::oMeter  := TProgress():New( 4.8, 2, ::oDlg, , , , .f.,, 300, 15, "
", .f., .f. )
   ::oMeter:SetRange( 0, LEN( ::aIdx ) )
   ::oAnimate := TAnimate():New( 2.8, 2,  ::oDlg, .t., , 200, 12)

   @ 110,10  BUTTON ::oBtnOK Prompt "
Conferma" SIZE 55,20 PIXEL OF ::oDlg  ACTION ( ::Order() )
   @ 110,95  BUTTON ::oBtnExit Prompt "
Annulla"  SIZE 55,20 PIXEL OF ::oDlg  ACTION ( ::oDlg:End() )

   ACTIVATE DIALOG ::oDlg CENTERED;
         ON INIT ( QSelf:oAnimate:CopyFile(), QSelf:oAnimate:Play() )
RETURN NIL


METHOD Order() CLASS TIndice
   LOCAL i
   LOCAL k
   LOCAL bCode

    local cfor := "
!Deleted()"
    local bFor := "
{ || " + cfor + "}"

   ::oBtnOk:Disable()
   ::oBtnExit:Disable()


//   xbrowser ::aIdx

   FOR i := 1 TO LEN( ::aIdx )
     //dbUseArea( .t., ::cDriver, ::cFile, ::cAlias, ::lShared, ::lReadOnly )
      DbUseArea( .F. ,"
DBFCDX", ::aIdx[ i, 1 ],, .F. )

      FOR k := 1 TO LEN( ::aIdx[ i, 2 ] )

         bCode := "
{ || " + ::aIdx[ i, 2, k, 1 ] + "}"

         OrdCondSet(cFor,bFor,,,,, RECNO(),,,, )
         OrdCreate( ::aIdx[ i, 2, k, 3 ], ::aIdx[ i, 2, k, 2 ], ::aIdx[ i, 2, k, 1 ], &bCode )

      NEXT

      DbCloseArea()

      ::oMeter:nPosition := ( ( i * 100 ) / Len( ::aIdx ) )
   NEXT

   ::oBtnExit:Enable()

   MsgInfo( "
Azione terminata", "Index" )

   ::oDlg:End()

RETURN NIL

Re: problem with dbUseArea

PostPosted: Sun Apr 16, 2023 2:42 pm
by Silvio.Falconi
thanks , where was the error ?

Re: problem with dbUseArea

PostPosted: Sun Apr 16, 2023 5:08 pm
by alerchster
Hi

Last comma makes an blank line to array, and than aIdx(i,1) is empty for dbusearea where i=2 -works correct for i=1 but len(aIdx)=2 and then crash!

::aIdx := { ;
{ "CUSTOMER" , { { "Upper(First)" , "First" , "Customer" } ,;
{ "Upper(Last)" , "Last" , "Customer" } ,;
{ "State" , "State" , "Customer" } } } ,;
}

Re: problem with dbUseArea

PostPosted: Mon Apr 17, 2023 8:43 am
by Silvio.Falconi
alerchster wrote:Hi

Last comma makes an blank line to array, and than aIdx(i,1) is empty for dbusearea where i=2 -works correct for i=1 but len(aIdx)=2 and then crash!

::aIdx := { ;
{ "CUSTOMER" , { { "Upper(First)" , "First" , "Customer" } ,;
{ "Upper(Last)" , "Last" , "Customer" } ,;
{ "State" , "State" , "Customer" } } } ,;
}

I really didn't understand why I use that code elsewhere and for a long time so I hadn't changed it, I couldn't understand why it didn't work