Home > Back-end >  In Visual Foxpro, how do I change date format {^yyyy-mm-dd} to {dd/mm/yyyy} when building an EXE?
In Visual Foxpro, how do I change date format {^yyyy-mm-dd} to {dd/mm/yyyy} when building an EXE?

Time:07-19

In Visual Foxpro, how do I change date format {^yyyy-mm-dd} to {dd/mm/yyyy} when building an EXE file?

CodePudding user response:

There are a number of Global Settings in Vfp, and Set Date is one of them. Which like many other settings is "Scoped to the Current DataSession". So that when you start the Vfp IDE, or a custom myProject.EXE outside the IDE, you would get all default settings, which is American.

When your Exe starts it runs the code from the Project's "main" member which can be a PRG code file. So that you can put a few lines there like

Set Date YMD && yymmdd date, or:
Set Date DMY && ddmmyy
Set Century On && four digit year YYYY
Set Mark To "/" && DD/MM/YYYY

There are several further Settings like Set Hours and related and also Set SysFormats On which is an "all-in-one" and means taking over the current Windows O/S locale settings more or less. SET SYSFORMATS is scoped to the current data session, just like SET DATE so that you would repeat the same code all over again as soon as you create a new Data Session, like for example when you run a Form that has a property DataSession=2, or when you create a Session object.

NB: You can lookup all these Settings and object properties in the local Vfp Help file via F1 key. See also https://www.vfphelp.com/help/index.htm

CodePudding user response:

To add to Stefan's response (which is perfect), I would advise creating an "Environment" object where you can define all the SET options you need as parameters and set them all with a function in all your forms/reports as well as your application entry point.

We do something like this in our application (1000 forms/reports):

THISFORM.AddObject("oCusEnv", "CustomEnv")
THISFORM.oCusEnv.SetEnv()

Using THISFORM.AddObject() ensures the CustomEnv object inherits the forms datasession so the changes to the environment in SetEnv() will apply to the forms private datasession.

Note: We don't make use of DataEnvironment objects, if you are using them, I believe this would be the best place to issue any SET statements as the form inherits the DataEnvironment's datasession.

  • Related