05-16-2004, 05:23 AM
I need help outputting the correct information using arrays. For some reason my table search isn't working. I just get "Error" to output when it's suppose to compare the input Account$ from the third file to the AccountsTable$ Account numbers in the second file and output it if it is valid and output "Error" when it is not. All records whether valid or not are to be processed the same. Also, I'm suppose to extract the CityName$ from the CityTable$ based upon the Local Number (variable name Locals in code) from the third file. Local Number is numeric and the CityTable$ is alphanumeric. I'm not sure how to get this to work either. I have included parts of the code to help see this problem more clearly. Any help would be very much appreciated.
Code:
GOSUB HOUSEKEEPING
DO UNTIL EOF$ = "Y"
GOSUB PROCESSRECORDS
LOOP
GOSUB EndOfJob
END
HOUSEKEEPING:
GOSUB OpenFiles
GOSUB InitailizeVariables
GOSUB LoadCityTable
GOSUB LoadAccountTable
GOSUB ReadFile
GOSUB PreviousLocalsSetup
GOSUB PreviousStateSetup
GOSUB PreviousFederalSetup
RETURN
PROCESSRECORDS:
GOSUB ControlBreakCheck
GOSUB AccountLookup
IF FOUNDAccount$ = "Y" THEN
PrintAccount$ = Account$
ELSE
PrintAccount$ = "Error"
END IF
GOSUB PageCheck
GOSUB DetailCalculations
GOSUB Accumulation
GOSUB WriteDetail
GOSUB ReadFile
RETURN
EndOfJob:
GOSUB FinalTotalOutput
GOSUB CloseFiles
RETURN
OpenFiles:
OPEN "A:CITY.DAT" FOR INPUT AS #1
OPEN "A:ACCOUNTS.DAT" FOR INPUT AS #2
OPEN "A:BONDS.DAT" FOR INPUT AS #3
OPEN "A:BOND1.DOC" FOR OUTPUT AS #4
RETURN
InitailizeVariables:
EOF$ = "N"
LocalsTotal = 0
StateTotal = 0
FederalTotal = 0
FinalTotal = 0
PageNumber = 1
LinesPerPage = 30
LineCount = LinesPerPage + 1
QuantitySoldTot = 0
PrincipleValueTot = 0
MaxSize = 12
DIM CityTable$(9)
DIM AccountsTable$(MaxSize)
RETURN
LoadCityTable:
INPUT #1, CityName$
FOR CityNameSubscript = 1 TO 9
CityTable$(CityNameSubscript) = CityName$
INPUT #1, CityName$
NEXT CityNameSubscript
RETURN
LoadAccountTable:
INPUT #2, AccountNum$
FOR AccountSubscript = 1 TO MaxSize
AccountsTable$(AccountSubscript) = AccountNum$
IF AccountNum$ = "ENDTABLE" THEN
SaveSubscript = AccountSubscript
Subscript = MaxSize
END IF
INPUT #2, AccountNum$
NEXT AccountSubscript
RETURN
ReadFile:
INPUT #3, Federal, State, Locals, Account$, QuantitySold, PrincipleValue
IF Account$ = "STOP" THEN EOF$ = "Y"
RETURN
PreviousLocalsSetup:
LocalsHold = Locals
RETURN
PreviousStateSetup:
StateHold = State
RETURN
PreviousFederalSetup:
FederalHold = Federal
RETURN
ControlBreakCheck:
IF FederalHold <> Federal THEN
GOSUB LocalsTotalOutPut
GOSUB StateTotalOutput
GOSUB FederalTotalOutput
LineCount = LineCount + 6
PRINT #4,
ELSE
IF StateHold <> State THEN
GOSUB LocalsTotalOutPut
GOSUB StateTotalOutput
LineCount = LineCount + 6
PRINT #4,
PRINT #4,
ELSE
IF LocalsHold <> Locals THEN
GOSUB LocalsTotalOutPut
LineCount = LineCount + 6
PRINT #4,
PRINT #4,
END IF
END IF
END IF
RETURN
AccountLookup:
FOUNDAccount$ = "N"
FOR SearchSubscript = 1 TO SaveSubscript
GOSUB AccountCheck
NEXT SearchSubscript
RETURN
AccountCheck:
IF Account$ = AccountTable$(SearchSubscript) THEN
FOUNDAccount$ = "Y"
SearchSubscript = SaveSubscript
END IF
RETURN
PageCheck:
IF LineCount > LinesPerPage THEN
PRINT #4, CHR$(12)
GOSUB Headings
END IF
RETURN
Headings:
CLS
PRINT #4, TAB(21); "Federal, State and Locals Bond Value Report"; TAB(71); "Page"; TAB(76); USING "###"; PageNumber;
PRINT #4,
PRINT #4, TAB(3); "Federal"; TAB(13); "State"; TAB(21); "Local"; TAB(31); "Account";
PRINT #4, TAB(41); "Quantity"; TAB(51); "Principle"; TAB(68); "Total"
PRINT #4, TAB(6); "ID #"; TAB(14); "ID #"; TAB(22); "ID #"; TAB(31); "Number"; TAB(43); "Sold";
PRINT #4, TAB(53); "Value"; TAB(68); "Value"
PRINT #4,
LineCount = 6
PageNumber = PageNumber + 1
RETURN
DetailCalculations:
BondAmt = QuantitySold * PrincipleValue
RETURN
Accumulation:
LocalsTotal = LocalsTotal + BondAmt
RETURN
WriteDetail:
PRINT #4, TAB(7); USING "###"; Federal; TAB(16);
PRINT #4, USING "##"; State; TAB(25);
PRINT #4, USING "#"; (Locals);
PRINT #4, TAB(31); PrintAccount$; TAB(44); USING "#,###"; QuantitySold; TAB(52);
PRINT #4, USING "#,###.##"; PrincipleValue;
PRINT #4, TAB(64); USING "#,###,###.##"; BondAmt
LineCount = LineCount + 1
RETURN
LocalsTotalOutPut:
PRINT #4,
PRINT #4, TAB(31); "Local #"; LocalsHold; TAB(45); "Total Value:";
PRINT #4, TAB(62); "$"; TAB(63); USING "##,###,###.##"; LocalsTotal;
PRINT #4, TAB(77); "*"
StateTotal = StateTotal + LocalsTotal
LocalsTotal = 0
GOSUB PreviousLocalsSetup
RETURN
StateTotalOutput:
PRINT #4, TAB(31); "State #"; StateHold; TAB(45); "Total Value:";
PRINT #4, TAB(61); "$"; TAB(62); USING "###,###,###.##"; StateTotal;
PRINT #4, TAB(77); "**"
FederalTotal = FederalTotal + StateTotal
StateTotal = 0
GOSUB PreviousStateSetup
RETURN
FederalTotalOutput:
PRINT #4, TAB(31); "Federal #"; FederalHold; TAB(45); "Total Value:";
PRINT #4, TAB(59); "$"; TAB(60); USING "#,###,###,###.##"; FederalTotal;
PRINT #4, TAB(77); "***"
FinalTotal = FinalTotal + FederalTotal
FederalTotal = 0
GOSUB PreviousFederalSetup
RETURN
FinalTotalOutput:
GOSUB LocalsTotalOutPut
GOSUB StateTotalOutput
GOSUB FederalTotalOutput
PRINT #4,
PRINT #4, TAB(26); "Final Total Value of All Bonds:"; TAB(59);
PRINT #4, "$"; TAB(60); USING "#,###,###,###.##"; FinalTotal;
PRINT #4, TAB(77); "****"
RETURN
CloseFiles:
CLOSE #1
CLOSE #2
CLOSE #3
CLOSE #4
RETURN