#include "fivewin.ch"
#include "xbrowse.ch"
function Main()
local aData, oDlg, oBrw, oCol
aData := { { 1,1,1}, ;
{ 2,2,2}, ;
{ 3,3,3}, ;
{ 4,4,4} }
DEFINE DIALOG oDlg SIZE 600,300 PIXEL TITLE 'XBROWSE RAGGED ARRAYS'
@ 10,10 XBROWSE oBrw ;
ARRAY aData ;
SIZE 180,100 PIXEL OF oDlg ;
FASTEDIT CELL
oCol = oBrw:AddCol()
oCol:bStrData = { || TRANSFORM( aData[obrw:nArrayAt,1],"999,999.99") }
oCol:cHeader = "First"
oCol:nEditType = EDIT_GET
oCol:cEditPicture = "999,999.99"
oCol:bOnPostEdit = { | oCol, xVal, nKey | aData[obrw:nArrayAt,1] := VAL(xVal) }
oCol = oBrw:AddCol()
oCol:bStrData = { || TRANSFORM( aData[obrw:nArrayAt,2],"999,999.99") }
oCol:cHeader = "second"
oCol:nEditType = EDIT_GET
oCol:cEditPicture = "999,999.99"
oCol:bOnPostEdit = { | oCol, xVal, nKey | aData[obrw:nArrayAt,2] := VAL(xVal) }
//-----------------------------------------//
oCol := oBrw:AddCol()
oCol:cHeader := "DEBE"
oCol:bStrData := { || Transform(aData[obrw:nArrayAt,3],"99999.99") }
oCol:nHeadStrAlign := AL_CENTER
oCol:nDataStrAlign := AL_RIGHT // AL_LEFT
oCol:nWidth := 60
oBrw:aCols[3]:nEditType := EDIT_GET
oBrw:aCols[3]:bOnPostEdit := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE, ;
(aData[obrw:nArrayAt,3]:=val(Transformo(xVal,5)) ,;
oBrw:refresh() ) , ) }
oBrw:aCols[3]:cEditPicture := "@B"
//-----------------------------------------//
oBrw:CreateFromCode()
@ 130,10 BUTTON "Next" OF oDlg ACTION oBrw:goDown() PIXEL
ACTIVATE DIALOG oDlg CENTERED
return nil
// ------------------------------------------------------------------------------------
Function Transformo(cValor,nDigitos) // nDigitos es cant numeros permitidos antes del punto
local cTransformada , nPunto , nLen , cCifra , cDecimales
nLen:=len(cValor)
nPunto:=at(".",cValor) // en nPunto tengo el lugar del punto o cero si no tiene punto
if nPunto > 1 .and. nPunto <> nLen
if nPunto < (nDigitos+1)
cCifra := substr(cValor,1,(nPunto-1))
cDecimales := substr(cValor,(nPunto+1),(nLen-nPunto))
if len(cDecimales) = 1
cDecimales:=cDecimales+"0"
endif
cTransformada:=cCifra+"."+cDecimales
Return cTransformada
endif
endif
if nPunto = 0 // si no tiene punto
if len(cValor) > nDigitos //3
cCifra := substr(cValor,1,nDigitos) // extraigo cifra sin punto decimal
cDecimales := substr(cValor,(nDigitos+1),(len(cValor)-(nDigitos+1)))
if len(cDecimales) = 1
cDecimales:=cDecimales+"0"
endif
if len(cDecimales) > 2
cDecimales:=str(round(val(cCifra+cDecimales),2))
cDecimales:=substr(cDecimales,(len(cDecimales)-2))
endif
endif
if len(cValor) < nDigitos
cCifra := alltrim(cValor)
cDecimales := "00"
endif
cTransformada:=cCifra+"."+cDecimales
Return cTransformada
endif
cTransformada := cValor
Return cTransformada
// ------------------------------------------------------------------------------------