XL: Reading the MS-DOS Environment StringLast reviewed: February 21, 1996Article ID: Q69725 |
The information in this article applies to:
IMPORTANT: The CALL() and REGISTER() functions are provided for advanced users only. If you use these functions incorrectly you could accidentally cause errors in your system's operation.
SUMMARYIt is possible to retrieve a set of characters from the MS-DOS environment string from Microsoft Excel if you are running under Microsoft Windows 3.0. This is done using the CALL and REGISTER functions.
MORE INFORMATIONThe DOS environment is an area of memory that MS-DOS sets aside to store a series of ASCII strings. Each string in the environment is terminated by a byte of zero. The final string is terminated by two bytes of zero. The following Microsoft Excel macro function will return the first N number of characters (starting with the second character) from the DOS environment string, including the zero bytes separating strings. This occurs as long as the first character in your environment string has the ASCII decimal value of N.
A1 Get_Environment A2 =REGISTER("KERNEL","GetMS-DOSEnvironment","D") A3 =CALL(A2) A4 =RETURN()Note: The CALL function can also be used on a standard worksheet in Microsoft Excel version 3.0. Using a return parameter of "D" in the REGISTER function tells Microsoft Excel to interpret the value returned from the DLL function call as a string with the first byte containing the number of bytes to follow in the string. In this case, the first byte in the string returned will be the first ASCII character in your environment string. If this character has a decimal value of N, the following N characters will be returned.
ExampleIf the first string in your environment is "~USERNAME=BOB", cell A3 returns 126 characters of your environment string, starting with
USERNAME=BOB{null}where {null} indicates the zero byte terminating the string. This is because the ASCII tilde character "~" has a decimal value of 126. You can then search this string for particular environment variables.
REFERENCES"Online Help," version 5.0 "Function Reference," version 4.0, pages 42-43, 350-352, 475-480 "Function Reference," version 3.0, pages 24, 193-194, 253-258 "Functions and Macros," version 2.1x, pages 255-256 and 337-340
|
KBCategory: kbusage
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |