'mical DEFINT A-Z DECLARE SUB visu (m, p) DECLARE SUB lire (n) DECLARE SUB Efface () DECLARE SUB MicroCalculet () DECLARE FUNCTION ValeurAffichee& () DECLARE SUB AfficheNombre (Nombre$) DECLARE SUB Afficheresultat (result AS LONG) DIM aff$(3), symbol$(12), ChiffreAffiche(0 TO 8) DIM A AS LONG CONST ligneInit = 10, colinit = 30 CONST vrai = -1, faux = 0 CONST blanc = 11, Moins = 10, Erreur = 12 CONST Oper = 1, Nombre = 2 '0 1 2 3 4 5 6 7 8 aff$(1) = "ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿" aff$(2) = "³ ³ ³ ³ ³ ³ ³ ³ ³ ³" aff$(3) = "ÀÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÙ" CLS GOSUB init 'visu 0, 0 'visu 1, 1 'visu 2, 2 'visu 3, 3 'visu 4, 4 'visu 5, 5 'visu 6, 6 'visu 7, 7 'x$ = INPUT$(1) Efface MicroCalculet END DO lire n PRINT n LOOP '------------------------------------------------------------------------ init: 'lire les symboles FOR i = 0 TO 12 READ symbol$(i) NEXT i 'afficher la 'visu' LOCATE ligneInit - 1, colinit PRINT "0 1 2 3 4 5 6 7 8" FOR i = 1 TO 3 LOCATE ligneInit + i - 1, colinit - 1 PRINT aff$(i) NEXT i visu 0, 8 RETURN '------------------------------------------------------------------- DATA "0" DATA "1" DATA "2" DATA "3" DATA "4" DATA "5" DATA "6" DATA "7" DATA "8" DATA "9" DATA "-" : '10 DATA " " : '11 DATA "E" : '12 ' ' ' ' ' ' SUB AfficheNombre (Nombre$) posit = 8 IF (LEN(Nombre$) > 8) THEN visu Erreur, 0 ELSE FOR i = LEN(Nombre$) TO 1 STEP -1 n = VAL(MID$(Nombre$, i, 1)) visu n, posit posit = posit - 1 NEXT i IF (VAL(Nombre$) < 0) THEN visu Moins, 0 END IF END IF END SUB ' ' ' ' ' ' SUB Afficheresultat (result AS LONG) SHARED A AS LONG r$ = LTRIM$(STR$(result)) IF (LEN(r$) > 8) THEN Efface visu 0, Erreur ELSE FOR i = 1 TO 8 n = VAL(MID$(r$, i, 1)) visu n, 9 - i NEXT i IF (result < 0) THEN visu 0, Moins END IF END IF END SUB ' ' ' ' ' ' SUB Efface SHARED ChiffreAffiche() SHARED position FOR posit = 0 TO 7 visu blanc, posit ChiffreAffiche(i) = 0 NEXT posit visu 0, 8 ChiffreAffiche(8) = 0 position = 8 END SUB ' ' ' ' ' ' ' SUB lire (n) Touche$ = "" WHILE Touche$ = "" Touche$ = INKEY$ WEND n = ASC(LEFT$(Touche$, 1)) SELECT CASE (LEFT$(Touche$, 1)) CASE "0" TO "9" n = ASC(LEFT$(Touche$, 1)) - ASC("0") CASE "+" n = 10 CASE "-" n = 11 CASE "*" n = 12 CASE "/" n = 13 CASE "=" n = 14 CASE "d", "D" n = 15 CASE "c", "C" n = 16 CASE "s", "S" n = 17 CASE ELSE n = -1 END SELECT END SUB ' ' ' ' ' ' SUB MicroCalculet SHARED ChiffreAffiche() SHARED position SHARED A AS LONG DIM Pileop(3), Pileoper(5) AS LONG DIM nombreAffiche AS LONG NombreAffic$ = "" A = 0 Efface termine = faux position = 8 ToucheOperateur = faux Avantdernierop = 10'+ DerniereTouche = Nombre DO lire n SELECT CASE n CASE 0 TO 9 IF (ToucheOperateur) THEN Efface position = 8 NombreAffic$ = "" ToucheOperateur = faux END IF DerniereTouche = Touche Touche = Nombre IF (position > 0) THEN IF NOT ((position = 8) AND (n = 0)) THEN NombreAffic$ = NombreAffic$ + LTRIM$(STR$(n)) ChiffreAffiche(position) = n visu n, position position = position - 1 AfficheNombre NombreAffic$ END IF ELSE BEEP END IF CASE 10 TO 14 'operateurs DerniereTouche = Touche Touche = Oper ToucheOperateur = vrai Operateur = n IF (DerniereTouche <> Oper) THEN F = VAL(NombreAffic$) GOSUB calcule Efface AfficheNombre LTRIM$(STR$(A)) IF (n = 14) THEN Avantdernierop = 0 END IF Avantdernierop = Operateur CASE 15 'clear CASE 16 'C 'Clear All DerniereTouche = Touche Touche = Oper Efface A = 0 position = 8 NombreAffic$ = "" CASE 17 termine = vrai CASE ELSE END SELECT LOOP UNTIL termine EXIT SUB calcule: SELECT CASE Avantdernierop CASE 10 '+ A = A + F CASE 11 '- A = A - F CASE 12 '* A = A * F CASE 13 '/ IF (F <> 0) THEN A = A \ F ELSE A = 999999999 END IF CASE 14 '= A = F NombreAffic$ = "" CASE ELSE END SELECT RETURN VoirCalculs: END SUB ' ' ' ' ' ' FUNCTION ValeurAffichee& SHARED ChiffreAffiche() DIM va AS LONG va = 0 FOR i = 8 TO 1 STEP -1 va = va + ChiffreAffiche(i) * 10 ^ (8 - i) NEXT i ValeurAffichee& = va END FUNCTION ' ' ' ' ' ' SUB visu (m, posit) SHARED symbol$() LOCATE ligneInit + 1, colinit + 2 * posit PRINT symbol$(m) END SUB