Jump to content
bs27975

val(string) or eval(string) a la bash $(())?

Recommended Posts

I see number()

Local $dNumber1 = Number(1 + 2 + 10) ; Returns 13.

 

Is there an equivalent for a string arg? e.g. val("1 + 2 + 10").

 

The bash equivalent to the above would be:

dNumber1=$((1 + 2 + 10)) # Returns 13.

 

However:

myexpression='1 + 2 + 10'

dNumber1=$(("${myexpression}")) # Returns 13.

 

would be the same. Which is only to say, whether the contents are a string or number or formula doesn't matter to it. (Because the interpreter would strip the quotes off first.)

 

So, is there a way to have the quotes stripped off before number() interprets something like: number("1 + 2 + 10")

 

Rationale:

I have an input box where I ask the user for a number. It occurs to me that instead of manually calculating some input value, the computer could do it for them.

e.g. "(1,200,000,000 * 7 - 350,000,000) / 26,500,000"

[Yes, I know, the commas are problematic there.]

 

Thoughts or suggestions?

 

Share this post


Link to post
Share on other sites
Posted (edited)
5 hours ago, TheXman said:

Have you tried the EXECUTE function?

MsgBox(0, "", '"1+2+10" = ' & Execute("1+2+10"))

 

Thank you!

I took Execute to be for running .exe's - this use never occurred to me.  My bad.

Edited by bs27975

Share this post


Link to post
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

×
×
  • Create New...