I appreciate you sharing this code.
Looking at your code was interesting to me as I was looking to be able to do an interesting variation of that.
But your code has a big problem in that it adds line feeds each time for each line. The problem is caused by adding
that #CR$ at the end of each WriteStringN , which is not needed because the N of WriteStringN already adds the CR.
Partial code shown. If you comment out the #CR$ at the end, it works fine.
Code: Select all
pos1 = FindString(string.s, "; last modified:", 1)
If pos1 = 1 ; yes, this is the line ! And it begins at position 1 !!
WriteStringN(2, modString.s); + #CR$) ; write the new values into 2. file
done = 0
Else
WriteStringN(2, string.s); + #CR$)
EndIf
Until Eof(1)
If done = 1
FileSeek(1, 0)
If CreateFile(2, source + ".pb")
WriteStringN(2, "; ----------------------------------------------------"); + #CR$)
WriteStringN(2, modstring.s) ;+ #CR$)
WriteStringN(2, "; ----------------------------------------------------"); + #CR$)
Repeat
WriteStringN(2, ReadString(1)); + #CR$)
Until Eof(1)
EndIf
EndIf
Now the interesting variation of this idea. I liked the idea of adding the last modified Date and Time to the
beginning part of the code when saved. It's a good future reference when looking at past code.
But I also wanted a way to add it to the finished executable program, so I could call it using a hot key for reference,
if some one using it in the field has a program question. Yes you could put version info in under compiler options, but
a lot of people don't really know how to use explorer to find it. Thus the hot key approach, and it works great!
I used your existing code except for the extra #CR$
But I added the following code after it in which I create a cdt.pb file only containing the string
cdt$="last modified: Date at Time"
The AddDateToSource.exe executable is created in my D:\PureBasic4.5\ directory, and uses the
same tool settings as above.
Code: Select all
dat$="last modified: " + GetDate() + " at " + GetTime(#C12HOUR)
CreateFile(1,"cdt.pb")
WriteString(1,"cdt$="+Chr(34)+dat$+Chr(34))
CloseFile(1)
Then you need to add the following to the programs code that you would like to add this to.
Code: Select all
;Located at first part of your programs code.
ver$="2.0"; add your version info here.
;include this file which has that one string cdt$ , with the Date and Time in it.
IncludeFile "D:\PureBasic4.5\cdt.pb"
;Debug cdt$
;combine all info into a string called vcdt$
vcdt$="Version: "+ver$+Chr(10)+Chr(10)+"Creation Date & Time: "+Chr(10)+cdt$
;add #ctrlv in your Enumeration list #ctrlv is Ctrl v
;make sure you use the right window # mine in this case was 0
;add AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_V, #ctrlV) ;vcdt$ view version date time
;to you main window hot keys list.
;in your main loop add:
Case #ctrlv
;Note ver$ (version) needs to be changed at first line of this code when you need to change versions.
MessageRequester("Program Name Version: Date: & Time:", vcdt$ , $C0)
The neat thing about this is that when ever you run the program from the IDE and press Ctrl v , it will display
that info, and it will change each time. But when you compile to an exe for release, its Date and Time is fixed
in the exe, and can be called any time using the hot key. You don't need the cdt.pb file any longer because it's
info has been compiled into your executable when it was compiled to an exe.
It works really great, and is a good add on to your code.
Thanks for sharing your code, and hope this added part is also of use to others on this forum.