      ' ----------------- PLUARG - consulta categorias ---------------------------
    ' $INCLUDE: 'EDITAL.BAS'
      DIM SHARED V1%(2000),V2%(2000),V3%(2000)
      ON ERROR GOTO ErrorHandler

      ' $INCLUDE: 'I58ARG.BAS'
      GET#58,1
      CAT$=CA58$
     ' $INCLUDE: 'OPNTEM.BAS'
     ' $INCLUDE: 'OPNPLU.BAS'
      GET#5,1
      UP  =CVS(UP5$)                                       ' ultimo plu

5600  APUNTADOR% = VARPTR(V1%(1)): CALL SAVESCRN(1, APUNTADOR%)
5602  COLOR 15,7
         LOCATE 24,2:PRINT "Creando Indice, Favor de Esperar...  "+SPACE$(41);
         LOCATE 23,2:PRINT "":IE=0:GOSUB 5614
      COLOR 15,7
         LOCATE 24,2:PRINT "Ordenando Indice, Favor de Esperar..."+SPACE$(41);
         LOCATE 23,2:PRINT "":GOSUB 5622
      COLOR 15, 7:LOCATE 24,1:PRINT SPACE$(80);:LOCATE 23,2:PRINT "" ' limpia mensaje

      PR=06:PC=64:NR=15:NC=14:GOSUB 9980       
      PR=08:PC=65:NR=12:NC=12:GOSUB 9981
      COLOR  0, 7:LOCATE 7,66:PRINT "Cat  Nombre "
      COLOR 15, 7:LOCATE 24,02:PRINT SPACE$(78);
      COLOR 15, 7:LOCATE 24,02:PRINT " ";CHR$(24);" ";CHR$(25);" PgDn PgUp=desplazarse    Enter=insertar";
      COLOR 16,15:LOCATE 24,03:PRINT CHR$(24);
                  LOCATE 24,05:PRINT CHR$(25);
                  LOCATE 24,07:PRINT "PgDn";
                  LOCATE 24,12:PRINT "PgUp";
                  LOCATE 24,32:PRINT "Enter";
                  ' LOCATE 24,50:PRINT "END";
                  ' LOCATE 24,54:PRINT "C";
      LOCATE 23,2:PRINT "":COLOR 7,0

      IF RECCNT=0 THEN IB=0:GOTO 5608
      IB=1:LIMI=1:LIMS=LIMI+11
      IF LIMS>RECCNT THEN LIMS=RECCNT
         IF RECCNT>12 THEN PW=20 ELSE PW=LIMS+8
      GOSUB 5612
5604  BAND=0
      DO
          X$=INKEY$
          SELECT CASE X$
                 CASE IS=CHR$(13)                          ' es enter
                      BAND=1
                      CATXX$=CAT23$
                      GOTO 5610
                 CASE IS=CHR$(0)+CHR$(72)                  ' arriba
                      IF PW=9 THEN IF I=1 THEN ELSE LIMI=LIMI-1:LIMS=LIMS-1 ELSE PW=PW-1
                      GOSUB 5612
                 CASE IS=CHR$(0)+CHR$(80)                  ' abajo
                      IF I=RECCNT THEN 5606
                      IF PW=20 THEN IF I=RECCNT THEN ELSE LIMI=LIMI+1:LIMS=LIMS+1 ELSE PW=PW+1
5606                  GOSUB 5612
                 CASE IS=CHR$(0)+CHR$(73)                  ' page up
                      LIMI=LIMI-12:IF LIMI<=0     THEN LIMI=1
                      LIMS=LIMI+11:IF LIMS>RECCNT THEN LIMS=RECCNT
                      PW=9
                      GOSUB 5612
                 CASE IS=CHR$(0)+CHR$(81)                  ' page down
                      LIMI=LIMI+12:IF LIMI>RECCNT THEN LIMI=RECCNT-11:IF LIMI<=0 THEN LIMI=1
                      LIMS=LIMI+11:IF LIMS>RECCNT THEN LIMS=RECCNT:LIMI=LIMS-11:IF LIMI<=0 THEN LIMI=1
                      PW=LIMS-LIMI+9
                      GOSUB 5612
                 ' CASE IS=CHR$(0)+CHR$(79)                   es end
                 '      GOTO 5610
                 ' CASE IS="C"                                es C
                 '      GOTO 5610
                 ' CASE IS="c"                                es c
                 '      GOTO 5610
                 CASE ELSE
          END SELECT
      LOOP UNTIL X$=CHR$(13) OR X$=CHR$(0)+CHR$(72) OR X$=CHR$(0)+CHR$(80) OR X$="C"
      GOTO 5604

5608  COLOR 16,15:LOCATE 24,2:PRINT SPACE$(78);
      IF IB=0 THEN COLOR 16,15:LOCATE 24,2:PRINT " No encontr˘ la categorˇa...";:LOCATE 23,2:PRINT "":BEEP:W$=INPUT$(1)
      COLOR 16,15:LOCATE 24,2:PRINT SPACE$(78);:LOCATE 23,2:PRINT ""
      BAND=0

5610  APUNTADOR% = VARPTR(V1%(1)):CALL RESTSCRN(1, APUNTADOR%)
      LSET CA58$=CATXX$
      PUT#58,1
      CLOSE:END

5612  CR=8:COLOR 15,7                                      ' reimprime cuadro
      FOR I=LIMI TO LIMS
          GET#23,I
          CR=CR+1
          LOCATE CR,66:PRINT " ";CAT23$;" ";NOM23$
      NEXT I
      I=LIMI+PW-9
      GET#23,I
      COLOR 15,1:LOCATE PW,66:PRINT " ";CAT23$;" ";NOM23$
      RETURN

5614                                                       ' CREA INDICE
      GOSUB 5630                                           ' abre archivo indice
      CLOSE#23                                             ' cierra arch indice
      KILL IND$                                            ' borra arch indice
      GOSUB 5630                                           ' abre arch indice
      IJ=0

      IE=0
      OPEN "I",33,"ASC-B"
      IF IE=1    THEN CLOSE#33:SHELL "\SIEARG2\MGPARG":RETURN
5616  IF EOF(33) THEN CLOSE#33:RETURN
         INPUT#33,X01$,X02$,X03$,X04$,X05$,X06$,X07$,X08$,X09$,X10$,X11$,X12$,X13$,X14$,X15$,X16$,X17$,X18$,X19$,X20$,X21$,X22$,X23$,X24$,X25$,X26$,X27$,X28$
         NOL$=MID$(X03$,2,24)                               ' nombre
         NOC$=MID$(X04$,2,08)                               ' corto
         XPLU$=MID$(X02$,2,5)                               ' plu
         PLU=VAL(XPLU$)                                     ' plu
         IF PLU=0 THEN 5616
         IF PLU=9 THEN 5616
         IF VAL(MID$(XPLU$,1,1))<1 OR VAL(MID$(XPLU$,1,1))>8 THEN 5616
         IF VAL(MID$(XPLU$,2,1))<1 OR VAL(MID$(XPLU$,2,1))>9 THEN 5616
         IF MID$(XPLU$,3,1)<"0" OR MID$(XPLU$,3,1)>"9" THEN
            IJ=IJ+1
            LSET CAT23$=MID$(XPLU$,1,2)
            LSET NOM23$=NOC$
            LSET CS23$ =MKI$(1)
            PUT#23,IJ
         ENDIF
         GOTO 5616

5622                                                       ' ORDENAR (SORT)
     PLC$="C:"+"024"+"ARG.ARG"                             ' indice
     CMND$="2\1\0\0\"+PLC$+"\"+PLC$+"\0\12\N\N\0\01\02\A\A\0\Y\D\11\2\I\E\0\0"
     CLOSE#23                                              ' cierra arch indice
     ' CALL SETCON(SLVN$)
     SLVN$="1"
     CALL SORTMC(CMND$,SORTERR%,RECCNT%)
     RECCNT=RECCNT%
     IF RECCNT<0 THEN RECCNT=RECCNT+65536
     IF SORTERR%=0 THEN GOSUB 5630:RETURN
     PRINT:PRINT "*** ERROR AL ORDENAR ARCHIVO INDICE ...VERFIFIQUE QUE HAYA ESPACIO SUFICIENTE";SORTERR%
     CLOSE:END

5630 IND$="C:"+"024"+"ARG.ARG"
     ' $INCLUDE: 'I24ARG.BAS'
     RETURN

6999 ' $INCLUDE: 'R40GRL.BAS'

ErrorHandler:
      IF ERR=70 THEN LOCATE 24,01:COLOR 16,15:PRINT "pd...";:LOCATE 23,2:PRINT "":RESUME
      IF ERR=24 OR ERR=25 OR ERR=27 THEN GOSUB 7510:RESUME
      COLOR 16,15:LOCATE 24,01:PRINT "Error en los datos ";ERR;" Linea ";ERL;". Llame a SIERRA.";:LOCATE 23,2:PRINT "":W$=INPUT$(1):CLOSE:END
