problem with dbUseArea - resolved -

Post Reply
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

problem with dbUseArea - resolved -

Post by Silvio.Falconi »

DbUseArea( .F. ,"DBFCDX", ::aIdx[ i, 1 ],, .F. ) // not work


Error

Code: Select all | Expand

   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


#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 ?
Last edited by Silvio.Falconi on Tue Apr 18, 2023 10:40 am, edited 1 time in total.
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: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: problem with dbUseArea

Post by Silvio.Falconi »

any solution ?
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
Antonio Linares
Site Admin
Posts: 42520
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 75 times
Contact:

Re: problem with dbUseArea

Post by Antonio Linares »

Dear Silvio,

param i seems to be nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: problem with dbUseArea

Post 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 ?
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
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: problem with dbUseArea

Post by Jimmy »

hi Silvio,

have you try a Macro ?

Code: Select all | Expand

   xName := ::aIdx[ i, 1 ]
   DbUseArea( .F. ,"DBFCDX", &(xName),, .F. )
greeting,
Jimmy
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: problem with dbUseArea

Post by Silvio.Falconi »

Jimmy wrote:hi Silvio,

have you try a Macro ?

Code: Select all | Expand

   xName := ::aIdx[ i, 1 ]
   DbUseArea( .F. ,"DBFCDX", &(xName),, .F. )
error
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
alerchster
Posts: 97
Joined: Mon Oct 22, 2012 4:43 pm
Has thanked: 2 times

Re: problem with dbUseArea

Post by alerchster »

Hi

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

This code works :-)

Code: Select all | Expand


#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
Regards

Ing. Anton Lerchster
User avatar
alerchster
Posts: 97
Joined: Mon Oct 22, 2012 4:43 pm
Has thanked: 2 times

Re: problem with dbUseArea

Post by alerchster »

Code: Select all | Expand


#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
Regards

Ing. Anton Lerchster
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: problem with dbUseArea

Post by Silvio.Falconi »

thanks , where was the error ?
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
alerchster
Posts: 97
Joined: Mon Oct 22, 2012 4:43 pm
Has thanked: 2 times

Re: problem with dbUseArea

Post 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" } } } ,;
}
Regards

Ing. Anton Lerchster
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: problem with dbUseArea

Post 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
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
Post Reply