Page 1 of 1

I know it's VBScript, but about eval()...

Posted: 13 May 2011 01:47
by orange_batch
I've read in the past that eval() is bad because it can be abused. I've seen that said about JavaScript in particular, but isn't it the same with any language??

Here are two very simple examples.

Say I want to do a calculation from DOS using VBScript:

Code: Select all

cscript math.vbs //nologo 100*5

math.vbs:

Code: Select all

wscript.echo eval(wscript.arguments(0))


Say we want do to something with variables:

Code: Select all

cscript cake.vbs //nologo banana

cake.vbs:

Code: Select all

chocolatecake="yum chocolate"
bananacake="yum bananas"
wscript.echo eval(wscript.arguments(0)&"cake")


Is there a proper way to do these? Or is this right?

Thanks!

Re: I know it's VBScript, but about eval()...

Posted: 13 May 2011 04:13
by amel27

Code: Select all

wscript.echo eval(wscript.arguments(0)&"&""cake""")