1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB - using a variable

Discussion in 'Software Development' started by Lucky5tar, Apr 26, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. Lucky5tar

    Lucky5tar Thread Starter

    Joined:
    Aug 2, 2008
    Messages:
    279
    I think it's obvious what I'm trying to do here - use the "proxy" variable but it's chucking an error message (invalid character), how do you properly call text variables?

    Code:
    dim proxy
    set proxy = "%Proxy2%"
    
    dim oShell
    set oShell = Wscript.CreateObject("Wscript.Shell")
    
    if msgbox("Turn Proxy on?", vbQuestion or vbYesNo) = vbYes then
    oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
    oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", ""%proxy%":8081", "REG_SZ"
    else
    oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
    end if
    
    Set oShell = Nothing 
    
     
  2. IT-Support

    IT-Support

    Joined:
    Nov 30, 2009
    Messages:
    277
    You need to change the line to:

    oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", proxy & ":8081", "REG_SZ"
     
  3. Lucky5tar

    Lucky5tar Thread Starter

    Joined:
    Aug 2, 2008
    Messages:
    279
    And how do I correctly set the value? (line 2)
     
  4. IT-Support

    IT-Support

    Joined:
    Nov 30, 2009
    Messages:
    277
    set proxy = "myProxyDomain.com"

    Obviously put your proxy server domain name in where it says myProxyDomain or if you're using an IP address then put the IP in.
     
  5. Lucky5tar

    Lucky5tar Thread Starter

    Joined:
    Aug 2, 2008
    Messages:
    279
    No that generates an error:

    Object Required [String"Proxy2"]
     
  6. IT-Support

    IT-Support

    Joined:
    Nov 30, 2009
    Messages:
    277
    Try losing the Set part, so it becomes:
    proxy = "myProxyDomain.com"
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/919318

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice