IF INSTR(text$
, "QB64 COMPILER ONCE ONLY SETUP CODE ENDS HERE") THEN PRINT #2, "'************ START OF TIMED EVENTS INITIALIZATION" PRINT #2, "TimeEvent = _FREETIMER" PRINT #2, "ON TIMER(TimeEvent, 1) TimedEvent 'A once a second timer" PRINT #2, "IF NOT NoIDEMode THEN TIMER(TimeEvent) ON" PRINT #2, "DIM SHARED AutoSave AS INTEGER, AutoSaveTimer AS DOUBLE " PRINT #2, "'************ END OF TIMED EVENTS INITIALIZATION" PRINT #2, "VKOfound = -1 'only the first time this appears in the code." PRINT #2, "IF LEFT$(temp$,10) = " + CHR$(34) + "$AUTOSAVE:" + CHR$(34) + " THEN " PRINT #2, " AutoSave = -1" PRINT #2, " temp1$ = MID$(temp$,11)" PRINT #2, " l1 = INSTR(temp1$, " + CHR$(34) + "*" + CHR$(34) + ")" PRINT #2, " AutoSaveTimer = VAL(LEFT$(temp1$,l1)) * VAL(MID$(temp1$,l1+1))" PRINT #2, " AutoSaveTimer = VAL(MID$(temp$,11))" PRINT #2, " IF AutoSaveTimer = 0 THEN a$ = " + CHR$(34) + "ERROR: No Time Set on AutoSave" + CHR$(34) + ": GOTO errmes" PRINT #2, " layout$ = " + CHR$(34) + "$AUTOSAVE:" + CHR$(34) + " + LTRIM$(STR$(AutoSaveTimer))" PRINT #2, " GOTO finishedlinepp"
IF INSTR(text$
, "a3u$ = UCASE$(a3$)") THEN PRINT #2, "IF LEFT$(a3u$,9) = " + CHR$(34) + "$AUTOSAVE" + CHR$(34) + " THEN GOTO finishednonexec" PRINT #2, "SUB TimedEvent" PRINT #2, "STATIC backidet$, TimeElapsed AS _UNSIGNED LONG" PRINT #2, "TimeElapsed = TimeElapsed +1" PRINT #2, "IF NOT Autosave THEN EXIT SUB" PRINT #2, "IF AutoSaveTimer = 0 THEN EXIT SUB" PRINT #2, "IF TimeElapsed MOD AutoSaveTimer = 0 THEN" PRINT #2, " IF NOT _DIREXISTS(" + CHR$(34) + "internal\autosave" + CHR$(34) + ") THEN MKDIR " + CHR$(34) + "internal\autosave" + CHR$(34) PRINT #2, " IF backidet$ <> idet$ THEN" PRINT #2, " ProposedTitle$ = FindProposedTitle$" PRINT #2, " IF ProposedTitle$ = " + CHR$(34) + CHR$(34) + " THEN" PRINT #2, " savename$ = " + CHR$(34) + "untitled" + CHR$(34) + " + tempfolderindexstr$" PRINT #2, " savename$ = ProposedTitle$ + " + CHR$(34) + ".bas" + CHR$(34) PRINT #2, " savename$ = ideprogname" PRINT #2, " t$ = DATE$ + " + CHR$(34) + " - " + CHR$(34) + " + TIME$" PRINT #2, " LOOP UNTIL l = 0" PRINT #2, " savename$ = " + CHR$(34) + "internal\autosave\" + CHR$(34) + " + savename$ + " + CHR$(34) + " (" + CHR$(34) + " + t$ + " + CHR$(34) + ") .bas" + CHR$(34) PRINT #2, " OPEN savename$ FOR OUTPUT AS #1510" PRINT #2, " FOR i = 1 TO iden" PRINT #2, " tempstring$ = idegetline(i)" PRINT #2, " PRINT #1510, tempstring$" PRINT #2, " backidet$ = idet$"
SHELL "qb64 -x source\qb64-MOD.bas"
Another update to the routine here, to make it a little more flexible -- we can now set the amount of time IN PROGRAM and not need to set it in QB64.bas like the previous version above does.
NOTE: Notice that I've configured this to run as a timed event which counts in SECONDS now, instead of MINUTES. For testing purposes, all you need to do is set something incredibly fast such as $AUTOSAVE:1 and it'll save your work every second into separate, individual, time-stamped BAS files.
NOTE2: I'm also lazy and don't want to calculate how many seconds are in a sequence of minutes. If I want it to autosave my work every 27.2 minutes, how many seconds is that? I dunno! And, I don't want to have to get out a calculator to figure it out!!
So, this is a "smart" metacommand which calculates for us, as I'll illustrate below:
$AUTOSAVE:10 <--- This will autosave our work every 10 seconds into timestamped BAS files
$AUTOSAVE:60 <--- This will do it once a minute
$AUTOSAVE:27.2*60 <--- This will do it once every 27.2 minutes, AND it'll calculate that math and automagically replace the value for us so we can see how many seconds 27.2*60 is.
So, in the end, usage is now:
$AUTOSAVE:secondsJust remember,
seconds can include multiplication to be precalculated for us. It doesn't do variables, addition, subtraction, or division -- JUST multiplication! After all, if you're trying to divide the number of seconds you autosave, you're doing something wrong...
**********************
**********************
And just out of personal curiosity, am I the only person who is interested in such things? These topics seldom ever get a response, so I'm often wondering if there's no need to bother sharing such code. (I don't care though; I'll continue to share anyway, just so these little "Mod-Projects" are archived in various places across the net, and available to help me hunt them down for myself, if I ever need them again in the future. Ptttttbbbttt!!)
Surely I'm not the only person out there to ever need/want to be able to have QB64 save my code at set intervals, for me?? The longer the project, the more I like/require things to be regularly backed up so I can maintain a working chain in case of total brain failure and code collapse. Am I the only one who does this? :P