:confused:
I'm trying to understand how to work with "environ" in Visual Basic 6 and i can't figure it out.
Please if someone can write me some explanation or some part of code that contained the "environ" issue.
TNX ;)
Printable View
:confused:
I'm trying to understand how to work with "environ" in Visual Basic 6 and i can't figure it out.
Please if someone can write me some explanation or some part of code that contained the "environ" issue.
TNX ;)
To show what's in the Path environment variable:
MsgBox Environ("path")
What's the problem?
Hi there Tygur,
do u now if there are any way of setting Environment vars from winthin VB ?
Code:
Private Declare Function SetEnvironmentVariable Lib "kernel32" _
Alias "SetEnvironmentVariableA" (ByVal lpName As String, ByVal lpValue As String) As Long
Private Sub Form_Load()
SetEnvironmentVariable "TEST", "UGH"
Shell "CMD.EXE"
'Now type SET, you'll see the Environment Variable set
' lasts just for this process, goes away when the .EXE stops.
End Sub
thanks jim mcnamara, but (there is always a but :) )
it does not seem to do the job in win2k ?
oops.. sorry its working... I looked in here :
http://www.pvp.no/vbw/env.jpg
not in running the SET command (as it said I should:rolleyes: )
assume it will be in the props panel after I reboot
thanks jim
okokok.. I know... I'd better goto bed :rolleyes:
didnt read this eitherany suggestions on how to make it stay there ?Quote:
' lasts just for this process, goes away when the .EXE stops
There is one problem with setting environment variables from within VB. If you set an environment variable using the SetEnvironmentVariable API, the changes don't show up when you try using Environ. So I've made a function that can be used in place of Environ so you can also get the changes that were made since your app started:
VB Code:
'This is the API declaration Private Declare Function GetEnvironmentVariable Lib "kernel32" _ Alias "GetEnvironmentVariableA" (ByVal lpName As String, _ ByVal lpBuffer As String, ByVal nSize As Long) As Long 'Uses API to get an environment variable 'This is necessary because the Environ function will not detect changes to the environment vars Function EnvironAPI(sString As String) As String Dim EnvVar As String Dim lLength As Long EnvVar = Space(256) lLength = GetEnvironmentVariable(sString, EnvVar, 256) 'If the environment variable is longer than 256 characters, we didn't get the whole thing yet If lLength > 256 Then EnvVar = Space(lLength) lLength = GetEnvironmentVariable(sString, EnvVar, lLength) End If EnvVar = Left(EnvVar, lLength) EnvironAPI = EnvVar End Function
Thanks :)
Quote:
Originally posted by Tygur
So I've made a function that can be used in place of Environ so you can also get the changes that were made since your app started:
LIES!!!!!! :eek:
Looks RATHER like the code here with very MINOR changes: http://www.vbapi.com/ref/g/getenvironmentvariable.html
:D On defence of Tygur, the code on that site isnt in a function, its in the code for a commandbutton. So Tygur did make the function, even though he may not have written the code;)
:rolleyes:Quote:
Originally posted by sbrown23
LIES!!!!!! :eek:
Looks RATHER like the code here with very MINOR changes: http://www.vbapi.com/ref/g/getenvironmentvariable.html
Well, I hate to bust your bubble, but I really did write that function I posted and the code within it. For one thing, I never go to vbapi.com for api help. I always refer to the source of this information, the MSDN Library.Quote:
Originally posted by sbrown23
LIES!!!!!! :eek:
Looks RATHER like the code here with very MINOR changes: http://www.vbapi.com/ref/g/getenvironmentvariable.html
I've been using VB since 1997. You'd think I ought to know how to use such a simple API function by now :rolleyes:
The reason why the codes look so similar is because there are only so many ways of calling such a simple API function, and they are all quite similar. Can you come up with a better way? I certainly came up with a better way than whoever wrote that code at vbapi.com. Read further.
Is your problem the length I chose for the buffer (256)? 256 is a very common number for buffer lengths when people are making API calls. You'll find hundreds, maybe thousands of codes out there for api calls like GetWindowText and GetClassName that send strings with a length of 255 or 256. Everybody does it.
Also, tell me. If you wanted to abreviate "Envorironment Variable", how would you do it? I'm sure most people would agree that "EnvVar" is quite common. I doubt the vbapi.com people trademarked the name or anything :rolleyes: And if you're going to bother me about the names of my length variable, you've really got issues :rolleyes:
That code is not similar to the code at vbapi.com, anyway. Look closer. If the environment variable is longer than 256 characters, my function up there will handle that and still return the whole thing. The code at vbapi.com does not. In fact, if the environment variable is longer than 256 characters long, the code at vbapi.com will not even retrieve it. Something like that is simply not acceptable for any code I make.
So, why did you think I copied that code, again? :rolleyes:
:eek: run for cover sbrown23... the tiger is awake!!
:D
slam, heheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheheh:D :D :D :D :D :D :D :p :p :p :p :p :p
The API.com code looks different alot.
Like he's the originator of coding this particular API call?
Just look below!~