operaciones entre campos en un xBrowse
-
- Posts: 212
- Joined: Wed Apr 07, 2021 3:56 pm
operaciones entre campos en un xBrowse
Buenas tardes. necesito mostrar en un a columna de un xBrowse el resultado de la resta de campos de acuero a una determinada situacion.
algo asi : if (impapag=0,("importe" - "monto"),("impapag"-"monto")) donde tanto impapag como importe como monto son campos de la misma base.
gracias
algo asi : if (impapag=0,("importe" - "monto"),("impapag"-"monto")) donde tanto impapag como importe como monto son campos de la misma base.
gracias
- cmsoft
- Posts: 1297
- Joined: Wed Nov 16, 2005 9:14 pm
- Location: Mercedes - Bs As. Argentina
- Been thanked: 2 times
Re: operaciones entre campos en un xBrowse
Code: Select all | Expand
oBrw:aCols[5]:bStrData := {|| if (base->impapag=0,base->importe - base->monto, base->impapag - base->monto)}
Re: operaciones entre campos en un xBrowse
Cesar prueba en su lugar la data :bEditValue
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: operaciones entre campos en un xBrowse
We recommend a very simple way.
Directly include the expression in your columns clause like this:
We highly recommend using this syntax.
This syntax is portable and can be used with any datasource DBF, TDatabase, ADO, MySql/MariaDB, etc.
Here is a working sample
If your version of FWH is not very old, you can also write:

The expression can be of any degree of complexity, but should be macro expandable.
Do not use alias names. XBrowse applies the correct alias.
Directly include the expression in your columns clause like this:
Code: Select all | Expand
@ r,c XBROWSE oBrw SIZE w,h OF oDlg ;
DATASOURCE Alias() ;
COLUMNS "IMPAPAG","IMPORTE","MONTO","IF(IMPAPAG=0,IMPORTE-MONTO,IMPAPAG-MONTO)" ;
HEADERS nil, nil, nil, "RESULT"
We highly recommend using this syntax.
This syntax is portable and can be used with any datasource DBF, TDatabase, ADO, MySql/MariaDB, etc.
Here is a working sample
Code: Select all | Expand
#include "fivewin.ch"
function Main()
FWNumFormat( "E", .t. )
XBROWSER "invitems.dbf" ;
COLUMNS "ITEMCODE", "QUANTITY", "PRICE", "QUANTITY*PRICE" ;
SETUP ( oBrw:aCols[ 4 ]:cHeader := "VALUE", ;
oBrw:aCols[ 4 ]:cEditPicture := NUMPICT(9,2) )
return nil
If your version of FWH is not very old, you can also write:
Code: Select all | Expand
#include "fivewin.ch"
function Main()
FWNumFormat( "E", .t. )
XBROWSER "invitems.dbf" ;
COLUMNS "ITEMCODE", "QUANTITY", "PRICE", ;
"QUANTITY*PRICE AS VALUE PICT '@E 999,999.99'"
return nil

