Click or drag to resize

GetEnv Function

Retrieve the contents of a DOS environment variable.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.4a
Syntax
 FUNCTION GetEnv(
	cEnvVariable AS STRING
) AS STRING
View Source

Parameters

cEnvVariable
Type: String
The name of the environment variable whose contents you want to retrieve.  (Note that GetEnv() is not case-sensitive.)

Return Value

Type: String
The contents of the specified environment variable.
If the variable cannot be found, GetEnv() returns a NULL_STRING.
Remarks
GetEnv() lets you retrieve information from the DOS environment into an application program.  Typically, this is configuration information — including path names — that describe the location of files (database, index, label, or reports). Note:  Instead of using environment variables for configuring your application, you may want to consider using registry settings.
Tip Tip
Empty return value:
If you are certain that an environment variable exists and yet GetEnv() always returns a NULL_STRING, be sure there are no spaces between the environment variable name and the first character of the string assigned to it in the DOS SET command.
Examples
This example retrieves the current DOS path setting, making it the current X# path:
X#
1cPath := GetEnv("PATH")
2SET PATH TO (cPath)
This example uses environment variables to configure the specific locations of files.  When you set up a system, define environment variables that contain the location of various file types, like this:
X#
1C>SET LOC_DBF=<DatabaseFilePath>
2C>SET LOC_NTX=<IndexFilePath>
3C>SET LOC_RPT=<ReportFilePath>
In the configuration section of your application program, assign the contents of the environment variables to variables.
Then when you access a file, preface the reference with the path, as follows:
X#
1cDdfDirectory := GetEnv("LOC_DBF")
2USE (cDdfDirectory + "invoices.dbf")
See Also