'===========================================================================
' Subject: SELF MODIFYING CODE                Date: 11-13-97 (21:00)       
'  Author: Bert van Dam                       Code: QB, QBasic, PDS        
'  Origin: bd1rsd@usa.net                   Packet: MISC.ABC
'===========================================================================
'This program modifies itself each time it's run. It keeps a counter of
'the number of times it has been run in the variable 'counter'. When run the
'program modifies itself on disk, and then chaines to itself, which runs the
'modified version.

'When  trying  this  you  must save the file in ascii, and remove everything
'above the dotted line, inclusing the line itself. Do not change anything in
'the code, not even the comments!

'...................................................
'MODIFY.BAS
'Self modifying program, Bert van Dam, donated to the public domain.

Counter = 1                  'rem to keep sufficient space
                             'for larger numbers
PRINT
PRINT "The current counter is now "; Counter
PRINT
PRINT "Do you want to run the program again (y/n)? ";
Antw$ = INPUT$(1)
PRINT Antw$
IF INSTR(UCASE$(Antw$), "Y") = 0 THEN END

'increase counter by 1
Counter = Counter + 1
Counter$ = STR$(Counter)

'open the source code
OPEN "c:\qb45\chained\modify.bas" FOR BINARY AS #1

'goto the right location in the program and write the new
'counter value
PUT #1, 96, Counter$
CLOSE #1

'chain to the new version of the program
CHAIN "c:\qb45\chained\modify.bas"
END