The expression can be of any degree of complexity, but should be macro expandable.
Do not use alias names. XBrowse applies the correct alias.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- cmsoft
- Posts: 1297
- Joined: Wed Nov 16, 2005 9:14 pm
- Location: Mercedes - Bs As. Argentina
- Been thanked: 2 times
Re: operaciones entre campos en un xBrowse
Mr. Rao, sieguiendo con el hilo, como podría hacer para reemplazar esto con el formato que ud. indica?
En la base de datos, guardo el código del tipo de turno
Code: Select all | Expand
aTurno := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
aEstado := {"Abierto","Cerrado","Abierto Parcial"}
aTipo := {"Completo","Cortado"}
REDEFINE XBROWSE oBrw DATASOURCE oQry;
COLUMNS "id","fecha","turno","nombre","tipo","estado","gnc","productos","ctacte","efectivo","tarjeta","retiros","faltante";
HEADERS "#","Fecha","Turno","Playero","Tipo","Estado","GNC","Productos","Cta.Cte","Efectivo","Tarjeta","Retiros","Falt/Sobr";
SIZES 50,70,90,120,70,90,70,70,70,70,70,70,70;
ID 111 OF oDlg AUTOSORT ON DBLCLICK (VerCerrar(),oBrw:Refresh())
REDEFINE SAY oBrw:oSeek PROMPT "" ID 113 OF oDlg
oQry:bOnChangePage := {|| oBrw:Refresh() }
oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}
oBrw:aCols[5]:bStrData := {|| IF(oQry:RecCount()> 0,aTipo[oQry:tipo]," ")}
oBrw:aCols[6]:bStrData := {|| IF(oQry:RecCount()> 0,aEstado[oQry:estado]," ")}
En la base de datos, guardo el código del tipo de turno
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: operaciones entre campos en un xBrowse
Code: Select all | Expand
// PRIVATE not LOCAL
PRIVATE aTurno := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
PRIVATE aEstado := {"Abierto","Cerrado","Abierto Parcial"}
PRIVATE aTipo := {"Completo","Cortado"}
REDEFINE XBROWSE oBrw DATASOURCE oQry;
COLUMNS "id","fecha","aTurno[turno]","nombre","aTipo[tipo]","aEstado[estado]","gnc","productos","ctacte","efectivo","tarjeta","retiros","faltante";
HEADERS "#","Fecha","Turno","Playero","Tipo","Estado","GNC","Productos","Cta.Cte","Efectivo","Tarjeta","Retiros","Falt/Sobr";
SIZES 50,70,90,120,70,90,70,70,70,70,70,70,70;
SORT nil,nil,"TURNO",nil,"TIPO","ESTADO" ;
ID 111 OF oDlg AUTOSORT ON DBLCLICK (VerCerrar(),oBrw:Refresh())
REDEFINE SAY oBrw:oSeek PROMPT "" ID 113 OF oDlg
oQry:bOnChangePage := {|| oBrw:Refresh() }
BUT
Please do not change your code.
In this particular case, I advise you to keep your existing code with this minor modification in the bStrData codeblock.
Instead of:
Code: Select all | Expand
oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}
modify as
Code: Select all | Expand
oBrw:aCols[3]:bStrData := {|x,o| aTurno[o:Value] }
Why this change?
Now your code does not refer to a specific oQry object.
Later if you want to change the software/browse to use ADO for MySql or FWH MariaLib libray, the same code works without any changes. This way the code is highly portable and can be used with any datasource.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- cmsoft
- Posts: 1297
- Joined: Wed Nov 16, 2005 9:14 pm
- Location: Mercedes - Bs As. Argentina
- Been thanked: 2 times
Re: operaciones entre campos en un xBrowse
Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error
Code: Select all | Expand
PROCEDURE TURNOS(cPermisos)
LOCAL oBar, hHand
PRIVATE aTurno := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
PRIVATE aEstado := {"Abierto","Cerrado","Abierto Parcial"}
PRIVATE aTipo := {"Completo","Cortado"}
Code: Select all | Expand
turnos.prg(12) Warning W0002 Ambiguous reference, assuming memvar 'ATURNO'
turnos.prg(13) Warning W0002 Ambiguous reference, assuming memvar 'AESTADO'
turnos.prg(14) Warning W0002 Ambiguous reference, assuming memvar 'ATIPO'
- cmsoft
- Posts: 1297
- Joined: Wed Nov 16, 2005 9:14 pm
- Location: Mercedes - Bs As. Argentina
- Been thanked: 2 times
Re: operaciones entre campos en un xBrowse
nageswaragunupudi wrote:Code: Select all | Expand
oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}
modify asCode: Select all | Expand
oBrw:aCols[3]:bStrData := {|x,o| aTurno[o:Value] }
Why this change?
Now your code does not refer to a specific oQry object.
Later if you want to change the software/browse to use ADO for MySql or FWH MariaLib libray, the same code works without any changes. This way the code is highly portable and can be used with any datasource.
Esto funciono perfecto!!!
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: operaciones entre campos en un xBrowse
cmsoft wrote:Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este errorCode: Select all | Expand
PROCEDURE TURNOS(cPermisos)
LOCAL oBar, hHand
PRIVATE aTurno := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
PRIVATE aEstado := {"Abierto","Cerrado","Abierto Parcial"}
PRIVATE aTipo := {"Completo","Cortado"}
Code: Select all | Expand
turnos.prg(12) Warning W0002 Ambiguous reference, assuming memvar 'ATURNO'
turnos.prg(13) Warning W0002 Ambiguous reference, assuming memvar 'AESTADO'
turnos.prg(14) Warning W0002 Ambiguous reference, assuming memvar 'ATIPO'
Either
Add declaration MEMVAR aTurno, aEstado, aTipo
OR
much easier
Add -a compiler switch in your script
( -a stands for automatic memvar declaration)
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- cmsoft
- Posts: 1297
- Joined: Wed Nov 16, 2005 9:14 pm
- Location: Mercedes - Bs As. Argentina
- Been thanked: 2 times
Re: operaciones entre campos en un xBrowse
Mr. Rao, desde que version de Fivewin funciona esta capacidad?
Porque me da un error, pero tengo la versión 16...
Porque me da un error, pero tengo la versión 16...