通用菜单生成器 韩 力 1994-03-04 10 REM TF/TB=正文前/背景色,MFMB=菜单前/背景色,N=菜单条数 12 REM X/Y=菜单左上角坐标,C 菜单选中项,M$()=菜单提示内容 14 TF = 7: TB = 1: MF = 4: MB = 2: SCREEN 0: COLOR TF, TB: CLS 16 S = 1: N = 4: X = 9: Y = 30: DIM M$(N), FC(N), BC(N): M$(1) = "1. The first item" 18 M$(2) = "2. The second item": M$(3) = "3. The third item": M$(4) = "4. The fourth item" 20 FOR J = 1 TO N: IF LEN(M$(J)) > L THEN L = LEN(M$(J)) 22 NEXT J: FOR J = 1 TO N: M$(J) = M$(J) + SPACE$(L - LEN(M$(J))): NEXT J 24 COLOR MF, MB: LOCATE X, Y: PRINT CHR$(218); STRING$(L, CHR$(196)); CHR$(191) 26 FOR J = 1 TO N: COLOR MF, MB: LOCATE X + J, Y 28 PRINT CHR$(179); M$(J); CHR$(179); : COLOR 0, 0: PRINT " ": NEXT J 30 LOCATE X + N + 1, Y: COLOR MF, MB: PRINT CHR$(192); STRING$(L, CHR$(196)); CHR$(217); 32 COLOR 0, 0: PRINT " ": LOCATE X + N + 2, Y + 2: COLOR 0, 0: PRINT SPACE$(L + 2) 34 FOR J = 1 TO N: FC(J) = MF: BC(J) = MB: NEXT J: FC(S) = MB: BC(S) = MF 36 A$ = INKEY$: IF A$ = CHR$(13) GOTO 58 ELSE IF A$ = CHR$(27) THEN S = 0: GOTO 58 38 FOR J = 1 TO N: IF A$ <> CHR$(0) + CHR$(72) OR BC(J) = MB GOTO 46 40 IF J = 1 THEN SWAP FC(1), FC(N): SWAP BC(1), BC(N): S = N 42 IF J > 1 THEN SWAP FC(J), FC(J - 1): SWAP BC(J), BC(J - 1): S = J - 1 44 GOTO 56 46 IF A$ <> CHR$(0) + CHR$(80) OR BC(J) = MB GOTO 54 48 IF J = N THEN SWAP FC(1), FC(N): SWAP BC(1), BC(N): S = 1 50 IF J < N THEN SWAP FC(J), FC(J + 1): SWAP BC(J), BC(J + 1): S = J + 1 52 GOTO 56 54 NEXT J 56 FOR J = 1 TO N: LOCATE X + J, Y + 1: COLOR FC(J), BC(J): PRINT M$(J): NEXT J: GOTO 36 58 COLOR TF, TB: LOCATE X + N + 4, Y: PRINT "Item"; S; "is selected."