Taking Stock

This file is part of and SINCUS Exchange Tape 103 - Potpourri. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 2068

This program is a stock portfolio valuation tool that tracks company names, share counts, and current prices to calculate individual holding values and a total portfolio value. On first use, it collects company names and share quantities, storing them in a string array `N$` and a numeric array `S`, then saves both to tape as separate data files using `SAVE DATA` statements. Subsequent runs load those arrays from tape before prompting the user to enter current share prices from newspaper stock quotations. The program supports hardcopy output via an attached thermal printer (TS2040), printing a formatted portfolio report with a decorative header and dollar-sign separator lines. Two distinct `SAVE` lines at lines 9998–9999 demonstrate a deliberate strategy: one saves with `LINE 9995` to auto-load data arrays before starting, while the other saves with `LINE 1` for general-purpose use.


Program Analysis

Program Structure

The program is organized into three logical phases:

  1. Initialization (lines 1–5): Handles first-use branching, disabling FLASH, setting up uppercase input via POKE 23658,8, and initializing the total accumulator.
  2. Main valuation loop (lines 10–89): Iterates over each company, prompts for current share price, computes holding value, accumulates total, and optionally prints a formatted hardcopy report to the TS2040 printer.
  3. Summary and save routines (lines 176–9999): Displays and prints the portfolio total with a dated label, followed by first-use setup subroutine at line 8000, and tape save/load management lines at 9990–9999.

Data Persistence Strategy

The program separates persistent data from session data. Company names (N$) and share counts (S) are considered stable and are saved to tape as named data files "STOKNAMDAT" and "SHARNUMDAT" respectively via SAVE DATA at line 8050. Current prices (P) and computed values (V) are treated as ephemeral and are only held in session arrays. This design means the user only needs to re-enter prices on each run, not the full portfolio definition.

First-Use Subroutine

Lines 8000–8060 form the first-use setup subroutine, invoked when the user answers “Y” at line 3. It displays multi-screen instructions about data entry requirements, then collects company names and share counts before saving both arrays. The subroutine correctly uses RETURN at line 8060. Notably, this subroutine defines T, N$, and S internally, so control must not reach the main loop (lines 15–75) without having previously defined these arrays — the flow is safe on first use because the subroutine returns to line 5 which re-inputs T and re-dimensions the arrays.

Load Path at Line 9995

Line 9995 is never reached during normal execution; it exists solely as the auto-run target for the SAVE "STOKVALU" LINE 9995 command at line 9998. When the program is loaded via that save, it executes LOAD DATA for both arrays and then jumps to line 1 to begin normal operation. This is a clean bootstrapping pattern for tape-based data loading.

Array Dimensioning Anomaly

The main program dimensions P(T) and V(T) at line 15, but N$(T,10) and S(T) are dimensioned inside the first-use subroutine at line 8020. On subsequent runs (when the user answers “N” to first use), the program skips the subroutine and loads data via the tape load at line 9995 — but if the user runs the main save (LINE 1) and loads it fresh, the arrays N$ and S are never dimensioned before line 15, which would cause an error. The program depends on the correct save variant being used for reliable operation.

Input Validation

Lines 1 and 80 use a guard pattern: if the user presses ENTER with no input (resulting in an empty string), the program loops back to re-ask the question. This prevents accidental blank responses from being treated as valid answers.

Printer Output Formatting

Lines 85–89 and 180 produce printer output using LPRINT. The report includes a decorative separator of underscores, a spaced-out title “T A K I N G S T O C K”, and tabulated columns using TAB positions 18 and 25. The dollar-sign line ($$$$...) is printed to both screen and printer for the totals section.

Key BASIC Idioms and Techniques

  • POKE 23658,8 — forces uppercase input mode, appropriate for a data-entry application.
  • POKE 23692,255 at line 10 — disables the scroll prompt (“scroll?”), allowing the listing to print without interruption.
  • PAUSE 0 followed by implicit keypress detection — used at lines 8006, 8010, and 176 as an efficient “press any key to continue” idiom.
  • INPUT with multiple variables in a single statement (line 176) — e.g., INPUT "...MONTH ";M;" DAY ";D;" YEAR ";Y — uses the Spectrum’s multi-variable INPUT syntax.
  • Two SAVE variants at lines 9998 and 9999 with different LINE parameters serve different operational contexts, with inline REM comments explaining their intended use.

Variable Summary

VariableTypePurpose
I$StringFirst-use Y/N response
TNumericTotal number of companies
N$String array (T×10)Company names (max 10 chars)
SNumeric array (T)Number of shares per company
PNumeric array (T)Current price per share
VNumeric array (T)Computed value per holding
TOTNumericTotal portfolio value
C$StringPrinter copy Y/N response
M, D, YNumericMonth, day, year for report date
NNumericLoop counter

Content

Related Products

Related Articles

Related Content

Image Gallery

Taking Stock

