Click or drag to resize

GetEnv Function

X#
Retrieve the contents of a DOS environment variable.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax
 FUNCTION GetEnv(
	cEnvVariable AS STRING
) AS STRING
Request Example 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=<paramref name="DatabaseFilePath" />
2C>SET LOC_NTX=<paramref name="IndexFilePath" />
3C>SET LOC_RPT=<paramref name="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