tags:

views:

202

answers:

5

I have many constant variables for example:

Const Total_US_Price = "100"

However, in my code, I am pulling a string "Total_US_Price". I want to replace my string with the value of the Const variable.

How do I do that? How do I change "Total_US_Price" to return "100" (both being strings)?

A: 

You would use the "CInt " function.

VBScript CInt Function explained and usage.

Chris
+2  A: 

It sounds like you want to use the eval() function...

http://www.devguru.com/technologies/vbscript/QuickRef/eval.html

EDIT: I hope you're not pulling these strings from the client side (query string, POSTed form values, or cookies) or else you are opening yourself up for a world of hurt. Someone could inject whatever strings they wanted and it will get executed on your web server.

pjabbott
Eval should be avoided where ever possible.
AnthonyWJones
A: 

I don't think this can be done other than by executing code dynamically, using either Eval() to get the value directly, or Execute() to get it by side-effect.

Specifically:

MyVarName = "Total_US_Price"
Value100 = Eval(MyVarName)
' Or...
Exectute("Value100 = " + MyVarName)

The Eval is more practical, but less flexible...

mjv
A: 

If you have access to source, remove const line and add these lines instead:

dim Total_US_Price
Total_US_Price = "100"

Now you can change the value whenever you like.

ssg
+1  A: 

Not sure what you exactly mean with 'pulling a string' but please don't abuse eval. Use a lookup table for lookup values.

set x = createobject("scripting.dictionary")    
x("total_us_price") = 100
price = x("total_us_price")
Joost Moesker