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

      ' $INCLUDE: 'I57ARG.BAS'
      GET#57,1
      PLU$=PLU57$
     ' $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=62:NR=15:NC=16:GOSUB 9980       
      PR=08:PC=63:NR=12:NC=14:GOSUB 9981
      COLOR  0, 7:LOCATE 7,64:PRINT " Plu   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
                      PLUXX$=PLU23$
                      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¢ el plu...";: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 PLU57$=PLUXX$
      PUT#57,1
      CLOSE:END

5612  CR=8:COLOR 15,7                                      ' reimprime cuadro
      FOR I=LIMI TO LIMS
          GET#23,I
          CR=CR+1
          LOCATE CR,64:PRINT PLU23$;" ";NOM23$
      NEXT I
      I=LIMI+PW-9
      GET#23,I
      COLOR 15,1:LOCATE PW,64:PRINT PLU23$;" ";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
      FOR I=1 TO UP
          GET#3,I
          IF ASC(F3$)=0 THEN
             IJ=IJ+1
             IF VAL(PL3$)<>0 THEN 
                LSET PLU23$=PL3$
                LSET NOM23$=NC3$
                LSET CS23$ =MKI$(1)
                PUT#23,IJ
             ENDIF
             ' LOCATE 23,2:PRINT USING "#### #### ";IJ;UP;:PRINT PL3$;" ";NOM23$:W$=INPUT$(1)
          ENDIF
      NEXT I
      RETURN

5622                                                       ' ORDENAR (SORT)
     PLC$="C:"+"026"+"ARG.ARG"                             ' indice
     CMND$="2\1\0\0\"+PLC$+"\"+PLC$+"\0\15\N\N\0\01\05\A\A\0\Y\D\14\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:"+"026"+"ARG.ARG"
     ' $INCLUDE: 'I26ARG.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
