DeleteBegin:

' ********************************************
' *                 PAR Real                 *
' *   Copyright (C) 1986, PAR Software, Inc. *
' *            All Rights Reserved           *
' ********************************************

1000 REM This is the Beginning
' file = RF/KBR
ON ERROR GOTO ErrorFix
BREAK ON
ON BREAK GOSUB ReturnUser
DIM SHARED Lin(30),Strt(30),MaxLength(30),Fieldlength(30),Use$(6)
DIM SHARED UseIndex(30),Saved$(30),Saved#(30),Prompt$(30),BGColor(30)
DIM SHARED SavedBack#(30),Default#(13),Expenses#(13)
DIM SHARED FileList$(25),KBR$(16)
DIM SHARED how%(8)
DIM SHARED AnswerArray#(30)
GOSUB Menus12On
GOSUB KBRMenuOn
MENU ON
ON MENU GOSUB MenuCheck 
Extension$ = ".KEY"
DirNames$ = "RF/KBR.Index"
KBRFlag = 0
IF File$ = "" THEN
WindowName$ = "Key Business Ratios"
ELSE
WindowName$ = "Key Business Ratios: " + left$(File$,len(File$)-4)
END IF
 
Start:
GOSUB ColorOff
WINDOW 1,WindowName$,(0,1) - (588,186),22
CursorColor = 3
Use$(1) = " &"
Use$(2) = " ##.##%"
Use$(3) = " $$#########,.##"
Use$(4) = " ####"
Use$(5) = " $$##########,.##"
Use$(6) = " $$#############,.##"

Initialize:
FOR lcv = 0 TO 8: READ how%(lcv): NEXT lcv
DATA 110,0,175,0,22200,64,10,1,0
Speech1$="The result is to large to output"
Cur$ = " "
FOR lcv = 1 TO 24
READ Lin(lcv) :READ Strt(lcv) :READ Fieldlength(lcv)
READ MaxLength(lcv) :READ Prompt$(lcv)
READ UseIndex(lcv)
READ BGColor(lcv)
NEXT lcv
GOSUB PrintScreenOne
GOSUB ColorOn
IF File$ <> "" THEN GOSUB LoadRoutine
IF File$ <> "" THEN GOSUB PrintValues

InCheck:
a$ = "":MoveCursorFlag = 0 : EnterFlag = 0:SaveAsFlag = 0
WHILE a$ = ""
IF TIMER - NewTime >= .3 THEN CALL FlashCursor
a$ = INKEY$
KBRFlag = 1
WEND
CALL GetRoutine (Word$)

Main:  
Value# = VAL(Word$)
BackUp$ = Saved$(Index)
IF EnterFlag = 1 THEN 
IF Value# >= 100000000 THEN
Word$ = Backup$
phrase$ = "the val you enterd must be less than one hundrid mill yun"
Speech2$ = "Please try again"
CALL InputError
GOTO Main
END IF
Saved$(Index) = Word$:Saved#(Index) = Value#
IF (Index/2) = INT(Index/2) THEN
IF Saved#(Index) = 0 THEN Answer2# = 0: GOTO Out
Answer2# = Saved#(Index - 1) / Saved#(Index)
ELSE
IF Saved#(Index + 1) = 0 THEN Answer2# = 0:GOTO Out
Answer2# = Saved#(Index) / Saved#(Index + 1)
END IF
Out:
IF BGColor(Index) = 1 THEN COLOR 2,3 ELSE COLOR 2,1
LOCATE Lin(Index),39
PRINT USING "#########.###"; Answer2# ;
AnswerArray#(Index) = Answer2#
END IF     
IF MoveCursorFlag <> 0  THEN
CursorColor = BGColor(Index)
LOCATE Lin(Index),Strt(Index)
COLOR 2,BGColor(Index)
PRINT SPACE$(Fieldlength(Index));
LOCATE Lin(Index),Strt(Index)
IF UseIndex(Index) = 1 THEN PRINT USING Use$(UseIndex(Index));Saved$(Index);
IF UseIndex(Index) <> 1 AND Saved#(Index) <> 0 THEN PRINT USING Use$(UseIndex(Index));Saved#(Index);
IF Index <> LastLine AND MoveCursorFlag = 1 THEN Index = Index + IndexIncrement
IF Index <> 1 AND MoveCursorFlag = -1 THEN Index = Index - IndexIncrement
Idx = 0
IF Index > LastLine THEN Index = LastLine
NewTime = TIMER - 1
SavedBack#(Index) = VAL(Saved$(Index))
END IF   
GOTO InCheck

