rem *_______________ Section 1.0 __________________*
rem *						   *
rem *       CREATE STOCK FILE FOR FIRST TIME	   *
rem *	    --------------------------------	   *
rem *	WRITTEN: February 5, 1983		   *
rem *	UPDATED: April 20, 1983			   *
rem *	COPYRIGHT: E. A. Valenzuela		   *
rem *	VERSION: 1.50				   *	
rem *______________________________________________*

rem ----- requires subroutines -----
rem          stkupdat.bas
rem          scrnin.bas
rem          stkbas.bas    ... for jump vectors

700 rem ...... original creation ......
 nstk% = 0
 morestock$ = "y"

rem ... check to see if a stock file already exists ...
  if end #9 then 711
 OPEN "B:STKFIL01.DAT" AS 9
 print "FILE B:STKFIL01.DAT ALREADY EXISTS"
 input " do you want to continue? y or n? "; yes$ 
 if yes$ = "n" then CLOSE 9: RETURN

 print "old file will be written to B:STKFIL01.BAK"
 IF RENAME("B:STKFIL01.BAK", "B:STKFIL01.DAT") = 1 THEN GOTO 711 
 print
713 print "UNABLE TO RENAME OLD DATA FILE TO BACKUP"
 input "enter name for old stock file: 5 characters "; name$
   namefile$ = "B:" + UCASE$(name$) + "FIL.DAT"   
if rename(namefile$, "B:STKFIL01.dat") = 0 then goto 713
  
 input "do you want to continue? y or n? "; yes$
 if yes$ = "n" then return

711 CREATE "B:STKFIL01.DAT" recl 80 as 9 

WHILE MORESTOCK$ = "y"
  nstk% = nstk% + 1
  gosub 710    
  gosub 715    
  gosub 755    
  RETURN

rem ...... create screen display ...................

710 print clear$; \
           fn.down$(1); \
           fn.right$(15); "STOCK PURCHASE DATA" : rem line 2
     print down$; fn.right$(4); "STOCK NAME:"   : rem line 4
     print fn.right$(6); "EXCHANGE:"            : rem line 5
     print fn.right$(1); "NUMBER SHARES:"       : rem line 6
     print fn.right$(1); "PURCHASE DATE:"       : rem line 7
     print fn.right$(4); "TOTAL COST:"          : rem line 8
     print fn.right$(4); "COMMISSION:"          : rem line 9
     print fn.right$(8); "SYMBOL:"              : rem line 10
     print fn.right$(6); "DIVIDEND:"            : rem line 11

     print down$; fn.right$(2); "INSTRUCTIONS:" : rem line 13 
rem ...... enter data

return

715 gosub 800
    gosub 810
    gosub 820
    gosub 830
    gosub 840
    gosub 850
    gosub 860
    gosub 870

rem ...........field corrections....................
rem ... instructions on line 13, column 16

720 print fn.line$(13); fn.clear$(16,60); fn.right$(16); \
          "SELECT FIELD TO BE CORRECTED"
    print fn.right$(3); "0 = no changes"
print fn.right$(3); "1 = stock name         5 = total purchase cost"
print fn.right$(3); "2 = stock exchange     6 = commission charges"
print fn.right$(3); "3 = number of shares   7 = stock symbol"
print fn.right$(3); "4 = date purchased     8 = annual dividend"
    PRINT  : rem line 19
730 print fn.right$(6);bell$;
    input "WHICH FIELD DO YOU WANT TO CHANGE?"; field%

rem ... wait for valid field selection ...

while (field% < 0) or (field% > 8)
  print up$; fn.clear$(6,line%); fn.right$(16);
  input "ENTER A FIELD BETWEEN 0 AND 8: "; field%
wend

rem ... make valid correction ...

if field% eq 0 then goto 740
if field% ne 0 then             \
  print fn.line$(13); fn.clear$(16,line%) :\
  for j% = 1 to 8              :\
    print fn.clear$(2,line%)   :\
  next j%                      :\

  on field% gosub 800,          \ re-enter name
                  810,          \ re-enter exchange
                  820,          \ re-enter shares
                  830,          \ re-enter purchase date
                  840,          \ re-enter purchase cost
                  850,          \ re-enter commission
                  860,          \ re-enter symbol
                  870:          \ re-enter dividend
goto 720                       

740 rem ... 0 was entered, no changes selected ...

rem ... ask for reverification ...

print fn.right$(16);bell$;
 input "are you sure?"; y$

rem ... wait for yes or no

while (y$ ne "y") and  (y$ ne "n")
     print up$; fn.clear$(16,line%); fn.right$(16);bell$;
     input "enter y for yes or n for no"; y$
wend
  print up$; fn.clear$(16,line%)
  if y$ = "y" then RETURN
  if y$ = "n" then goto 720

750 RETURN

rem ...........valid data entry, store the record.......................
755 rem
 key%(nstk%)=nstk%
 i% = nstk%
   GOSUB 335

  print fn.line$(13); fn.clear$(16,line%) 
  for j% = 1 to 7     :
    print fn.clear$(2,line%)  :
  next j%             :
  print fn.line$(13)  :
morestock$ = fn.entry$(0,44, \
 "input another stock? y or n?",13,16)
 
if morestock$ = "n" then goto 714
if fn.mod%(nstk%,10) <> 10 then goto 714
712 rem .. save every 10 records to disk file ..  
  close 9

  open "B:STKFIL01.DAT" recl 80 as 9 
  if end #9 then 714
  while -1
    read #9; dummy%
  wend
rem .. chain program to itself to conserve memory ..
  drive$ = "A:"
  prog.name$ = "STKBASE"
  CHAIN DRIVE$ + PROG.NAME$
    
714 rem .. continue adding stocks
WEND	: rem .. end of while morestock$

rem ***** end of while morestock$ = "yes" *****

close 9

rem ... alphabetize the data files just to be sure ...

 open "B:STKFIL01.DAT" as 9
  FOR k%=1 to nstk%
    read #9; nshrs%(k%),namstk$(k%),symbol$(k%),xchng$(k%),  \
             purdate$(k%),commission(k%),totpurprice(k%),    \
             kode%(k%),dividend(k%)
    kode%(k%)=k% 
  NEXT K%
 close 9
NEWFILE$ = "B:STKFIL01.BAK"
OLDFILE$ = "B:STKFIL01.DAT"
  if not rename(NEWFILE$, OLDFILE$) then 1687
goto 1685

1687 print "unable to rename oldfile to BAK file"

1685 GOSUB 1681

     N% = NSTK%
     GOSUB 1550
 
CREATE "B:STKFIL01.DAT" RECL 80 as 9
  FOR J%=1 to nstk%
    k%=kode%(j%)
    PRINT #9; nshrs%(k%),namstk$(k%),symbol$(k%),xchng$(k%),  \
             purdate$(k%),commission(k%),totpurprice(k%),k%, \
             dividend(k%)
  NEXT J%
 close 9

rem ... SET UP PRICE FILES FOR FIRST TIME ONLY ...
CREATE "B:STKPRICE.DAT" RECL 30 AS 8
CREATE "B:STKPRICE.BAK" RECL 30 AS 7

GOSUB 5200 : rem ENTRY to STKUPDAT.BAS subroutine...

 GOSUB 345	: rem .. print stock price header
 print #7 ; nstk%, newdate$, newdate$

 GOSUB 355 	: rem .. print stock price file
FOR I% = 1 TO NSTK%
 print #7; NEWprice(i%),NEWprice(i%)
 oldprice(i%) = newprice(i%)
NEXT I% 

 print #7; newprice(i%), newprice(i%)
 oldprice(i%) = newprice(i%)
 GOSUB 350	: rem .. print S&P 500 price 

CLOSE 7,8

799 return

rem *_____________ end of section 1.0 _____________*
rem *						   *
rem *     end of STOCK FILE CREATION SUBROUTINE    *
rem *						   *
rem *----------------------------------------------*

rem ***********************************************
rem *              SUBROUTINES                    *
rem ***********************************************

800 temp$ = fn.entry$(9,17,\
      "enter name of stock",13,16)
rem ...... check name length ...... restrict to 24 characters
    namstk$(nstk%) = left$(temp$,24)
    return

810 xchng$ = fn.entry$(8,17,\
      "enter exchange: NYSE, AMEX, OTC or OTHER",13,16)
    xchng$(nstk%) = ucase$(xchng$)
    return

820 nshrs$ = fn.entry$(7,17,\
      "enter number of shares purchased",13,16)
    nshrs%(nstk%) = val(nshrs$)
    return

830 purdate$(nstk%) = fn.entry$(6,17,\
      "enter date: month/day/year purchased",13,16)
    return

840 totpurprice$ = fn.entry$(5,17,\
      "enter total purchase cost",13,16)
    totpurprice(nstk%) = val(totpurprice$)
    return

850 commission$ = fn.entry$(4,17,\
      "enter total commission charges",13,16)
    commission(nstk%) = val(commission$)
    return

860 SYMBOL$ = FN.ENTRY$(3,17,\
      "ENTER STOCK SYMBOL",13,16)
    SYMBOL$(NSTK%) = UCASE$(SYMBOL$)
    RETURN

870 dividend$ = fn.entry$(2,17,\
      "enter stock dividend",13,16)
    dividend(nstk%) = val(dividend$)
    return
 
899 rem ... error code goes here ...
rem -------- end subroutine stkcreat ---------------