PROCEDURE GetIndex()
local lcRoot,lcTabla,lcUse,lnFall,lnReind
Store 0 to lnFall,lnReind
LcRoot="RutadeTablas" && por ejemplo lcRoot="c:\MyApp\Datos" * Generalmente una propiedad de _screen.
* 1
LcTabla="COMPROD" && tabla de la que se generan las etiquetas de índice
lcUse=ADDBS(lcRoot)+"COMPROD"
&& si la tabla está abierta, la cerramos. Esto es muy bueno porque baja cualquier caché.
IF USED(lcTabla)
SELECT (lcTabla)
USE
ENDIF
USE (lcUse) IN 0 EXCLUSIVE
* Si la apertura en exclusive falla, se debe saltar el reindexado. En VP6 no existe TRY CATCH ENTRY, solamente tienes ON ERROR, pero lo puedes utilizar.
IF USED(lcTabla)
SELECT (lcTabla) && debes seleccionar la tabla siempre
WaitIndex(.T.) && llamado a la rutina WaitIndex()
INDEX ON NUMERO TAG CMPPNUM
INDEX ON IDCLIEN TAG CMPPID
INDEX ON DTOS(FECHA) TAG CMPPFE
INDEX ON ENTREGA TAG CMPTREG
USE && siempre debes cerrar la tabla después de crear las etiquetas.
lnReind = lnReind + 1
ELSE
lnFall=lnFall + 1
ENDIF
* 2
LcTabla="BUYMOV"
lcUse=ADDBS(lcRoot)+"COMPROD"
IF USED(lcTabla)
SELECT (lcTabla)
USE
ENDIF
USE (lcUse) IN 0 EXCLUSIVE
IF USED(lcTabla)
SELECT BUYTRAN
WaitIndex(.t.)
INDEX ON CODocumen+trim(ref) TAG BUYCOD
INDEX ON IDPROV+DTOS(VENCERA) TAG BUYTRAN
INDEX ON DTOS(VENCERA)+IDPROV TAG BUYVEN
INDEX ON IMPORTE TAG BTRIMP
USE
lnReind = lnReind + 1
ELSE
lnFall=lnFall + 1
ENDIF
* 3 Continúa con el resto de tablas a indexar
* Finaliza el proceso
WAIT CLEAR
Messagebox(ltrim(str(lnReind))+" Tablas reindexadas"+chr(13);
+ltrim(str(lnFall))+" Tablas no pudieron reindexarse",0,"Reindexado")
ENDPROC
*****************************
PROCEDURE WaitIndex(lNotWait)
*****************************
DELETE TAG ALL
IF !lNotWait
WAIT "Generando índices de "+Alias()+" "+ltrim(str(Reccount()))+"regs..." WINDOW AT 25,50 NOWAIT
ENDIF
ENDPROC