Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date stamp in Command Window
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01281107
Message ID:
01281204
Views:
7
Larry,

We wrote a program that does exactly that when VFP starts, it is quite old, we wrote it for VFP 6 IIRC and it has room for a lot of improvement, but it works like this:

In the config.fpw that starts with foxpro we add
_startup = 'cmdEdit.prg' && Add path if needed
cmdEdit.prg has the following code, you'll notice some hard coding stuff that it would be better if changed
* This program adds a date string as a comment in _command.prg to easily visualize
* When a new day of commands started in our command window
* In order to be automatically executed, it should be included in the config.fpw file as:
* _startup = 'x:\foxv\prog\cmdedit.prg'

#define kNewLine Chr(13)

local lcCmd, lnSelect, lcUser, lcPreLine, lcInfoLine, lcPostLine, llReturn, llError, loDialog, lcSafety
lnSelect	= Select()
llReturn	= .f.
llError		= .f.


if not File('c:\fox\_command.prg') or Version(2) = 0		&& Check that the file _command exists and it is not a RunTime version
	return .f.
endif

try
	select 0
	use x:\foxv\cmdedit
	lcUser	= Upper(getenv('USERNAME'))

	if Seek(lcUser, 'cmdEdit', 'User') or Seek('*', 'cmdEdit', 'User')
		lcCmd			= Filetostr('c:\fox\_command.prg')
		lcInfoLine		= getLine(cmdEdit.InfoLine)
		if At(lcInfoLine, lcCmd) = 0 and cmdEdit.Active
			SaveHistory(lcCmd, lcUser)	&& Saves the _command content in the x:\fox\command folder
			lcPreLine		= getLine(cmdEdit.PreLine) + kNewLine
			lcInfoLine		= lcInfoLine + kNewLine
			lcPostLine		= getLine(cmdEdit.PostLine) + kNewLine
			lcCmd			= lcCmd + lcPreLine + lcInfoLine + lcPostLine
			lcSafety		= Set("Safety")
			set safety off
			llReturn		= Strtofile(lcCmd, 'c:\fox\_command.prg') > 0
			set safety &lcSafety
		else
			llReturn		= .T.
		endif
	endif
catch
	loDialog 	= SkyDialog('*Could not update _command file', 'Errors found while running cmdEdit.prg', '', '', 'Arial;11;;255;000;000,Default', 5000, '', 117, '', '')
	llError		= .T.
finally
	use in Select('cmdedit')
	select (lnSelect)
	_shell = ''
endtry

if not llError and not llReturn
	loDialog 	= SkyDialog('*Could not update _command file', 'Failed to write changes into c:\fox\_command.prg', '', '', 'Arial;11;;255;000;000,Default', 5000, '', 117, '', '')
endif
return llReturn

**************************************************************************************************************
function getLine(tcText)

try
	lcText			= Evaluate(tcText)
catch
	lcText			= tcText
endtry
lcText			= Alltrim(Iif(Vartype(lcText)='C', lcText, Transform(lcText)))
lcText			= Iif(Left(lcText, 1)='* ', '', '*') + lcText
return lcText

**************************************************************************************************************
function SaveHistory(tcCommand, tcUser)
local lcFolder, lcPost, lnFiles, laFiles(1)

if CmdEdit.HistSize > 0
	lcFolder		= Addbs(Iif(Empty(CmdEdit.HistFolder), 'C:\FOX', Alltrim(CmdEdit.HistFolder)))
	if Directory(lcFolder, 1)
		lnFiles			= Adir(laFiles, lcFolder + tcUser + '_command@*')
		if lnFiles >= CmdEdit.HistSize	&& Delete older files
			create cursor c_files (file C(30), size i, date D, time C(10))
			append from array laFiles
			index on Dtos(date) + time tag date descending
			go Top
			Skip (CmdEdit.HistSize - 1)
			scan rest
				delete File (lcFolder + Alltrim(c_files.File))
			endscan
			use in Select('c_files')
		endif
		lcPost			= Dtos(Date()) + Strtran(time(), ':', '')
		Strtofile(tcCommand, Forceext(lcFolder + tcUser + '_command@' + lcPost , '.PRG'))
	else
		md (lcFolder)
	endif
endif
You'll notice that there are two "features", one is that we use a table so each one of us can use a different "TimeStamp" for when they start, and second is that we make a copy of _command in a separate folder to keep a "History" just in case

The table we called use x:\foxv\cmdedit.dbf (again, hardcoded :() and it's structure is
Field  Field Name      Type                Width    Dec   Index   Collate Nulls    Next    Step
    1 USER            Character               5            Asc   Machine    No
    2 PRELINE         Character              80                             No
    3 INFOLINE        Character              80                             No
    4 POSTLINE        Character              80                             No
    5 HISTSIZE        Integer                 4                             No
    6 ACTIVE          Logical                 1                             No
    7 HISTFOLDER      Character              64                             No
Note that User is only 5 chars for that is the policy in here, you should change it and as you can see it has an index on it so we can find the record for the user, and * is the default (keep in mind I do not remember all the details!)

Well, now the table has those preline, infoline and postline things that really are just to somehow customize the entry, we use a line of stars for pre and post lines and a message that has the datetime as infoline, the important thing here is that the program does not add anything in the command window if infoline already exists in it, so if you put a constant string, nothing will be added after the first time, if you put a date, then one line will be added each day that you start vfp, and if you add a datetime, a line will be added each time you start vfp (if more than a second elapsed), for example we have entries like
'Session started for ' + longdate(date()) + ' at ' + time() && Longdate is a custom function
or
'Session started for ' + longdate(date())
Also, I just noticed there is a bug in SaveHistory, as I checked my folder and have 761 saved commands, so they are not getting deleted.

Anyways, I am not sure if I was clear, in the end, each day I start foxpro I see something like this:
*********************************************************************************
*Session started for Thursday, January 10, 2008
*********************************************************************************
[Update]
Ah, I just noticed we use SkyDialog that is nothing more than a MessageBox replacement
Also noticed the use of try and catch, wich means we updated the program or is not as old as I thought <g>
[/Update]
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Reply
Map
View

Click here to load this message in the networking platform