Environment variables in VB6
Does anyone know how I can use environment variables in VB6? I know that there are probably answers all over the web, but I can't find anything. I'm trying to use variable set by a different app in my own program.
Thank you.
[243 byte] By [
yudi] at [2007-11-11 10:18:06]

# 1 Re: Environment variables in VB6
use the environ function, for example
environ("username")
mstraf at 2007-11-11 17:22:46 >

# 2 Re: Environment variables in VB6
That was fast...
Thanks. I'll try it out and post back here soon.
yudi at 2007-11-11 17:23:53 >

# 3 Re: Environment variables in VB6
Unless it's global, such as those that load during Windows startup, your application will not be able to access an environment variable that has been created by another application.
# 4 Re: Environment variables in VB6
When I tried mstraf's tip, I got an error message.
So there is no way to use another app's env. vars? I was reading an SDK that said I will need to do just that...
Is there maybe an API call that can do that?
yudi at 2007-11-11 17:25:57 >

# 5 Re: Environment variables in VB6
When I tried mstraf's tip, I got an error message...
it is (usually) helpful to know what error message you get... :)
for me
debug.print environ("username")
works fine
mstraf at 2007-11-11 17:26:55 >

# 6 Re: Environment variables in VB6
So there is no way to use another app's env. vars? I was reading an SDK that said I will need to do just that...
Is there maybe an API call that can do that?
That is correct. Application level environment variables are only known to the application that created them.
# 7 Re: Environment variables in VB6
Maybe it will be useful if I tell the scenario:
I am trying to make a U3 (www.u3.com) app. To do this, the U3 container program creates several environment variables that my app will need to read.
For example, the variable "U3_HOST_EXEC_PATH" holds the path to my app on the U3 device.
The U3 SDK says that my app will need to read these variables in order to work. Is there any way I can do this? Why would the SDK say to do it if there is no possible way?
yudi at 2007-11-11 17:28:58 >

# 8 Re: Environment variables in VB6
Well apparently I posted a link to an example over six months ago in a Microsoft newsgroup concerning a VB 6.0 app that supports U3. I knew that something about this sounded familiar. ;-)
http://tinyurl.com/g7pbe
# 9 Re: Environment variables in VB6
Interesting! I'll have a better look at the code soon, and I'll post back then.
yudi at 2007-11-11 17:31:01 >

# 10 Re: Environment variables in VB6
This code is great! It shows exactly how to use the U3 vars! I still don't understand why the Environ() code didn't work for me, but this code does. Thanks!
yudi at 2007-11-11 17:32:01 >
