472,374 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

I can Store an expression within a Variable?

Sample:

String c="1+2+3"

since it can makes to obtain the value of this Expression?

Other Sample:

Int X=4
String c="1+2+3+X "
Nov 24 '05 #1
8 2343

Daniel R. Rossnagel wrote:
Sample:

String c="1+2+3"

For your first example, I believe that VB.NET contains some kind of
expression evaluator method, although I'm not sure about that. You
can, of course, write your own suite of expression parsers and
evaluators. It's so easy that I'm sure that there are several out on
the Web if you search for them.
Other Sample:

Int X=4
String c="1+2+3+X "


This, however, would not be possible as written, because at run time
the variable you called "X" no longer has a name, and may even have
been optimized away, so there would be no way to find "X" and discover
what its value was. There are other ways of accomplishing the same
thing, but you can't just mention the name of a variable somewhere and
trust that you can find it using Reflection or anything like that.

Nov 24 '05 #2
Thanks. It happens that I come from VFP and it used much the
macrosubstitution

Sample:
X=4
C="1+2+3+X "
R=&C

Strange much this of the VFP

"Bruce Wood" <br*******@canada.com> escribió en el mensaje
news:11**********************@g44g2000cwa.googlegr oups.com...

Daniel R. Rossnagel wrote:
Sample:

String c="1+2+3"


For your first example, I believe that VB.NET contains some kind of
expression evaluator method, although I'm not sure about that. You
can, of course, write your own suite of expression parsers and
evaluators. It's so easy that I'm sure that there are several out on
the Web if you search for them.
Other Sample:

Int X=4
String c="1+2+3+X "


This, however, would not be possible as written, because at run time
the variable you called "X" no longer has a name, and may even have
been optimized away, so there would be no way to find "X" and discover
what its value was. There are other ways of accomplishing the same
thing, but you can't just mention the name of a variable somewhere and
trust that you can find it using Reflection or anything like that.

Nov 24 '05 #3

Daniel R. Rossnagel wrote:
Thanks. It happens that I come from VFP and it used much the
macrosubstitution

Sample:
X=4
C="1+2+3+X "
R=&C


I'm not familiar with VFP, but what you say is possible in an
interpreted language, in which symbolic information is always available
at runtime.

In compiled languages this isn't (necessarily) true.

Nov 24 '05 #4
\\\Eval by Nigel Amstrong
1. Create a file called: DynamicMath.js
2. Add this code to it:

class DynamicMath
{
static function Eval(MathExpression : String) : double
{
return eval(MathExpression);
};
}

3. Compile it with the command line jsc compiler: jsc /t:library
DynamicMath.js
4. Add a reference to DynamicMath.dll to your project (and to
Microsoft.JScript.dll as well)
5. Use from your favourite .NET language:
Dim d As Double = DynamicMath.Eval("2 + 3 + 4")
MessageBox.Show(d)
6. That's it
Nov 24 '05 #5

Gabriel Lozano-Morán wrote:
\\\Eval by Nigel Amstrong
1. Create a file called: DynamicMath.js
2. Add this code to it:

class DynamicMath
{
static function Eval(MathExpression : String) : double
{
return eval(MathExpression);
};
}

3. Compile it with the command line jsc compiler: jsc /t:library
DynamicMath.js
4. Add a reference to DynamicMath.dll to your project (and to
Microsoft.JScript.dll as well)
5. Use from your favourite .NET language:
Dim d As Double = DynamicMath.Eval("2 + 3 + 4")
MessageBox.Show(d)
6. That's it


Very cool.

However, one still couldn't do one of the things the OP wants to do,
which is:

Dim x As Double = 1.25;
Dim d As Double = DynamicMath.Eval("2 + 3 + x");

Nov 25 '05 #6
Hi Bruce,

What about Eval("2+3" + x) ?

succes,
Bart

http://www.xenopz.com/blog/bartdeboeck/

Nov 25 '05 #7
ba**********@hotmail.com wrote:
What about Eval("2+3" + x) ?


That's not even going to compile. I think you meant:

Eval("2 + 3") + x;

Which is doable if you know in advance that the only thing you're going to
do with X is add it to the expression.

--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 25 '05 #8
Hi James,

It will compile in C#, the expression, however, should be Eval("2+3+"
+ x)

Thanks,
Bart

Nov 29 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: F. Da Costa | last post by:
Hi, Does anybody know why IE5+ does *not* honour array objects (like a table) across a session? Example: Frame A contains a var tableVar which is set via form Frame B (on init) using...
12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
5
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into...
8
by: No Such Luck | last post by:
Is there anyway to literally evaluate the contents of a string in an if statement? For example: int i = 0; char * str = "i == 0"; if(str) /* I know this doesn't do what I want */ {
1
by: TARUN | last post by:
Hello All I get stuck in one problem , Please help me and excuse me on the poor Knowledge in SQL Server Store procedure Q1...I want to return a string type value from store procedure , Is it...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.