Code: Select all
#include "Fivewin.ch"
#include "xBrowse.ch"
//------------------------------------------------//
Function Main() //Fap_2Arrays()
local oDlg, oCbx1,cVar1,cItems1:={}, oCbx2,cVar2,cItems2:={" "}
local aArr2
cItems1 := CreaArray1()
aArr2 := CreaArray2()
cVar1 := cItems1[1]
cVar2 := cItems2[1]
DEFINE DIALOG oDlg FROM 1,1 TO 300, 600 PIXEL TITLE "Prueba 2 ComboBox con Arrays"
@ 20, 10 COMBOBOX oCbx1 Var cVar1 ITEMS cItems1 SIZE 130,200 PIXEL OF oDlg ;
ON CHANGE ( cVar1 := cItems1[oCbx1:nAt], CargaItems2(cVar1, @cVar2, @cItems2, oCbx2, aArr2) )
@ 20,160 COMBOBOX oCbx2 Var cVar2 ITEMS cItems2 SIZE 130,200 PIXEL OF oDlg
@100,20 BUTTON "Salir" SIZE 100, 20 PIXEL OF oDlg ;
ACTION ( Msginfo("Bye..."), oDlg:End() )
CargaItems2(cVar1, @cVar2, @cItems2, oCbx2, aArr2)
ACTIVATE DIALOG oDlg CENTERED
Return nil
//------------------------------------------------//
Function CargaItems2(cVar1, cVar2, cItems2, oCbx2, aArr2)
local n, nLen := 4 //longitud del codigo
cItems2 := {}
For n := 1 to len(aArr2)
if Substr(aArr2[n],1,nLen) == Substr(cVar1,1,nLen)
aadd( cItems2, aArr2[n] )
endif
Next
/*
O asi:
AEval( aArr2, {|a| if(Substr(a,1,nLen) == Substr(cVar1,1,nLen), aadd(cItems2, a),) } )
*/
oCbx2:SetItems(cItems2)
cVar2 := cItems2[1]
oCbx2:Refresh()
oCbx2:Open()
Return nil
//----------------------------------//
Function CreaArray1()
local aArray := {}
aadd(aArray, "COD1 Cajas")
aadd(aArray, "COD2 Bancos")
aadd(aArray, "COD3 Cuentas por cobrar")
aadd(aArray, "COD4 Inventarios")
Return aArray
//----------------------------------//
Function CreaArray2()
local aArray := {}
aadd(aArray, "COD1 0001 Caja General")
aadd(aArray, "COD1 0002 Caja Chica")
aadd(aArray, "COD1 0003 Efectivo para cambio")
aadd(aArray, "COD2 0001 Banco Produccion")
aadd(aArray, "COD2 0002 Banco Mercantil")
aadd(aArray, "COD2 0003 Banco Nacional")
aadd(aArray, "COD2 0004 Banco Del Campo")
aadd(aArray, "COD2 0005 Banco Central")
aadd(aArray, "COD3 0001 Cliente 0001")
aadd(aArray, "COD3 0002 Cliente 0002")
aadd(aArray, "COD3 0003 Cliente 0003")
aadd(aArray, "COD3 0004 Cliente 0004")
aadd(aArray, "COD3 0005 Cliente 0005")
aadd(aArray, "COD4 0001 Gasolina")
aadd(aArray, "COD4 0002 Diesel")
aadd(aArray, "COD4 0003 Grasas")
aadd(aArray, "COD4 0004 Aceites")
aadd(aArray, "COD4 0005 Otros")
Return aArray