Comment ======================================= Calc.Mnu Version 1.1 (C) Copyright 1990-91 Kevin Moore * All rights Reserved 4-5-94 Pete Hunter @ Computer Tyme added feature to turn on Numlock when CALC is loaded if Numlock is not already on. If Numlock is on it will be left on upon exiting CALC. Also enabled lower case "c" to clear calculator. ======================================= EndComment Var I Row Cnt KeysArr KeyNum Sign Number Status Operator Operand R DisplayWin SaveNumlock Qualifier Ch Index Const First = 1 Valid = 2 Error = 3 SaveNumlock = Numlock Numlock On KeysArr[1].Ch = 'c' KeysArr[1].Ch = 'C' KeysArr[1].Index = 1 KeysArr[2].Ch = Char( 27 ) KeysArr[2].Index = 2 KeysArr[3].Ch = '%' KeysArr[3].Index = 14 KeysArr[4].Ch = Char( 241 ) KeysArr[4].Index = 3 KeysArr[5].Ch = '7' KeysArr[5].Index = 11 KeysArr[6].Ch = '8' KeysArr[6].Index = 12 KeysArr[7].Ch = '9' KeysArr[7].Index = 13 KeysArr[8].Ch = '/' KeysArr[8].Index = 15 KeysArr[9].Ch = '4' KeysArr[9].Index = 8 KeysArr[10].Ch = '5' KeysArr[10].Index = 9 KeysArr[11].Ch = '6' KeysArr[11].Index = 10 KeysArr[12].Ch = '*' KeysArr[12].Index = 16 KeysArr[13].Ch = '1' KeysArr[13].Index = 5 KeysArr[14].Ch = '2' KeysArr[14].Index = 6 KeysArr[15].Ch = '3' KeysArr[15].Index = 7 KeysArr[16].Ch = '-' KeysArr[16].Index = 17 KeysArr[17].Ch = '0' KeysArr[17].Index = 4 KeysArr[18].Ch = '.' KeysArr[18].Index = 20 KeysArr[19].Ch = '=' KeysArr[19].Index = 18 KeysArr[20].Ch = '+' KeysArr[20].Index = 19 Shadow Off DoubleLineBox BoxHeaderColor( Black,Grey ) BoxHeader = ' Calculator ' BoxInsideColor( White,Grey ) BoxBorderColor( White,Grey ) DrawBox( 10,5,27,14 ) NoBoxBorder BoxInsideColor( White,Blue ) DrawBox( 12,6,23,1 ) DisplayWin = CurrentWindow BoxInsideColor( Black,Green ) Shadow Off Procedure DrawKey( N,BordFG,BordBG,TextFG,TextBG,Shad ) Var X,Y X = (((N - 1) Mod 4) * 6) + 1 If ((N Mod 4) <> 0) Y = (N / 4) + 1 Else Y = (N / 4) EndIf Y = (Y * 2) - 1 ;Offset inside the back window X = X + 11 Y = Y + 7 BoxInsideColor( BordFG,BordBG ) DrawBox( X,Y,5,2 ) If Shad TextColor( TextFG,TextBG ) Write( ' ',KeysArr[N].Ch,' ' ) Write( Char( 219 ) ) TextColor( BordBG,BordBG ) Write( ' ' ) TextColor( BordBG,BordFG ) Loop( 3 ) Write( Char( 220 ) ) EndLoop Else Write( ' ' ) TextColor( TextFG,TextBG ) Write( ' ',KeysArr[N].Ch,' ' ) EndIf EndProc Loop( 20 ) DrawKey( LoopIndex,Black,Grey,Black,Green,True ) EndLoop Procedure CheckFirst If Status = First Status = Valid Number = '0' Sign = ' ' EndIf EndProc Procedure SetDisplay( N ) Var S S = Str( N * 1.0 ) If Mid( S,1,1 ) <> '-' Sign = ' ' Else Delete( S,1,1 ) Sign = '-' EndIf If Length( S ) > 21 CalcError Else While Right( S,1 ) = '0' Delete( S,Length( S ),1 ) EndWhile If Right( S,1 ) = '.' Delete( S,Length( S ),1 ) EndIf Number = Sign + S EndIf EndProc Procedure GetDisplay Return (Value( Sign + Number ) * 1.0 ) EndProc Procedure CalcError Var CWin ClearSCreen WriteCenter( 'ERROR' ) Status = Error EndProc Procedure Display If Length( Number ) > 21 CalcError Else ClearScreen Loop( 22 - Length( Number ) ) Write( ' ' ) EndLoop Write( Number ) EndIf EndProc Procedure Clear Status = First Number = '0' Sign = ' ' Operator = '=' EndProc SetTopWindow( DisplayWin ) Clear Display Repeat I = ReadKey KeyNum = 0 If I = Esc NumLock SaveNumlock ExitMenu Endif If (Status = Error) And (I <> 'C') Then I = ' '; If I = 'c' Then KeyNum = 1 If I = 'C' Then KeyNum = 1 If I = Char( 8 ) Then KeyNum = 2 If I = '%' Then KeyNum = 3 If I = '_' Then KeyNum = 4 If I = '7' Then KeyNum = 5 If I = '8' Then KeyNum = 6 If I = '9' Then KeyNum = 7 If I = '/' Then KeyNum = 8 If I = '4' Then KeyNum = 9 If I = '5' Then KeyNum = 10 If I = '6' Then KeyNum = 11 If I = '*' Then KeyNum = 12 If I = '1' Then KeyNum = 13 If I = '2' Then KeyNum = 14 If I = '3' Then KeyNum = 15 If I = '-' Then KeyNum = 16 If I = '0' Then KeyNum = 17 If I = '.' Then KeyNum = 18 If I = '=' Then KeyNum = 19 If I = Char( 13 ) Then KeyNum = 19 If I = '+' Then KeyNum = 20 If KeyNum <> 0 ; Numerals If (KeysArr[KeyNum].Index > 3) If (KeysArr[KeyNum].Index < 14) CheckFirst If Number = '0' Then Number = '' Number = Number + I EndIf EndIf ;Period If KeyNum = 18 CheckFirst; If Pos( '.',Number ) = 0 Then Number = Number + '.' EndIf ;BackSpace If KeyNum = 2 CheckFirst If Length( Number ) = 1 Number = '0' Else Delete( Number,Length( Number ),1 ) EndIf EndIf ;Sign If KeyNum = 4 If Sign = ' ' Sign = '-' Else Sign = ' ' EndIf EndIf ;Operands If (KeysArr[KeyNum].Index > 13) If (KeysArr[KeyNum].Index < 20) If Status = Valid Status = First R = GetDisplay If I = '%' If ((Operator = '+') Or (Operator = '-')) R = Operand * R / 100 EndIf If ((Operator = '*') Or (Operator = '/')) R = R / 100 EndIf EndIf If Operator = '+' Then SetDisplay( Operand + R ) If Operator = '-' Then SetDisplay( Operand - R ) If Operator = '*' Then SetDisplay( Operand * R ) If Operator = '/' If R = 0 CalcError Else SetDisplay( Operand / R ) EndIf EndIf EndIf Operator = I Operand = GetDisplay EndIf EndIf If KeyNum = 1 Then Clear DrawKey( KeyNum,Black,Grey,Black,Green,False ) Wait( 10 ) EraseTopWindow Display EndIf Until I = Esc ; Numlock Off ClearScreenOnExit Off