this is my fields but I not use all on xbrowse
- Code: Select all Expand view RUN
- static cItemFlds := "INVNUM,SERIAL,ITEMIMG,ITEMCODE,ITEMNAME,QUANTITY,PRICE,TOTALQ,CHECK_IN,CHECK_OUT,DAYS,DISCOUNT,TOTAL,ITEMSTRUCT,ITEMMULTI,ITEMPRNA4,ITEMPRNPOS,RECNO()"
when I try to save there is an error because I save only 13 fields of 18 are on dbf
the error
- Code: Select all Expand view RUN
- pplication
===========
Path and name: C:\Work\Errori\aarray\test.Exe (32 bits)
Size: 3,931,648 bytes
Compiler version: Harbour 3.2.0dev (r1904111533)
FiveWin version: FWH 19.05
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200
Time from start: 0 hours 0 mins 28 secs
Error occurred at: 07/11/19, 09:40:03
Error description: Error BASE/1132 Bound error: array access
Args:
[ 1] = A { ... } length: 13
[ 2] = N 18
Stack Calls
===========
Called from: .\source\function\DBFFUNC2.PRG => FW_FIELDSPUT( 789 )
Called from: .\source\function\DBFFUNC2.PRG => (b)FW_SAVEARRAYTODBF( 737 )
Called from: => AEVAL( 0 )
Called from: .\source\function\DBFFUNC2.PRG => FW_SAVEARRAYTODBF( 737 )
Called from: test.prg => TEST( 222 )
I made a small test
- Code: Select all Expand view RUN
#include "fivewin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO
static cItemFlds := "INVNUM,SERIAL,ITEMIMG,ITEMCODE,ITEMNAME,QUANTITY,PRICE,TOTALQ,CHECK_IN,CHECK_OUT,DAYS,DISCOUNT,TOTAL,ITEMSTRUCT,ITEMMULTI,ITEMPRNA4,ITEMPRNPOS,RECNO()"
Function Test()
Local nInvoice := 1
Local aItems:= {}
local cDir :=".\data\"
local lNew := .t.
local lsave := .f.
local aGet[10]
local oDlg,oBrowse,oFolder
Local oBtnSave,oBtnClose
local oBtnArt1,oBtnArt2 // only for test
local dStagioneMin:= ctod("15/05/2019")
Local dStagioneMax:= ctod("15/09/2019")
BuilDbf(cDir)
if ! lNew
// copy on aItems the dbf ResItems
aItems := RESITEMS->( FW_DbfToArray( cItemFlds, { || RESITEMS->INVNUM == nInvoice } ) )
else
endif
DEFINE DIALOG oDlg TITLE "test array" SIZE 1120,650 ;
PIXEL TRUEPIXEL RESIZABLE
@ 1, 0 FOLDEREX oFolder OF oDlg SIZE oDlg:nWidth-585,oDlg:nHeight-390 PIXEL ;
PROMPT "Reservation","Payments"
@ 10,10 Button oBtnArt1 PROMPT "ARTICOLO 1" OF oFolder:aDialogs[1] size 100,40 ACTION INSERT_PRODUCT(aItems,nInvoice,1,oBrowse)
@ 10,120 Button oBtnArt2 PROMPT "ARTICOLO 2" OF oFolder:aDialogs[1] size 100,40 ACTION INSERT_PRODUCT(aItems,nInvoice,2,oBrowse)
@ 120, 02 XBROWSE oBrowse OF oFolder:aDialogs[1] ;
COLUMNS 3,4,5,6,7,8,9,10,11,12,13;
HEADERS "Ico","Tipo","Servizio","Q.tà","Costo","Tot p q.tà","Dal","al","Giorni","Sconto","Totale" ;
COLSIZES 55, 55,190,50,90,90,140,140,50,60,90 ;
PICTURES nil, nil,"@!","9999","€ 999,999.99","€ 999,999.99", "dd-mmmm-yyyy","dd-mmmm-yyyy","999","€ 999,999.99","€ 999,999.99";
ARRAY aItems ;
SIZE 100,82 PIXEL STYLE FLAT NOBORDER
ADD COLUMN TO XBROWSE oBrowse
bCalcRow := { || (oBrowse:aCols[ 6 ]:VarPut( oBrowse:aCols[ 4 ]:Value * oBrowse:aCols[ 5 ]:Value ),; // TOTALE PER QUANTITà = PREZZO x QUANTITà
oBrowse:aCols[ 9 ]:VarPut((oBrowse:aCols[ 8 ]:Value-oBrowse:aCols[ 7 ]:Value)+1),; // GIORNI = DATA OUT - DATA IN
oBrowse:aCols[ 11 ]:VarPut(( oBrowse:aCols[ 6 ]:value * oBrowse:aCols[ 9 ]:value)-oBrowse:aCols[ 10 ]:value),;
CalcoloTotali(oBrowse,aGet) )}
WITH OBJECT oBrowse
WITH OBJECT oBrowse:aCols[ 1]
:bFooter := { || Ltrim( Str( oBrowse:KeyNo() ) ) + " / " + LTrim( Str( oBrowse:KeyCount() ) )+" servizi" }
:lBmpStretch := .F.
:lBmpTransparent := .T.
:nwidth := 30
:bStrImage := {|| oBrowse:aArrayData[ oBrowse:narrayat][3] }
END
WITH OBJECT oBrowse:aCols[ 4]
:nWidth := 100
:nDataStrAlign := AL_CENTER
:AddBitmap( { FW_BmpPlus(), FW_BmpMinus() } )
// Right Button
:nEditType := EDIT_BUTTON
:bEditBlock := { |r,c,oCol| oCol:Value + 1 }
:nBtnBmp := 1
:lBtnTransparent := .t.
// Left Button
:bBmpData := { |v,lSel| If( lSel, 2, 0 ) }
:bBmpAction := { |oCol| IIF( oCol:Value>0,oCol:VarPut( oCol:Value - 1 ),) }
:bOnChange := bCalcRow
END
WITH OBJECT oBrowse:aCols[ 5]
:cEditPicture := '@ €99,999.99'
END
// colona per totale x qut riga
WITH OBJECT oBrowse:aCols[ 6]
* :nFooterType := AGGR_SUM
:cEditPicture := '@ €99,999.99'
END
WITH OBJECT oBrowse:aCols[ 7]
:nEditType := EDIT_BUTTON
:AddBitmap( "INVOICE_CALENDAR" )
:nBtnBmp := 1
:bEditBlock := { |r,c,o,k| XbrGetDate( o,"Seleziona una data",dStagioneMin,dStagioneMax ) }
:bOnChange := bCalcRow
END
WITH OBJECT oBrowse:aCols[ 8]
:nEditType := EDIT_BUTTON
:AddBitmap( "INVOICE_CALENDAR" )
:nBtnBmp := 1
:bEditBlock := { |r,c,o,k| XbrGetDate( o,"Seleziona una data",dStagioneMin,dStagioneMax ) }
:bOnChange := bCalcRow
END
WITH OBJECT oBrowse:aCols[ 10]
:nEditType := EDIT_GET
:bOnChange := bCalcRow
END
// colona per totale riga
WITH OBJECT oBrowse:aCols[ 11]
:nFooterType := AGGR_SUM
:cEditPicture := '@ €99,999.99'
END
WITH OBJECT oBrowse:aCols[ 12]
:AddBitmap({"INVOICE_CANCELLA","INVOICE_INCOLLA"})
:nBtnBmp := 1
:lBmpStretch := .F.
:lBmpTransparent := .T.
:nwidth := 30
:nEditType := EDIT_BUTTON
:bEditBlock := { ||DeleteRow(oBrowse,aGet) }
:nHeadBmpNo := 2
:cHeader := ""
:bLClickHeader := { ||DeleteAllRows(oBrowse,aGet) }
END
:lDrawBorder := .t.
:lHscroll := .F.
:l2007 := .F.
:l2015 := .T.
:nStretchCol := STRETCHCOL_WIDEST
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:lAllowRowSizing := .F.
:lAllowColSwapping := .F.
:lAllowColHiding := .F.
:nMarqueeStyle := MARQSTYLE_HIGHLROWMS
:CreateFromCode()
END
@ 520,680 BTNBMP oBtnSave ;
PROMPT "Save" SIZE 130,60 PIXEL OF oDlg;
RESOURCE "INVOICE_SAVE" FLAT RIGHT;
ACTION ( lSave := .T., oDlg:End() )
@ 520,780 BTNBMP oBtnClose ;
PROMPT "Chiudi" SIZE 130,60 PIXEL OF oDlg;
RESOURCE "INVOICE_EXIT" FLAT RIGHT;
ACTION ( oDlg:End() )
oDlg:bResized := <||
local oRect := oDlg:GetCliRect()
oFolder:nWidth := oRect:nRight-2
oFolder:nHeight := oRect:nBottom-60
oBrowse:nTop := oRect:nBottom-300
oBrowse:nHeight := oRect:nBottom-510
oBrowse:nWidth := oRect:nWidth - 15
oBtnSave:nLeft := oRect:nRight - 300
oBtnsave:nTop := oRect:nBottom - 60
oBtnClose:nLeft := oRect:nRight - 140
oBtnClose:nTop := oRect:nBottom - 60
oBtnArt1:nTop := oRect:ntop +60
oBtnArt1:nLeft := oRect:nLeft +20
oBtnArt2:nTop := oRect:ntop +60
oBtnArt2:nLeft := oRect:nLeft +250
return nil
>
ACTIVATE DIALOG oDlg CENTERED;
ON INIT EVAL(oDlg:bResized )
IF lSave
// save
AEval( aItems, { |a| a[ 1 ] := nInvoice } )
AEval( aItems, { |a,i| a[ 2 ] := i } ) // serial row
XBROWSER aItems
RESITEMS->( FW_SaveArrayToDBF( cItemFlds, aItems ) )
ENDIF
RETURN NIL
//--------------------------------------------------------------------------//
Function BuilDbf(cDir)
local aStructure
local i
if ! File( cDir+"ResItems.dbf" )
aStructure = {{ "InvNum", "C", 13, 0 }, ; //Invoice Num
{ "Serial", "N", 3, 0 }, ; // number of row
{ "ItemImg", "C", 120, 0 }, ; // image of Item
{ "ItemCode", "C", 2, 0 }, ; // Item Code E/S/ P
{ "ItemName", "C", 30, 0 }, ; // Item Description
{ "Quantity", "N", 3, 3 }, ; // quantity
{ "Price", "N", 9, 2 }, ; // price unit
{ "TotalQ", "N", 9, 2 }, ; // total for quantity
{ "Check_in" , "D", 8, 0 }, ; // date
{ "Check_out", "D", 8, 0 }, ; // date
{ "Days", "N", 3, 0 }, ; // total days
{ "Discount", "N", 9, 2 }, ; // descount
{ "Total", "N", 9, 2 }, ; // total row
{ "ItemStruct", "C", 30, 0 }, ; // structure if Itemcode is S
{ "ItemMulti" , "L", 1, 0 }, ; // Is multiple if Itemcode is S
{ "ItemPrnA4" , "L", 1, 0 }, ; // Print on A4 if Itemcode is S
{ "ItemPrnPos", "L", 1, 0 } } // Print on Pos if Itemcode is S
DBCreate( cDir+"ResItems", aStructure, "DBFCDX" )
ENDIF
USE &(cDir+"RESITEMS"+".dbf") VIA "DBFCDX" NEW
INDEX ON RESITEMS->INVNUM + STR( SERIAL, 3, 0 ) TAG invnum TO resitems
return nil
//--------------------------------------------------------------------------//
Function CalcoloTotali(oBrowse,aGet)
return nil
//--------------------------------------------------------------------------//
Static Function DeleteRow( oBrowse,aGet )
if msgYesNo( i18n("¿ E' sicuro che devo cancellare questa riga ?") )
iF ! oBrowse:nArrayAt = 1
if ! Empty( oBrowse:aArrayData )
ADel( oBrowse:aArrayData, oBrowse:nArrayAt, .t. )
oBrowse:MakeTotals()
oBrowse:Refresh()
CalcoloTotali(oBrowse,aGet)
endif
ELSE
MsgAlert("Non si può cancellare la prima riga")
Endif
Endif
return nil
//-------------------------------------------------------------------------//
//cancella tutte le righe
Static Function DeleteAllRows( oBrowse,aGet )
if msgYesNo( i18n("¿ E' sicuro che devo cancellare tutto ?") )
if ! Empty( oBrowse:aArrayData )
aSize( oBrowse:aArrayData, 0 )
oBrowse:Refresh()
oBrowse:MakeTotals()
CalcoloTotali(oBrowse,aGet)
endif
Endif
return nil
//--------------------------------------------------------------------------//
Function INSERT_PRODUCT(aItems,nInvoice,n,oBrowse)
local nSerial:= 0
Local cImmagine := ""
Local cCode := "S"
Local cProdotto := "Articolo"+Ltrim(str(n))
Local nQuantita := 1
Local nPrezzo := 10
Local ntotaleQ := nPrezzo*nQuantita
Local dCheck_in := date()
Local dCheck_out:= date()+1
Local nDays := dCheck_out-dCheck_in
Local nDiscount := 0
Local nTotal := 0
AaDd(aItems,{nInvoice,nSerial,cImmagine,cCode,cProdotto,nQuantita,nPrezzo,ntotaleQ,;
dCheck_in,dCheck_out,nDays,nDiscount,nTotal })
oBrowse:MakeTotals()
oBrowse:refresh()
return ni