Source Code

    1 FLASH 0: CLS : POKE 23658,8: INPUT "FIRST USE? Y/N",I$: IF I$="" THEN GO TO 1
    3 IF I$="Y" THEN GO SUB 8000
    5 LET TOT=0: INPUT "NUMBER OF CO.s REPRESENTED ";T
   10 POKE 23692,255: PRINT "NAME   # SHARES   PRICE   VALUE"
   15 DIM P(T): DIM V(T)
   18 FOR N=1 TO T
   20 PRINT N$(N);
   30 PRINT TAB 12;S(N);
   40 INPUT "current price ea. ";P(N)
   50 LET V(N)=S(N)*P(N)
   60 LET TOT=TOT+V(N)
   70 PRINT TAB 18;P(N);TAB 25;V(N)
   75 NEXT N
   80 INPUT "Want a COPY from TS2040? Y/N",C$: IF C$="" THEN GO TO 80
   85 IF C$="Y" THEN LPRINT "________________________________": LPRINT : LPRINT "     T A K I N G  S T O C K     ": LPRINT 
   86 LPRINT ''"NAME      SHARES   PRICE   VALUE": LPRINT : LPRINT 
   87 FOR N=1 TO T: LPRINT N$(N);"  ";S(N);TAB 18;P(N);TAB 25;V(N)
   89 NEXT N
  176 PRINT '"PRESS ANY KEY": PAUSE 0: CLS : PRINT AT 10,5;"NOW FOR TOTAL TODAY": INPUT "DATE IN NUMERALS?MONTH ";M;" DAY ";D;" YEAR ";Y
  178 PRINT '"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$": PRINT ''"TOTLVAL  $";TOT;" DATE: ";M;"/";D;"/";Y
  180 LPRINT '"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$": LPRINT ''"TOTLVAL  $";TOT;" DATE: ";M;"/";D;"/";Y
  185 STOP 
 8000 PRINT "YOU WILL NEED STOCK MARKET PRICEQUOTATIONS FROM NEWSPAPER, LIST OF COMPANIES WITH WHICH YOU OWN STOCK, AND NUMBER OF SHARES.";'"YOU WILL ENTER CURRENT PRICE &  COMPUTER WILL PRINT THE CURRENT VALUE OF THAT BLOCK OF STOCK &  THEN VALUE TOTAL FOR ALL STOCK  YOU OWN ON THAT DATE."
 8005 PRINT '"BUT FIRST,";'"YOU WILL BE SAVING THE COMPANY  NAMES AND NUMBER OF SHARES IN   A STRING ARRAY AND AN ARRAY SO  BE ACCURATE.  HENCEFORTH, YOU   WILL ONLY NEED TO ENTER CURRENT PRICE IN TABLE FOR COMPLETE COM-PUTATION."
 8006 PRINT '''"PRESS ANY KEY": PAUSE 0: CLS 
 8008 PRINT '"IF YOU ARE USING A TAPE, YOU'LL NEED TO RECORD POSITION # ON    TAPE CAREFULLY OR LEAVE A BLANK AREA EQUAL TO LENGTH OF THIS    PROGRAM AND RECORD THIS PROGRAM AHEAD OF TWO DATA SAVES SINCE   THEY WILL LOAD FROM WITHIN THIS PROGRAM."
 8009 PRINT '"SINCE MAX OF CORP. NAMES IS 10  LETTERS, YOU MAY WANT TO USE THESTOCK MARKET ABBREVIATIONS FOR  THE COMPANY ISSUE."
 8010 PRINT ''"PRESS ANY KEY": PAUSE 0: CLS 
 8012 INPUT "TOTAL NUMBER OF ENTRIES (USUALLYTHE NUMBER OF DIFFERENT CORPOR- ATIONS INVOLVED) ";T
 8014 PRINT AT 19,0;"YOU WILL BE ASKED TO GIVE THIS  TOTAL ENTRY NUMBER ";T;" AGAIN IN THE MAIN PROGRAM.": PAUSE 360: CLS 
 8020 DIM N$(T,10): DIM S(T)
 8025 FOR N=1 TO T
 8030 INPUT "NAME OF COMPANY ",N$(N)
 8035 INPUT "NUMBER OF SHARES ";S(N)
 8040 NEXT N
 8050 SAVE "STOKNAMDAT" DATA N$(): SAVE "SHARNUMDAT" DATA S()
 8060 RETURN 
 9990 STOP 
 9995 CLS : PRINT INK 9;"LOADING TWO DATA ARRAYS": LOAD "STOKNAMDAT" DATA N$(): LOAD "SHARNUMDAT" DATA S(): GO TO 1
 9998 SAVE "STOKVALU" LINE 9995: STOP : REM DO NOT USE THIS SAVE UNTIL YOU HAVE SAVED TWO DATA ARRAYS.
 9999 SAVE "STOKVALU" LINE 1: REM ALL-PURPOSE SAVE FOR LATER INVESTIGATION OF PROGRAM

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top