      SUBROUTINE PLH.BLD.CHECKBOX.TABLE(OPT,NAME,TBL.OPTIONS,N.COLS,COL.WIDTHS,CELL.CONTENTS,CELL.OPTIONS,INITIAL.VALS,RES)
*PIC-LAN
*
*ALL
*PC
*Y
*
*
*
      RES = ''
*
      T = ' ' : OCONV(OPT,'MCU') : ' '
*
      V.FLG  = ( INDEX(T,' V ' ,1) <> 0 )
      VT.FLG = ( INDEX(T,' VT ',1) <> 0 )
      VB.FLG = ( INDEX(T,' VB ',1) <> 0 )
      Q.FLG  = ( INDEX(T,' Q ' ,1) <> 0 )
*
      IF Q.FLG THEN
         Q.OPT = 'Q'
      END ELSE
         Q.OPT = ''
      END
*
      IF V.FLG THEN
         TBL.CMD = 'V'
      END ELSE
         TBL.CMD = ''
      END
*
      CALL PLH.TO.ATTRS(COL.WIDTHS   ,C.WID )
      CALL PLH.TO.ATTRS(CELL.CONTENTS,C.DATA)
      CALL PLH.TO.ATTRS(CELL.OPTIONS ,C.OPTS)
      CALL PLH.TO.ATTRS(INITIAL.VALS ,I.VALS)
*
      N.CELLS = DCOUNT(C.DATA,AM)
      FOR I = 1 TO N.CELLS
         LOCATE(I,I.VALS;DUMMY) THEN
            V = 1
         END ELSE
            V = 0
         END
         CALL PLH.BLD.CHECKBOX(Q.OPT,NAME:I,C.DATA<I>,V,R)
         C.DATA<I> = R
      NEXT I
*
      BEGIN CASE
         CASE V.FLG
            CALL PLH.BLD.TABLE('V',TBL.OPTIONS,N.COLS,C.WID,C.DATA,C.OPTS,RES)
         CASE VT.FLG
            GOSUB 100
            RB = ''
            FOR COL = 1 TO N.COLS
               T.DATA = PL_REPL(RR<COL>     ,VM,AM)
               T.OPTS = PL_REPL(RR.OPTS<COL>,VM,AM)
               CALL PLH.BLD.TABLE('',TBL.OPTIONS,C.WID<COL>,T.DATA,T.OPTS,T.RES)
               RB<COL> = T.RES
            NEXT COL
            CALL PLH.BLD.TABLE('','','',RB,'',RES)
         CASE VB.FLG
            GOSUB 100
            RB = ''
            RB.OPTS = ''
            FOR COL = 1 TO N.COLS
               FOR ROW = 1 TO N.ROWS
                  R = RR<COL,ROW>
                  IF ROW < N.ROWS THEN
                     RB<COL> = RB<COL> : R : '<br>' : CR : LF
                  END ELSE
                     RB<COL> = RB<COL> : R
                  END
                  IF ROW = 1 THEN
                     RB.OPTS<COL> = RR.OPTS<COL,ROW>
                  END
               NEXT ROW
            NEXT COL
            CALL PLH.BLD.TABLE('',TBL.OPTIONS,N.COLS,C.WID,RB,RB.OPTS,RES)
         CASE YES
            CALL PLH.BLD.TABLE('',TBL.OPTIONS,N.COLS,C.WID,C.DATA,C.OPTS,RES)
      END CASE
      CALL PLH.BLD.TABLE(TBL.CMD,TBL.OPTIONS,N.COLS,C.WID,C.DATA,C.OPTS,RES)
*
      RETURN
*
100   REM Convert C.DATA into RR by rows
*
      N.ROWS = INT( ( N.CELLS + N.COLS - 1 ) / N.COLS )
      RR = ''
      RR.OPTS = ''
      FOR ROW = 1 TO N.ROWS
         FOR COL = 1 TO N.COLS
            CELL = COL + ( ROW - 1 ) * N.COLS
            RR<COL,ROW> = C.DATA<CELL>
            RR.OPTS<COL,ROW> = C.OPTS<CELL>
         NEXT COL
      NEXT ROW
*
      RETURN
   END
