Results 1 to 2 of 2

Thread: Environment Variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    4

    Question

    I'm trying to figure out how to access the environment variables. I'm working on an NT app, and I need to access some variables. I tried a piece of test code and it doesn't work. According to everything I read.. it should. Here are both variations.. any help would be appreciated
    (VB 6.0 SP3, EE)

    dim strSystemDrive as String
    dim strSystemRoot as String

    strSystemDrive = Environ(SYSTEMDRIVE)
    strSystemRoot = Environ(SYSTEMROOT)

    MsgBox strSystemDrive
    MsgBox strSystemRoot

    According to the online MSDN library online at Microsoft.. this should set strSystemDrive to C: and strSystemRoot to C:\WINNT.

    I've also tried it like this:
    dim strSystemDrive as String
    dim strSystemRoot as String

    strSystemDrive = Environ$(SYSTEMDRIVE)
    strSystemRoot = Environ$(SYSTEMROOT)

    MsgBox strSystemDrive
    MsgBox strSystemRoot

    In the first case, it complains that SYSTEMDRIVE is an undefined variable (option explicit is set). In the second case, they just appear to be empty. In both cases, if I type in (SYSTEMROOT) or (SYSTEMDRIVE) in any other case, VB converts it to upper case.

    Anyone have any ideas?

    Thanks,

    David


  2. #2
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    You could just run the code below to see exactly what your Environemnt is:
    And then dedeuce the reason for the trouble you had on the basis of what you get.

    Code:
    Dim indx As Integer
    Dim EnvString As String
    Dim strSize As Integer
    
    indx = 1
    msg = "Current Envoronment."
    Do
      'Get environment variable.
      EnvString = Environ$(indx)
    
      'Check if the result is valid or a null string
      If Len(Trim(EnvString)) > 0 Then
        'Get length
        strSize = Len(EnvString)
        msg = msg & "Env " & indx & ":- " & Trim(EnvString) & vbCrLf
      End If
      indx = indx + 1
    Loop Until EnvString = ""
    MsgBox msg, 64, "Environment."
    Clipboard.Clear
    Clipboard.SetText msg, vbCFText

    Here are the results from running on my Win95 sys:
    Code:
    Current Environment.
    Env 1:- TMP=C:\WINDOWS\TEMP
    Env 2:- TEMP=C:\WINDOWS\TEMP
    Env 3:- PROMPT=$p$g
    Env 4:- winbootdir=C:\WINDOWS
    Env 5:- COMSPEC=C:\WINDOWS\COMMAND.COM
    Env 6:- PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\PROGRA~1\SUPERC~1\BIN
    Env 7:- CMDLINE=WIN
    Env 8:- windir=C:\WINDOWS
    Env 9:- BLASTER=A220 I5 D1 T4
    DocZaf
    {;->



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width