rem *______________ Section 3.0 ___________________*
rem *                                              *
rem *       CHANGE ENTRIES IN STOCK FILE           *
rem *       ----------------------------           *
rem *	UPDATED:  February 5, 1983                 *
rem *	BY:       Edward A. Valenzuela             *
rem *	REVISION: 1.31    			   *
rem *______________________________________________*

rem ----- requires following subroutines -----
rem	    scrnin.bas
rem 	    stkbas.bas    ... for jump vectors
rem 	    stkcreat.bas  ... for screen menu

7300 rem ...titles for screen display...

  TITLE1$ = "STOCK FILE CHANGE PROGRAM"
  TITLE2$ = "enter stock name for data changes"
    delete$="F"
	GOSUB 7305
	RETURN

rem ----------------- SUBROUTINES ------------------
7305 rem ...... create screen display ..............

  MORECHANGE$ = "Y"
WHILE MORECHANGE$ = "Y"

7310 print clear$; \
           fn.down$(2); \
           fn.right$(15); TITLE1$
     print down$; fn.right$(4); "STOCK NAME:"
     print down$; fn.right$(2); "INSTRUCTIONS:"

    namstk$ = fn.entry$(2,16,\
              TITLE2$,7,16)
    if end #9 then 7316
    open "B:STKFIL01.DAT" RECL 80 AS 9 
    if end #9 then 7317    
7311 i%=0
    while -1
     i%=i%+1
     GOSUB 310	: rem .. read in stock name

     if match(namstk$,namstk$(i%),1) = 0 then goto 7331 \
    else nrec%=i%: goto 7332

7331 wend

7317 print fn.line$(13); fn.right$(16); "match not found"
input "continue...? y or n?";y$
y$ = UCASE$(y$)
 if y$ = "Y" then goto 7310 : close 9 else RETURN

7316 print "data file B:STKFIL01.DAT not found"
     print "check disk in drive B"
     input "enter y to continue"; y$
     INITIALIZE
     goto 7310
7332 rem ... fill screen with selected data ...
  nstk% = nrec%
  gosub 710

rem ... add data to screen ...
i%=nrec%

  print fn.line$(4); fn.clear$(16,line%); fn.right$(16); namstk$(i%)
  print              fn.clear$(16,line%); fn.right$(16); xchng$(i%)
  print              fn.right$(16); nshrs%(i%)
  print              fn.right$(16); purdate$(i%)
  print              fn.right$(16); totpurprice(i%)
  print              fn.right$(16); commission(i%)
  print              fn.right$(16); symbol$(i%)
  print              fn.right$(16); dividend(i%)

if delete$="T" then RETURN : rem ... if called from STKDELETE
7340 rem ... ask for field corrections ...

gosub 720

rem ... valid data, store the record ...

I% = NREC%
print #9, nrec%; nshrs%(i%),namstk$(i%),symbol$(i%),xchng$(i%),purdate$(i%), \
              commission(i%),totpurprice(i%),key%(i%),dividend(i%)
CLOSE 9

rem ... ask if finished ...

 print fn.line$(13); :
  print fn.clear$(16,line%) 
  for j%=1 to 8 :
    print fn.clear$(2,line%) :
  next j%

 MORECHANGE$ = fn.entry$(0,44, \
   "input another stock? y or n?",13,16)
 MORECHANGE$ = ucase$(MORECHANGE$)

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

7349 RETURN

rem *____________ End of Section 3.0 ______________*

rem * -------- STOCK SPLIT UPDATE PROGRAM -------- *
7800 rem ...titles for screen display...

  TITLE1$ = "STOCK SPLIT PROGRAM"
  TITLE2$ = "enter stock name that split"
    delete$="T"
	GOSUB 7305
 if match(namstk$,namstk$(nrec%),1) <> 0 then close 9

print fn.line$(13); fn.right$(16); \
      "IS THIS THE CORRECT STOCK TO UPDATE ?"