SUB GetRoutine (Var$) STATIC
SHARED a$, Idx, Index, MoveCursorFlag,IndexIncrement,LeftLines,EnterFlag
IndexIncrement = 1
COLOR 2,1
IF (ASC(a$)>31 AND ASC(a$)<=122) THEN AlphaNum
IF ASC(a$) = 28 THEN CursorUp
IF ASC(a$) = 29 THEN CursorDown
IF ASC(a$) = 30 THEN CursorRight
IF ASC(a$) = 31 THEN CursorLeft
IF ASC(a$) = 13 THEN Enter
IF ASC(a$) = 8 OR ASC(a$) = 127 THEN BackSpace
GOTO EndGetRoutine
                                         
AlphaNum:
' IF UseIndex(Index) <> 1 AND ASC(a$) = 32 THEN GOTO EndGetRoutine
IF Idx = MaxLength(Index) THEN EndGetRoutine
COLOR 2,BGColor(Index)
IF LEN(TempVar$) = 0 THEN
LOCATE Lin(Index), Strt(Index)
PRINT SPACE$(Fieldlength(Index));
END IF
TempVar$ = TempVar$ + a$
LOCATE Lin(Index),Strt(Index):PRINT TempVar$;
Idx = Idx + 1
GOTO EndGetRoutine  

CursorDown:
MoveCursorFlag = 1
TempVar$ = ""
Var$ = Saved$(Index)
IndexIncrement = 2
GOTO EndGetRoutine

CursorUp:                           
IF Index <> 1 AND Index <> 2 THEN
MoveCursorFlag = -1
TempVar$ = ""
END IF
Var$ = Saved$(Index)
IndexIncrement = 2
GOTO EndGetRoutine

CursorLeft:
if Index <> 1 then
MoveCursorFlag = -1
TempVar$ = ""
end if
Var$ = Saved$(Index)
GOTO EndGetRoutine

CursorRight:
MoveCursorFlag = 1
TempVar$ = ""
Var$ = Saved$(Index)
GOTO EndGetRoutine

Enter:
IF LEN(TempVar$) <> 0 THEN
Var$ = TempVar$
TempVar$ = ""
Idx = 0
EnterFlag = 1
ELSE
Var$ = Saved$(Index)
END IF
MoveCursorFlag = 1
GOTO EndGetRoutine   

BackSpace:
IF Idx <> 0 THEN
TempVar$ = LEFT$(TempVar$,LEN(TempVar$)-1)
COLOR ,BGColor(Index)
LOCATE Lin(Index),Strt(Index)+Idx:PRINT " "; CHR$(8);
Idx = Idx - 1
' LOCATE Lin(Index),Strt(Index):PRINT TempVar$;
END IF
GOTO EndGetRoutine

EndGetRoutine:
END SUB

SUB FlashCursor STATIC 
SHARED Index,CursorColor,Cur$,NewTime,Idx
IF CursorColor = 2 THEN CursorColor = BGColor(Index) ELSE CursorColor = 2
LOCATE Lin(Index),Strt(Index)+Idx
COLOR ,CursorColor
PRINT Cur$;
NewTime = TIMER
END SUB   

HelpScreen:
wind% = 6
WINDOW wind%,"HELP",(20,17) - (542,186),22
COLOR 1,0
PRINT
PRINT
PRINT
COLOR 2,3
LINE (0,23)-(519,23),3
PRINT "Current Assets / Current Liabilities = Current Ratio             "
PRINT "Cash + Rents Receiv / Accnts Pay + Acru Sal & Taxes = Quick Ratio"
PRINT "Total Liabilities / Net Worth = Debt to Worth                    "
PRINT
PRINT
PRINT
LINE (0,71)-(519,71),3
PRINT "Gross Profit / Gross Income = Gross Profit Margin                "
PRINT "Net Income Before Taxes / Gross Income = Net Profit Margin       "
PRINT "Net Operating Expense / Gross Income = Operating Expense Ratio   "
PRINT
PRINT
PRINT
LINE (0,119)-(519,119),3
PRINT "Gross Income / Total Assets = Sales To Assets                    "
PRINT "Net Income Before Taxes / Total Assets = Return On Assets        "
PRINT "Net Income Before Taxes / Net Worth  = Return On Net Worth       "
PRINT "Cost of Goods Sold / Property Inventory = Inventory Turnover     "
PRINT "Cost of Goods Sold / Accounts Payable = Accounts Payable Turnover"
PRINT "Gross Income / Rents Receivable = Accounts Receivable Turnover   ";
ExitL = 110:ExitT = 4:ExitR = 163:ExitB = 18
ExitLoc = 120
PrtL=180:PrtT=4:PrtR=239:PrtB=18
PrtLoc=190
GOSUB PrintOrExit
RETURN

