Bug Article
[
Home
|
Contents
|
Search
|
Post
|
Reply
| Previous |
Next
]
Subject:
Errors/Inaccuracies in code
Name:
Wes Groleau
Date:
Wednesday, June 01, 2005
Email (spam proof):
Email the originator of this post
Product:
Other
Bug:
I downloaded some VB code that started out with: 'Below are two routines (and a demo routine) that dynamically set and get/return 'the value of environment variables. Note, you must use the EnvironmentGet function 'to return the current value of an environment variable, since the VB "Environ()" 'function only returns cached values (and cannot be refreshed). I discovered a bug and an incorrect comment in the code, so I tried to find the author to inform him. However, a search for "Andrew Baker" reveals that it is a very popular name. This website was the first hit that had anything to do with Visual Basic. Here is the error: EnvironmentGet = Left$(sBuffer, lEndPos - 1) On Windows 2000, in both Excel and Access, the "minus one" removes the last character of the string returned. Here is the inaccuracy: 'Set the environment variable for all other processes (via registry) lRet = SHSetValue(HKEY_CURRENT_USER, "Environment", ... etc. After this line is executed in Excel, the same Excel process will read the changed, but Access still reads the earlier value. If you exit Excel and re-open the same app, it will also read the original value. (Which is a Good Thing--the idea that I could write and run a VB app that would fool another VB app into thinking I was someone else was quite disturbing! Though not surprising in a #$%&$#^ Microsoft product)