* ADDGRADE.CMD

set confirm on
set colon off
SET DELETED OFF
SET TALK OFF
SET BELL OFF
STORE T TO MYES1
GOTO BOTTOM
STORE # TO MLASTNAME
GOTO TOP
DO WHILE MYES1
    DO PICGRADE
    ERASE
    @ 0,0 SAY MFIELD + " " + MNU
    STORE 0 TO MX
    STORE 2 TO MY
    STORE 1 TO MZ
    STORE 1 TO MSC
    STORE 4 TO MCO
    STORE 6 TO MSN
    STORE 30 TO MGP
       * MCO = COLON POSITION
       * MGN = GRADE POSITION, MSN = STUDENT NAME POSITION
       * MX = COLUMN, MY = ROW, MZ = COUNT ROWS, MSC = STUDENT #
    STORE "                         " TO MNAME
    GOTO TOP
    DO WHILE .NOT. EOF
        IF MZ = 21
            STORE 2 TO MY
            STORE 40 TO MX
            STORE 43 TO MCO
            STORE 45 TO MSN
            STORE 69 TO MGP
        ENDIF
        @ MY,MX SAY STR(#,2)
        @ MY,MCO SAY ":"
        @ MY,MSN SAY NAME
        IF &MFIELD&MNU = 999.00
           @ MY,MGP SAY " -- "
        ELSE
           @ MY,MGP SAY &MFIELD&MNU
        ENDIF
        STORE MSC + 1 TO MSC
        STORE MY + 1 TO MY
        STORE MZ + 1 TO MZ
        SKIP
    ENDDO
    STORE T TO MYES2
    DO WHILE MYES2
        @ 23,0 SAY "                                                    "
        STORE "   " TO MSNUM
        @ 22,0 SAY "  Type 0 to quit or STUDENT # to Change a grade ---->  ";
            GET MSNUM
        READ
        IF VAL(MSNUM) = 0
            STORE F TO MYES2
        ELSE
          IF VAL(MSNUM) > MLASTNAME
              RELEASE MSNUM
              LOOP
          ENDIF
          GOTO VAL(MSNUM)
          STORE "      " TO MGRADE
          @ 22,0 SAY "                                                       "
          @ 22,0 SAY "  Write in the Correct Grade for STUDENT Number ---->"
            IF VAL(MSNUM) < 21
               @ 1 + VAL(MSNUM),29 SAY "> " GET MGRADE
            ELSE
               @ 1 + VAL(MSNUM) - 20,68 SAY "> " GET MGRADE
            ENDIF
          READ
          REPLACE &MFIELD&MNU WITH VAL(MGRADE)
          RELEASE MGRADE

          IF VAL(MSNUM) < 21
              @ 1 + VAL(MSNUM),28 SAY "          "
              @ 1 + VAL(MSNUM),30 SAY &MFIELD&MNU
          ELSE
              @ 1 + VAL(MSNUM) - 20,67 SAY "          "
              @ 1 + VAL(MSNUM) - 20,69 SAY &MFIELD&MNU
          ENDIF
        ENDIF
        @ 23,30 SAY "                                     "
    ENDDO

    STORE T TO MRECALC
    STORE " " TO MCHOICE
    DO WHILE MRECALC
        @ 23,10 SAY "RECALCULATE ALL GRADES? <Y/N> " GET MCHOICE PICT "!"
        READ
        IF MCHOICE = "N"
            STORE F TO MRECALC
        ELSE
            IF MCHOICE = "Y"
               GOTO TOP
               ERASE
               DO WHILE .NOT. EOF
                   @ 12,0 SAY " "
                   ? "UPDATING STUDENT RECORD"
                   ? #
                   ?? "   " + NAME
                   ?? "                              "
                   DO CALTOTAL
                   STORE 0.00 TO MTOTAL
                   STORE MTOT/MAVG TO MTOTAL
                   REPLACE TOTAL WITH MTOTAL
                   DO GETGRADE
                   REPLACE GRADE WITH MGRADE
                   SKIP
                ENDDO
                STORE F TO MRECALC
            ELSE
               LOOP
            ENDIF
        ENDIF
    ENDDO

    @ 23,20 SAY"                                                "
    @ 22, 0 SAY " "
    INPUT "              ADD ANOTHER GRADE? "  TO MYES1
ENDDO
SET BELL ON
SET DELETED ON
set confirm off
set colon on
RETURN

NDDO
SET BELL ON
SET DELETED ON
set confirm off
set colon on
RETURN

              LOOP
            ENDIF
        ENDIF
    ENDDO

    @ 23,20 SAY"                                                "
    @ 22, 0 SAY " "
    INPUT "              ADD ANOTHER GRADE? "  TO MYES1
ENDDO
SET BELL ON
SET DELETED ON
set confirm off
set colon on
RETURN

LACE TOTAL WITH MTOTAL
               DO GETGRADE
               REPLACE GRADE WITH MGRADE
               SKIP
         