PrintHelp:
FOR lcv = 1 TO 11
PRINT #3, ""
NEXT lcv
PRINT #3, "               KEY BUSINESS RATIOS"
PRINT #3, ""
PRINT #3, ""
PRINT #3, "          Solvency and Liquidity Ratios "
PRINT #3, "         -------------------------------"
PRINT #3, "Current Assets / Current Liabilities = Current Ratio             "
PRINT #3, "Cash + Rents Receiv / Accnts Pay + Acru Sal & Taxes = Quick Ratio"
PRINT #3, "Total Liabilities / Net Worth = Debt to Worth                    "
PRINT #3, ""
PRINT #3, ""
PRINT #3, "              Profitability  Ratios    "
PRINT #3, "             -----------------------"
PRINT #3, "Gross Profit / Gross Income = Gross Profit Margin                "
PRINT #3, "Net Income Before Taxes / Gross Income = Net Profit Margin       "
PRINT #3, "Net Operating Expense / Gross Income = Operating Expense Ratio   "
PRINT #3, ""
PRINT #3, ""
PRINT #3, "             Asset Management Ratios    "
PRINT #3, "            -------------------------"
PRINT #3, "Gross Income / Total Assets = Sales To Assets                    "
PRINT #3, "Net Income Before Taxes / Total Assets = Return On Assets        "
PRINT #3, "Net Income Before Taxes / Net Worth  = Return On Net Worth       "
PRINT #3, "Cost of Goods Sold / Property Inventory = Inventory Turnover     "
PRINT #3, "Cost of Goods Sold / Accounts Payable = Accounts Payable Turnover"
PRINT #3, "Gross Income / Rents Receivable = Accounts Receivable Turnover   ";
PRINT #3, CHR$(12)
GOTO 100

PrintScreenOne:     
color 1,0
locate 1,10:PRINT "   From BalanceSheet: "
locate 2,10:PRINT "and Income Statement: "
locate 6,2:PRINT "1."
locate 7,2:PRINT "2."
locate 8,2:PRINT "3."
locate 12,2:PRINT "4."
locate 13,2:PRINT "5."
locate 14,2:PRINT "6."
locate 18,2:PRINT "7."
locate 19,2:PRINT "8."
locate 20,2:PRINT "9."
locate 21,1:PRINT "10."
locate 22,1:PRINT "11."
locate 23,1:PRINT "12.";
color 1,2
locate 4,10:PRINT  " Solvency and Liquidity Ratios "
locate 10,10:PRINT "     Profitability  Ratios     "
locate 16,10:PRINT "    Asset Management Ratios    "
for Loop3 = 1 to 24
locate Lin(Loop3),39
if BGColor(Loop3) = 1 then color 1,3 else color 1,1
PRINT "             ";
next Loop3
color 1,0
locate  6,52:PRINT "         CA / CL = CR"
locate  7,52:PRINT " C+RR / AP+AS+AT = QR"
locate  8,52:PRINT "         TL / NW = DW"
locate 12,52:PRINT "        GP / GI = GPM"
locate 13,52:PRINT "      NIBT / GI = NPM"
locate 14,52:PRINT "       NOE / GI = OER"
locate 18,52:PRINT "        GI / TA = STA"
locate 19,52:PRINT "      NIBT / TA = ROA"
locate 20,52:PRINT "     NIBT / NW = RONW"
locate 21,52:PRINT "         CS / PI = IT"
locate 22,52:PRINT "        CS / AP = APT"
locate 23,52:PRINT "        GI / RR = ART";

TempStart:    
FOR lcv = 1 TO 24
COLOR 1,0
LOCATE Lin(lcv),Strt(lcv)-LEN(Prompt$(lcv)): PRINT Prompt$(lcv);
COLOR 1,BGColor(lcv)
PRINT SPACE$(Fieldlength(lcv));
NEXT lcv
COLOR 1,2
Index = 1 : LastLine = 24:LeftLines = 10
RETURN

SaveRoutine:
TrySave = 1
IF File$ = "" THEN  SaveAs
OPEN File$ FOR OUTPUT AS #4
PRINT #4, "***** AUTOMATICALLY CREATED FILE - DO NOT EDIT !!!!! *****"
PRINT #4, BSKBR$
PRINT #4, ISKBR$
FOR lcv = 1 TO 24
PRINT #4,Saved$(lcv)
NEXT lcv
CLOSE #4
TrySave = 0
2500 GOTO EndMenuCheck
  
