Jump to content

Rebuild a Variable from other variables and use in a String


Recommended Posts

I have a simple example here and I am not sure how I would go about making this work. I want this script to launch either google or yahoo based on the $Site variable. I have hard coded "Google" in that site variable. I want to build the Variable name $GoogleURL when the $Site is equal to Google and $YahooURL when $Site is equal to "Yahoo".

$URLString does rebuild the variable name, however when I try to concatenate that in a string, the string will display $GoogleURL instead of passing on http://www.google.com

I have an actual application for this need, so don't be concerned that i have simplified this down to getting to either Google or Yahoo. I could do IF or Case statements however I will be dealing with 40+ sites in the practical application and anted to stay away from having to do so many IF or Case Statements......

$GoogleURL = "http://www.google.com"

$YahooURL = "http://www.yahoo.com"

$Site = "Google"

$URLString = ("$"&$Site & "URL")

MsgBox(0,"Launch Site","Internet Explorer will open up to " & $Site & " at " & $URLString)

ShellExecute ("iexplore.exe","-extoff " & $URLString)

Link to comment
Share on other sites

Hello TForgay,

Use Eval() in this type of situation.

$URLString = Eval( $Site & 'URL' )

Good Luck & Happy Coding!

Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Mass Spammer

My Public ID is 'Realm'. Mass Spammer is only a generic title for members with 500+ posts.

When you post a reproducer script, explain what it is your attempting to achieve, what errors/wrong results you are getting, and finally what you expect your script to do, all in which you had done, help will generally come fast. So the thanks goes to you for posting enough information which is a rarity with most new members.

btw, Your Welcome!

Good Luck with your script; Happy Coding!

Realm

Edit: Actually, I think the 'Mass Spammer' Title comes much earlier. I'd like to say 100 posts, but I am not for sure.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...