print fn.right$(16); bell$ ;
  input "y or n?"; y$

if y$= "x" then goto 900
if y$= "y" then goto 7810 else goto 7800

7810 print
     print "enter the split factor as a fraction"
     print "for example, if the stock splits 2 for 1"
     print "your present holdings double, the factor"
     print "is 2.00"
     print "if the split is 3 for 2, factor = 1.50"
     print
     print "if a stock dividend is declared rather than"
     print "a split, enter the multiplicative factor"
     print "for example, for a 5% stock dividend,"
     print "the factor is 1.05"
     print
7811 input "ENTER STOCK SPLIT FACTOR : "; split
     print
     print "you have entered "; split; " as the split factor"
     input "enter y/n if this is correct/incorrect "; yes$
     yes$ = ucase$( yes$ )
     if yes$ = "n" then goto 7811

 OPEN "B:STKPRICE.DAT" RECL 30 AS 8
 OPEN "B:STKFIL01.DAT" RECL 80 AS 9
   NPRC%=NREC%+1
 
 READ #8, NPRC%; newprice,oldprice
   newprice = newprice/split	
   new$     = str$( newprice )
   newprice$ = left$( new$, 6 )
   newprice = val( newprice$ )
 
   oldprice = oldprice/split 
   old$     = str$( oldprice )
   oldprice$ = left$( old$, 6 )
   oldprice = val( oldprice$ )
 PRINT #8, NPRC%; newprice,oldprice
 
 READ #9, NREC%; nshrs%,namstk$,symbol$,xchng$,purdate$, \
          commission,totpurprice,key%,dividend
   nshrs% = int%( nshrs% * split )
 PRINT #9, NREC%; nshrs%,namstk$,symbol$,xchng$,purdate$, \
   commission,totpurprice,key%,dividend
 
CLOSE 8,9
REM .. UPDATE HISTORICAL PRICE FILES ..
 GOSUB 7850

RETURN

7850 rem ----- UPDATE HISTORICAL PRICE FILE -----
     REM -----     FOR STOCK SPLITS         -----
  file%=1

7870 on file% goto 7851,7852,7853,7854,7855,7856

7851 filename$ = "B:DAYHST.DAT"
        GOTO 7860
7852 filename$ = "B:WEEKHST.DAT"
   	GOTO 7860
7853 filename$ = "B:MONTHST.DAT"
   	GOTO 7860
7854 filename$ = "B:QUARTHST.DAT"
   	GOTO 7860
7855 filename$ = "B:YEARHST.DAT"
   	GOTO 7860
  
  7860 if end #4 then 7859
       OPEN FILENAME$ RECL 8 AS 4
       if end #4 then 7863
  rec%=2

WHILE -1
 read #4, rec% ; nprices%
  newrec%=rec% + nrec% + 1
 read #4, newrec% ; oldprice
  oldprice = oldprice/split
   old$     = str$( oldprice )
   oldprice$ = left$( old$, 6 )
   oldprice = val( oldprice$ )
   print #4, newrec% ; oldprice
  REC% = rec% + nprices% + 2
WEND 

7859 rem ... no file, continue to next file ...
  file% = file%+1
  goto 7870  

7863 rem ... end-of-file ...
  CLOSE 4
  file% = file% + 1
  goto 7870

7856 RETURN

REM ------ END OF SUBROUTINE UPDATE FOR SPLIT ------

7900 rem ... UPDATE HISTORICAL PRICE FILE FOR ADDED STOCKS ...
  file%=1

7920 on file% goto 7901,7902,7903,7904,7905,7906

7901 name.file$ = "DAYHST"
        GOTO 7910
7902 name.file$ = "WEEKHST"
     	GOTO 7910
7903 name.file$ = "MONTHST"
        GOTO 7910
7904 name.file$ = "QUARTHST"
        GOTO 7910
7905 name.file$ = "YEARHST"
        GOTO 7910
  