LoadRoutine:
TryLoad = 1
OPEN File$ FOR INPUT AS #4
INPUT #4, dummy$
LINE INPUT #4, BSKBR$
LINE INPUT #4, ISKBR$
FOR lcv = 1 TO 24
INPUT #4,Saved$(lcv)
Saved#(lcv) = val(Saved$(lcv))
NEXT lcv
CLOSE #4
TryLoad = 0
3000 RETURN

LoadBalanceSheet:
IF KBRFile$ = "" THEN EndMenuCheck
BSKBR$ = left$(KBRFile$,len(KBRFile$)-4)
LoadinKBR = 1
OPEN KBRFile$+".KBR" FOR INPUT AS #5
INPUT #5, dummy$
LINE INPUT #5, KBR$(1)
INPUT #5, KBR$(2)
INPUT #5, KBR$(3)
INPUT #5, KBR$(4)
INPUT #5, KBR$(5)
INPUT #5, KBR$(6)
INPUT #5, KBR$(7)
INPUT #5, AccrSal$
INPUT #5, AccrTax$
INPUT #5, KBR$(8)
INPUT #5, KBR$(9)
INPUT #5, KBR$(10)
CLOSE #5
GOSUB SetBalanceSheetValues
GOSUB PrintValues
KBRFlag = 1
LoadinKBR = 0
3500 GOTO EndMenuCheck

LoadIncomeStatement:
if KBRFile$ = "" then EndMenuCheck
ISKBR$ = left$(KBRFile$,len(KBRFile$)-4)
LoadinKBR = 1
OPEN KBRFile$+".KBR" FOR INPUT AS #5
INPUT #5, dummy$
LINE INPUT #5, KBR$(11)
INPUT #5, KBR$(12)
INPUT #5, KBR$(13)
INPUT #5, KBR$(14)
INPUT #5, KBR$(15)
INPUT #5, KBR$(16)
CLOSE #5
GOSUB SetIncomeStatementValues
GOSUB PrintValues
KBRFlag = 1
LoadinKBR = 0
GOTO EndMenuCheck

SetBalanceSheetValues:
Period$ = KBR$(1)
Cash$ = KBR$(2)
AcctsReceivable$ = KBR$(3):Saved$(24) = KBR$(3)
Saved$(20) = KBR$(4)
Saved$(1) = KBR$(5)
Saved$(14) = KBR$(6):Saved$(16) = KBR$(6)
Saved$(4) = STR$(VAL(KBR$(7)) + VAL(AccrSal$) + VAL(AccrTax$))
Saved$(22) = KBR$(7)
Saved$(2) = KBR$(8)
Saved$(5) = KBR$(9)
Saved$(6) = KBR$(10): Saved$(18) = KBR$(10)
Saved$(3) = STR$(VAL(Cash$) + VAL(AcctsReceivable$))
FOR loop4 = 1 TO 24: Saved#(loop4) = VAL(Saved$(loop4)) : NEXT loop4
Return

SetIncomeStatementValues:
Period2$ = KBR$(11)
Saved$(8) = KBR$(12):Saved$(10) = KBR$(12):Saved$(12) = KBR$(12):Saved$(13) = KBR$(12):Saved$(23) = KBR$(12)
Saved$(19) = KBR$(13):Saved$(21) = KBR$(13)
Saved$(7) = KBR$(14)
Saved$(11) = KBR$(15)
Saved$(9) = KBR$(16): Saved$(15) = KBR$(16): Saved$(17) = KBR$(16)
FOR loop5 = 7 TO 24: Saved#(loop5) = val(Saved$(loop5)) : NEXT loop5
RETURN

PrintValues:
COLOR 1,0
LOCATE 1,33:PRINT "                                     "
LOCATE 1,33:PRINT BSKBR$
LOCATE 2,33:PRINT "                                     "
LOCATE 2,33:PRINT ISKBR$
FOR lcv = 1 to 24
LOCATE Lin(lcv),Strt(lcv)
COLOR 2,BGColor(lcv)
IF LEN(Saved$(lcv)) <> 0 THEN
IF UseIndex(lcv) = 1 THEN
PRINT USING Use$(UseIndex(lcv));Saved$(lcv);
ELSE
PRINT USING Use$(UseIndex(lcv));Saved#(lcv);
END IF
END IF
IF (lcv/2) = INT(lcv/2) THEN
IF Saved#(lcv) = 0 THEN Answer2# = 0: GOTO OutTwo
Answer2# = Saved#(lcv - 1) / Saved#(lcv)
ELSE
IF Saved#(lcv + 1) = 0 THEN Answer2# = 0:GOTO OutTwo
Answer2# = Saved#(lcv) / Saved#(lcv + 1)
END IF
OutTwo:
IF BGColor(lcv) = 1 THEN COLOR 2,3 ELSE COLOR 2,1
LOCATE Lin(lcv),39
PRINT USING "#########.###"; Answer2# ;
AnswerArray#(lcv) = Answer2#
NEXT lcv
COLOR 2,3
RETURN