7910 if end #4 then 7909
     filename$ = "B:" + name.file$ + ".DAT"
     NEWFILE$  = "B:" + name.file$ + ".$$$"
     OLDFILE$  = "B:" + name.file$ + ".BAK"	

	OPEN FILENAME$ RECL 8 AS 4 
        CREATE NEWFILE$ RECL 8 AS 1 
	FILE OLDFILE$	: rem ... as file #2
       if end #4 then 7929
while -1
 read  #4 ; date
 print #1 ; date
   read  #4 ; nprices%
   print #1 ; nprices%+1
   read  #4 ; market
   print #1 ; market

 i% = 1
 WHILE i% <= nadd%-1
   read  #4 ; oldprice
   print #1 ; oldprice
 i% = i% + 1
 WEND

   print #1 ; 0

 i% = nadd% + 1
 WHILE i% <= nprices%
   read  #4 ; oldprice
   print #1 ; oldprice
 i% = i% + 1
 WEND

WEND 

7909 rem ... no file, continue to next file ...
  file% = file%+1
  goto 7920  

7929 rem ... end-of-file ...
  CLOSE 1, 4
rem .. STEP 1 .. delete old BAK file
  DELETE 2
rem .. STEP 2 .. rename current DAT file to BACKUP
  if not rename( OLDFILE$, FILENAME$ ) \
     then 7930
rem .. STEP 3 .. rename TEMP file to NEW DAT file
  if not rename( FILENAME$, NEWFILE$ ) \
     then 7930
7930 FILE% = FILE%+1
  goto 7920

7906 RETURN

REM -------- END OF SUBROUTINE UPDATE FOR ADD ------

7950 rem ... UPDATE HISTORICAL PRICE FILE FOR DELETIONS ...
  file%=1

7970 on file% goto 7951,7952,7953,7954,7955,7956

7951 name.file$ = "DAYHST"
        GOTO 7960
7952 name.file$ = "WEEKHST"
	GOTO 7960
7953 name.file$ = "MONTHST"
   	GOTO 7960
7954 name.file$ = "QUARTHST"
   	GOTO 7960
7955 name.file$ = "YEARHST"
   	GOTO 7960
  
  7960 if end #4 then 7959
     filename$ = "B:" + name.file$ + ".DAT"
     NEWFILE$  = "B:" + name.file$ + ".$$$"
     OLDFILE$  = "B:" + name.file$ + ".BAK"	

	OPEN FILENAME$ RECL 8 AS 4 
        CREATE NEWFILE$ RECL 8 AS 1 
	FILE OLDFILE$	: rem ... as file #2
       if end #4 then 7969

while -1
 read #4 ; date
 print #1 ; date
 read #4 ; nprices%
 print #1 ; nprices%-1
 read #4 ; market
 print #1 ; market

 i% = 1
 WHILE i% <= nrec%-1
  read #4 ; oldprice
  print #1 ; oldprice
 i% = i% + 1
 WEND

  read #4 ; oldprice

 i% = nrec%+1 
 WHILE i% <= nprices%-1
  read #4 ; oldprice
  print #1 ; oldprice
 i% = i% + 1
 WEND

WEND 

7959 rem ... no file, continue to next file ...
     file% = file%+1
     goto 7970 

7969 rem ... end-of-file ...
  CLOSE 1, 4
rem .. STEP 1 .. delete old BAK file
  DELETE 2
rem .. rename current DAT file to BACKUP
  if not rename( OLDFILE$ , FILENAME$ ) \
     then 7980
rem .. rename TEMP file to NEW file
  if not rename( FILENAME$ , NEWFILE$ ) \
     then 7980
7980 FILE% = FILE%+1
  goto 7970  

7956 RETURN

rem *____________ End of Section 3.5 ______________*
rem *						   *
rem *      END OF STOCK FILE CHANGE SUBROUTINE     *
rem *						   *
rem *----------------------------------------------*