PrinterOutput:
GOTO PrinterRequester

PrintRoutine:
FOR lcv = 1 TO 11
PRINT #3, ""
NEXT lcv
PRINT #3,"                              KEY BUSINESS RATIOS"
PRINT #3,"":PRINT #3,""
PRINT #3, "             From BalanceSheet: ";BSKBR$
PRINT #3, "          and Income Statement: ";ISKBR$
PRINT #3,""
PRINT #3,""
PRINT #3, "                        Solvency and Liquidity Ratios "
PRINT #3, "                       -------------------------------"
PRINT #3, using " 1. $$#########,.## / $$#########,.## = #########.###          CA / CL = CR"; Saved#(1);Saved#(2);AnswerArray#(2)
PRINT #3, using " 2. $$#########,.## / $$#########,.## = #########.###  C+RR / AP+AS+AT = QR"; Saved#(3);Saved#(4);AnswerArray#(4)
PRINT #3, using " 3. $$#########,.## / $$#########,.## = #########.###          TL / NW = DW"; Saved#(5);Saved#(6);AnswerArray#(6)
PRINT #3, ""
PRINT #3, "                            Profitability  Ratios "
PRINT #3, "                           -----------------------"
PRINT #3, using " 4. $$#########,.## / $$#########,.## = #########.###         GP / GI = GPM"; Saved#(7);Saved#(8);AnswerArray#(8)
PRINT #3, using " 5. $$#########,.## / $$#########,.## = #########.###       NIBT / GI = NPM"; Saved#(9);Saved#(10);AnswerArray#(10)
PRINT #3, using " 6. $$#########,.## / $$#########,.## = #########.###        NOE / GI = OER"; Saved#(11);Saved#(12);AnswerArray#(12)
PRINT #3,""
PRINT #3, "                           Asset Management Ratios "
PRINT #3, "                          -------------------------"
PRINT #3, using " 7. $$#########,.## / $$#########,.## = #########.###         GI / TA = STA"; Saved#(13);Saved#(14);AnswerArray#(14)
PRINT #3, using " 8. $$#########,.## / $$#########,.## = #########.###       NIBT / TA = ROA"; Saved#(15);Saved#(16);AnswerArray#(16)
PRINT #3, using " 9. $$#########,.## / $$#########,.## = #########.###      NIBT / NW = RONW";Saved#(17);Saved#(18);AnswerArray#(18)
PRINT #3, using "10. $$#########,.## / $$#########,.## = #########.###          CS / PI = IT";  Saved#(19);Saved#(20);AnswerArray#(20)
PRINT #3, using "11. $$#########,.## / $$#########,.## = #########.###         CS / AP = APT"; Saved#(21);Saved#(22);AnswerArray#(22)
PRINT #3, using "12. $$#########,.## / $$#########,.## = #########.###         GI / RR = ART"; Saved#(23);Saved#(24);AnswerArray#(24)
PRINT #3,CHR$(12)
GOTO 100

     DATA 6,4,16,11,"",3,1
     DATA 6,21,16,11,"/",3,1

     DATA 7,4,16,11,"",3,3
     DATA 7,21,16,11,"/",3,3

     DATA 8,4,16,11,"",3,1
     DATA 8,21,16,11,"/",3,1

     DATA 12,4,16,11,"",3,1
     DATA 12,21,16,11,"/",3,1

     DATA 13,4,16,11,"",3,3
     DATA 13,21,16,11,"/",3,3

     DATA 14,4,16,11,"",3,1
     DATA 14,21,16,11,"/",3,1

     DATA 18,4,16,11,"",3,1
     DATA 18,21,16,11,"/",3,1

     DATA 19,4,16,11,"",3,3
     DATA 19,21,16,11,"/",3,3

     DATA 20,4,16,11,"",3,1
     DATA 20,21,16,11,"/",3,1

     DATA 21,4,16,11,"",3,3
     DATA 21,21,16,11,"/",3,3

     DATA 22,4,16,11,"",3,1
     DATA 22,21,16,11,"/",3,1

     DATA 23,4,16,11,"",3,3
     DATA 23,21,16,11,"/",3,3

9999 REM This is the end of the program.
DeleteEnd:
